Conversation
lib/customisation.nix
Outdated
| nix-repl> lib.apply ( { x, y }: x + y ) { x = 1; y = 2; z = -1; } | ||
| 3 |
There was a problem hiding this comment.
This has a very similar effect to
Do we need the body to be strict in the attribute names? If not, lazyFunction is strictly more useful, pardon the pun.
There was a problem hiding this comment.
Agreed that this has some overlap with lazyFunction ( I like your style, https://github.com/aakropotkin/ak-nix/blob/7242b7d7c49037700def339ea232d594b67dcd7c/lib/funk.nix#L346 there's no denying that we've got similar taste ); but my goal with this routine was intentionally limited to filtering a set of auto args rather than making them lazy ( which is just a side effect ).
If you've got any recommendations to avoid stepping on each others toes let me know. We wouldn't want to add redundant routines and you definitely beat me to the punch with this PR in October.
There was a problem hiding this comment.
I don't think yours actually makes it lazy though?
nix-repl> lib.fix (lib.applyArgs ({ a, b }: { a = b; b = 1; }) )
error: infinite recursion encountered
Maybe this looks like making up requirements, which in a way it is, but I'm concerned about function sprawl. As in the Fairbairn threshold.
There was a problem hiding this comment.
It's a real tragedy that we have an incentive to inline frequently called functions like this to gain better performance.
There was a problem hiding this comment.
I mean, I wouldn't expect that lib.applyArgs snippet to work because you've just got a lambda there. Lets review the definition:
applyArgs = f: args: let
fn = if lib.isFunction f then f else import f;
in fn ( builtins.intersectAttrs ( lib.functionArgs fn ) args );
The note I have about "this is only meant for functions that accept attrsets" was alluding to this a bit.
I'd describe this routine as more of "useful idiom"/short-hand rather than a generalized "works everywhere, do what I mean" utility ( we've got more robust routines for those situations anyways ).
There was a problem hiding this comment.
It's not just a lambda, but equivalent to
nix-repl> let r = lib.applyArgs ({ a, b }: { a = b; b = 1; }) r; in r
error: infinite recursion encountered
There was a problem hiding this comment.
Wait I just reread this again.
The applyArgs here is right to blow up because your second argument isn't an attrset.
This could be fixed with an assert builtins.isAttrs args; so that the error message is more sensible, but at bottom this is a type mismatch.
applyArgs :: function -> attrs -> any
So calling a partial applyArgs function function is an error. The message about infinite recursion is misleading but you'd get the same error with let r = ( { a, b }: { b = 1; a = b + 1; } ) r; in r. The evaluator is griping in an unhelpful but technically accurate way.
Description of changes
Adds two new lib routines:
lib.applyandlib.callWithas members ofcustomization.nix.Things done
Ran
lib/tests/misc.nixtests.sandbox = trueset innix.conf? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)nixos/doc/manual/md-to-db.shto update generated release notes