Merged
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>
9 tasks
Member
|
Also |
roberth
reviewed
Jan 25, 2021
types.functionTo, finallytypes.functionTo
Member
This should be tested. |
Member
Author
|
Added a bunch more tests now |
roberth
reviewed
Jan 26, 2021
Member
roberth
left a comment
There was a problem hiding this comment.
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>
Member
Author
|
Good point, now done :) |
roberth
approved these changes
Jan 27, 2021
| functor = (defaultFunctor name) // { wrapped = elemType; }; | ||
| }; | ||
|
|
||
| functionTo = elemType: mkOptionType { |
Member
There was a problem hiding this comment.
👍 good name, leaves room for function with a typed input, in case that becomes relevant someday.
Member
|
The editor config check failure is for an unrelated file. Merging. |
10 tasks
10 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
functionTofunctionToandfunctionToas welltypes.selectorFunctionsince there's a number of options needing such a type, so they open lib/types: add the selectorFunction type #44601 to add itselectorFunctionis just a less generic version of the previousfunctionToand suggests readding it instead, so Bring back functionTo to prevent evalutation errors while merging #44626 is createdselectorFunctiontype 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
sandboxinnix.confon non-NixOS linux)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"./result/bin/)nix path-info -Sbefore and after)