Repository navigation
Open
Labels
error-messagesConfusing messages and better diagnosticsfeatureFeature request or proposallanguageThe Nix expression language; parser, interpreter, primops, evaluation, etc
Description
Is your feature request related to a problem? Please describe.
Function reflection is an important part of everyday use of the Nix language, in callPackage and the module system, to improve syntax and to make strict functions lazy.
However, the information is too limited, creating pitfalls that "library" code such as callPackage can not currently compensate.
Furthermore, it prevents improvements to be made without breaking compatibility:
- Don't require ellipsis in NixOS module definitions. nixpkgs#254212
- Flakes: provide robust access to
outPaththrough newmetaargument #8908
Describe the solution you'd like
Two solutions have been already been proposed:
- Add functionInfo builtin #8961
- Flakes: provide robust access to
outPaththrough newmetaargument #8908
They could hardly be more different. Open design questions:
- One primop returning attrset or multiple primops?
- Use names that relate to the syntax or names that relate to the semantics?
- Syntax-based:
arg,args,ellipsis,hasArgs - Semantics-based:
bindsAllAttrs,args,isOpen,strict
- Syntax-based:
Currently implemented by neither:
- Support
__functor.
Describe alternatives you've considered
- Reject function reflection altogether. This would make the language more predictable, but that ship has sailed a very long time ago.
- "I want as little reflection as possible, because reflection is complicated and the language should be simple."
- This suggests a linear relation between the "amount of reflection" and difficulty, which is a simplistic view that's false.
- Everyday users don't need to interact with this newly exposed info at all. They do get to enjoy more robust reflection.
- "This will cause reflection to be used more often and cause never ending problems. What else do we need to expose next?"
- More use isn't all that bad, because users are already forced to interact with
functionArgsthroughcallPackageand the module system. - I believe the proposed interfaces cover all relevant function behaviors, and it's unlikely that we'll need more until perhaps the language itself is extended.
- More use isn't all that bad, because users are already forced to interact with
Additional context
Priorities
Add 👍 to issues you find important.
Reacted by Aleksana, Connor Baker, Ryan Hendrickson, Yueh-Shun Li and Philip Taron
Metadata
Metadata
Assignees
Labels
error-messagesConfusing messages and better diagnosticsfeatureFeature request or proposallanguageThe Nix expression language; parser, interpreter, primops, evaluation, etc
Projects
- StatusShow more project fields⚖ To discuss
Activity
anna328p commentedon Mar 28, 2024
https://github.com/anna328p/nix-prelude/blob/main/introspection.nix
Most of this is already possible in a hacky way using
toXML. I use it in my Nix code.roberth commentedon Mar 28, 2024
@infinisil has also written something like that in NixOS/nixpkgs#194992
I suppose it's an extra argument for making this info available: it already is available.
Of course it shouldn't have to be hacky or slow.
ShamrockLee commentedon Aug 27, 2026
If implemented, Nixpkgs developers no longer have to specify
lib.extendDrvArgNames'sinheritFunctionArgsmanually. (See #10350 (comment) for details.)In addition, the callable set support should be handled on the Nixpkgs side, e.g., by having
lib.functionInforead specific callable set attributes.roberth commentedon Nov 3, 2026
Worth making a decision here, also for improving the module system performance and legibility:
ShamrockLee commentedon Nov 4, 2026
I'm not sufficiently familliar with the Nix internal to make such decision.
The following opinions are from a Nix user's perspective.
Reading the PR description again, I found my use case suitable to compare the syntatx-based vs. semantics-based interface.
Typically,
inheritFunctiinArgsis set depending on whether the functionextenddrvArgs { }(theargs: updatingArgspart offinalAttrs: args: updatingArgs) takes arbitrary attribute sets.(lib.functionInfo (extenddrvArgs { })).isOpenlet fi = lib.functionInfo (extenddrvArgs { }); in fi.isFormal -> fi.hasEllipsis(
fi.hasEllipsis -> fi.isFormalis alwaystrue.)I would lean toward the latter, for the filliwing reasins:
isFormalandhasEllipsissyntax are clear and would hardly change even with future additions like{ a, ...@extraArgs }: { }.On the other hand, the variable name of
argsinargs: { }and{ a, ... }@args: { }doesn't seem to carry any semantics.People who would need this piece of information is likely manipulating the
*.nixfiles.Such information should only expose via, say,
builtins.getAST.I found the attribute set output quite ergonomic, but extending it in the future means adding attributes to the output (not sure if it is tolerable).
If adding attributes would not be possible, providing
builtins.isFormal(orbuiltins.hasFormalSetPattern) andbuiltins.hasEllipsisseems more robust.The corresponding Nixpkgs
libfunctions could expose a richer interface if the developers would like to.nixos-discourse commentedon Nov 9, 2026
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/from-argument-patterns-to-pattern-matching/81053/4