-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
lib.types.boolByOr: init #272764
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
Merged
Merged
lib.types.boolByOr: init #272764
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { lib, ... }: { | ||
|
|
||
| options.value = lib.mkOption { | ||
| type = lib.types.lazyAttrsOf lib.types.boolByOr; | ||
| }; | ||
|
|
||
| config.value = { | ||
| falseFalse = lib.mkMerge [ false false ]; | ||
| trueFalse = lib.mkMerge [ true false ]; | ||
| falseTrue = lib.mkMerge [ false true ]; | ||
| trueTrue = lib.mkMerge [ true true ]; | ||
| }; | ||
| } | ||
|
|
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
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
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.
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.
Should
boolhave type merging instead?bias = true;=> orbias = false;=> andThere 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.
bias = "quorum";=> chaos actually. UsemkMergereplicateto win.🤡
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.
I am a bit worried about backwards compat if we had something like
bool = boolWith { bias = null; }, since thenameof the type would change (unless we didname = if bias == null then "bool" else "bool-with-${bias}"). Though I guess the name shouldn't really influence anything, probably..Other than that, I'm not sure if we'll ever even need the AND-based variant. Even the OR-based one here is a bit dubious. It's probably only really necessary because of the
functionTo boolofallowInsecurePredicate, which we should actually be replaced with RFC 127 instead anyways.Actually considering that, it might make the most sense to declare this boolean type just locally in
pkgs/top-level/config.nix. I don't know of any other use cases of 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.
I think combined process capability flags are a good candidate for the type. A service may have a set of security capabilities that should encompass all processes in that service.
Example:
cap.SYS_NET = mkDefault true;,cap.SYS_CHOWN = mkDefault false;cap.SYS_NET = false;,cap.SYS_CHOWN = false;cap.SYS_NET = false;,cap.SYS_CHOWN = true;SYS_NETshows the relevance of priorities, whereasSYS_CHOWNshows the need forboolByOr.So I think it makes sense as a first class type.
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.
The
AND-based variant would be for things that are enabled by default but can be disabled by any other module.I suspect that these are mostly things that are phrased negatively.
networking.firewall.enablewould be an example of a secretly negative option, although definitely not one that any module should just go and disable. It's negative, because enabling it prevents functionality.I think it may be acceptable for a module to set
mkDefault falseon a nice to have feature that isn't as critical.Maybe in general you want cpufreq enabled, but some hardware service that suffers from it may disable cpufreq, but only as a default.
So I guess AND is for all flags that are nice to enable by default but might have negative consequences, so that some other modules can disable it by default. All while letting the user pick a setting without
mkForce.Currently we may (ab)use the
mkOptionDefault/mkDefaultseparation to get similar behavior.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.
Hmm I'm really not convinced. It seems undecidable whether something is "positive" or "negative". Even enabling the firewall newly allows
ipcommands to succeed when they didn't before, so you have new features in a way.In practice, merging with
mkDefaultand co. priorities works well enough. One module settingtrueand the otherfalsemeans the modules are incompatible with each other as is, so either don't use one of them, or make them have amkDefaultand co.I don't think I've ever seen anybody run into an actual problem due to not having
boolByOr/boolByAndsemantics. It really seems that it's only necessary forallowUnfreePredicate, due to how it would be impractical to writeThere 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.
I'm convinced of
boolByOr, just not ofboolByAnd, because its uses cases are more rare thanboolByOr, and more contrived because of the negatives. I'm also not convinced of needing to type merged a bias onto an existingbool, so we can skip that idea.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.
Alright let's have just
boolByOrfor now then, sounds fine to me