New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bring back types.functionTo
#110707
Bring back types.functionTo
#110707
Conversation
This reverts commit 4ff1ab5. We need this to type options like: services.xserver.windowManager.xmonad.extraPackages that specify functions that take an attribute set containing packages / plugins and return a list containing a selection of the values in this set. The reason we need a dedicated type for this is to have the correct merge behaviour. Without the functionTo type merging multiple function option definitions results in an evaluation error. The functionTo type merges definitions by returning a new function that applies the functions of all the definitions to the given input and merges the result. (cherry picked from commit 7ed41ff)
(cherry picked from commit 478af11)
Without this patch merging options like services.xserver.windowManager.xmonad.extraPackages results in the evaluation error: error: value is a list while a set was expected, at nixpkgs/lib/options.nix:77:23 With this patch we get the desired merging behaviour that just concatenates the resulting package lists. (cherry picked from commit 6e99f9f) Co-Authored-By: Silvan Mosberger <contact@infinisil.com>
Also |
types.functionTo
, finallytypes.functionTo
This should be tested. |
Added a bunch more tests now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One final touch to make the error message consistent with listOf
. Without it, the error message is inaccurate.
Now type checks the resulting function values and allows mkMerge and co. Also indicates that the type check is done in the function body Co-Authored-By: Robert Hensing <robert@roberthensing.nl>
Good point, now done :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
@@ -453,6 +453,16 @@ rec { | |||
functor = (defaultFunctor name) // { wrapped = elemType; }; | |||
}; | |||
|
|||
functionTo = elemType: mkOptionType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 good name, leaves room for function
with a typed input, in case that becomes relevant someday.
The editor config check failure is for an unrelated file. Merging. |
Motivation for this change
We have a bunch of NixOS options that can be assigned a function, like
These options currently all have no type specified, because there is no fitting type for that. Despite that, such options still work just fine, due to the default merging strategy being used in such a case:
nixpkgs/lib/options.nix
Lines 119 to 123 in f6dcf09
This PR (re)introduces
types.functionTo
, which specifies that merging behavior explicitly, with more control over it. This is a cherry-pick with some fixes from #44626.History
functionTo
functionTo
andfunctionTo
as welltypes.selectorFunction
since there's a number of options needing such a type, so they open lib/types: add the selectorFunction type #44601 to add itselectorFunction
is just a less generic version of the previousfunctionTo
and suggests readding it instead, so Bring back functionTo to prevent evalutation errors while merging #44626 is createdselectorFunction
type locally to the module, which motivates this PRIn the discussions from 2018, a number of alternatives have been brought up, but the simplicity and safety of
p: [ p.aeson ]
is just unbeatable. This has become a pattern in nixpkgs which we can't avoid that easily anymore, even if an alternative would be more suitable.Things done
sandbox
innix.conf
on non-NixOS linux)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
./result/bin/
)nix path-info -S
before and after)