-
-
Notifications
You must be signed in to change notification settings - Fork 15.2k
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
lib.options.filterOptions #295337
base: master
Are you sure you want to change the base?
lib.options.filterOptions #295337
Conversation
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.
What's the use case?
I feel like generally there should be a better solution than doing postprocessing on options.
lib/options.nix
Outdated
|
||
|
||
``` | ||
filterOptions :: ([n] -> o -> bool) -> opts -> opts |
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.
filterOptions :: ([n] -> o -> bool) -> opts -> opts | |
filterOptions :: (List String -> Option -> Bool) -> Options -> Options |
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.
Applied.
lib/options.nix
Outdated
@@ -466,6 +467,57 @@ rec { | |||
${concatMapStringsSep "\n" (defFile: " - ${defFile}") opt.files} | |||
''; | |||
|
|||
/** | |||
Filters an options tree. |
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.
This is very minimal. It's good to have "tree", but what does it do? How is the callback used?
Something like:
Filters an option tree, such that the returned tree only contains the options for which the callback returns true
.
Arguments passed to the callback are:
- The option path, as a list of strings representing the attribute names.
- The option declaration at that path.
It is not possible to prune entire branches of the option tree in one go, as the callback is only invoked for each option (leaf).
Question: doesn't this leave empty branches behind?
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.
Applied.
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.
There's a test for leaving no empty branches now.
lib/options.nix
Outdated
=> { | ||
services.foo = mkOption { description = "foo"; }; | ||
programs.a-prog = mkOption { description = "program"; }; | ||
} |
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.
This can not be the result. Please test it.
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.
Amended.
ef204ea
to
819202f
Compare
Co-authored-by: Samyak S Sarnayak <samyak201@gmail.com>
819202f
to
adc61bd
Compare
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/prs-ready-for-review/3032/3683 |
Here's a potentially cleaner alternative: If you create a submodule of all the options that you want to generate documentation for, you can use pkgs.nixosOptionsDoc {
options = options.services.maubot.settings.type.getSubOptions [ ];
# ...;
} You can change the |
Co-authored-by: Samyak S Sarnayak samyak201@gmail.com
Description of changes
Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Add a 👍 reaction to pull requests you find important.