replaceVars.withoutCheck: init#339303
Conversation
| replaceVars = callPackage ../build-support/replace-vars { } // { | ||
| withoutCheck = callPackage ../build-support/replace-vars { doCheck = false; }; | ||
| }; |
There was a problem hiding this comment.
I don’t understand how this works. (x: x) // { } is an error. Is this some __functor magic? I think I would prefer something like replaceVarsWith { doCheck = false; } ./file { … }, where replaceVars = replaceVarsWith { }.
There was a problem hiding this comment.
Is this some
__functormagic?
Yes, kind of. An attrset with __functor is also just an attrset.
nix-repl> replaceVars = callPackage ./pkgs/build-support/replace-vars { }
nix-repl> replaceVars
{
__functionArgs = { ... };
__functor = «lambda __functor @ /home/philip/Code/github.com/philiptaron/nixpkgs/lib/trivial.nix:957:19»;
override = { ... };
}
nix-repl> replaceVars // { a = 42; }
{
__functionArgs = { ... };
__functor = «lambda __functor @ /home/philip/Code/github.com/philiptaron/nixpkgs/lib/trivial.nix:957:19»;
a = 42;
override = { ... };
}
It's used a couple places in all-packages.nix:
- https://github.com/NixOS/nixpkgs/blob/6cc3e274c947096556c57d2b05dad5acda395b74/pkgs/top-level/all-packages.nix#L4036-L4038
- https://github.com/NixOS/nixpkgs/blob/6cc3e274c947096556c57d2b05dad5acda395b74/pkgs/top-level/all-packages.nix#L15825 (where I learned this trick)
- https://github.com/NixOS/nixpkgs/blob/6cc3e274c947096556c57d2b05dad5acda395b74/pkgs/top-level/all-packages.nix#L33290-L33295
- https://github.com/NixOS/nixpkgs/blob/6cc3e274c947096556c57d2b05dad5acda395b74/pkgs/top-level/all-packages.nix#L33961-L33964
There was a problem hiding this comment.
I'll note that callPackage is used in cases like this where it doesn't actually resolve to a package, but rather to a factory function that will then produce packages/derivations. If there were something like a callPackageFactory function that included the ability to passthru additional contents, this would look quite a bit more sane.
The core piece of code that's creating this functor attrset is
Line 264 in 4e2566e
As it is, I'm pretty sure that this specific feature doesn't yet justify replaceVarsWith, but if you feel quite strongly, I could introduce it.
There was a problem hiding this comment.
Right, I figured callPackage might be doing something like this. I just think __functor is weird and people don’t expect to find more functions under a function.
The nice thing about replaceVarsWith is that it would compose with any future extensions, like if we want to support postPatch or something. If you’re totally sure that there’ll never be another option ever again then maybe it could just be replaceVarsWithoutCheck?
There was a problem hiding this comment.
people don’t expect to find more functions under a function
One of the reasons I tilted this (odd) way was that I was able to document this variant "under" replaceVars so that it appeared in context on https://noogle.dev/f/pkgs/replaceVars. That documentation outweighs the oddity of people finding or failing to find functions under a function... I think. 😁
There was a problem hiding this comment.
I agree with @emilazy that __functor should be avoided when possible, it can be very confusing. I like the idea of replaceVarsWith more, especially because the same pattern is being used elsewhere too. Check out the docs for lib.fileset.gitTracked as an example how such a pair of functions can be crosslinked together in the docs, but nesting one under the other would also be fine imo.
There was a problem hiding this comment.
All right, I'll do replaceVarsWith.
msanft
left a comment
There was a problem hiding this comment.
Thanks a lot for adding this, and for taking the time to properly document and test it. I'm fine with the current implementation.
|
Thinking about alternatives to this, what if there was an alternative to Edit: Or rather, it should return a list of command and arguments to run. |
|
I took this approach in #357395.
I tried, but couldn't really think of a nice user interface for this. |
|
Closing in favor of #357395. |
Motivation for change
replaceVarsis a wrapper around the bash functionsubstitutein the stdenv.It has a checkPhase which causes the derivation to fail to build if any remaining text that matches
@[A-Za-z_][0-9A-Za-z_'-]@is in the output after replacement has occurred.As can be seen in #338962 (comment), sometimes this check phase is too strict, and there needs to be two phases of substitution.
So this PR introduces
replaceVars.withoutCheck, which has the same semantics but doesn't have a check phase making the assertion about remaining unreplaced variables.Description of changes
replaceVars.withoutCheckThings done
nix.conf? (See Nix manual)sandbox = relaxedsandbox = truenix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)