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/types: Add oneOf, extension of either to a list of types #65728
Conversation
55f518e
to
ba31c85
Compare
As per @grahamc's suggestion on IRC, I renamed it from |
It's not really an ADT though, https://github.com/shlevy/nix-adt/ would be more like it (and might be nice to reserve |
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 like it, one small mistake I spotted. The naming is very good.
ba31c85
to
9a44f44
Compare
Pushed |
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 wanted this as well!
I pushed a commit that replaces all nested |
@@ -36,7 +36,7 @@ in { | |||
}; | |||
|
|||
config = mkOption { | |||
type = attrsOf (nullOr (either (either bool int) str)); | |||
type = attrsOf (nullOr (oneOf [ bool int str ])); |
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.
type = attrsOf (nullOr (oneOf [ bool int str ])); | |
type = attrsOf (oneOf [ (nullOr bool) int str ]); |
or oneOf [ null bool int str ]
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 don't think null
is a type? And I prefer the nullOr (oneOf ...)
, because it gives the meaning of "either unset or one of these"
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've suggested it so it would be compatible with my another suggestion - #65728 (comment)
But I'm fine with this as well.
@@ -226,7 +226,7 @@ in rec { | |||
|
|||
environment = mkOption { | |||
default = {}; | |||
type = with types; attrsOf (nullOr (either str (either path package))); | |||
type = with types; attrsOf (nullOr (oneOf [ str path package ])); |
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.
@@ -520,7 +520,7 @@ in | |||
}; | |||
|
|||
systemd.globalEnvironment = mkOption { | |||
type = with types; attrsOf (nullOr (either str (either path package))); | |||
type = with types; attrsOf (nullOr (oneOf [ str path package ])); |
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.
It also looks like |
@danbst I feel like |
Thanks @infinisil! 🎉 |
Motivation for this change
Oftentimes a type such as
either str (either bool (either int float))
is needed, which is annoying to write. This change allows you to useoneOf [ str bool int float ]
instead. This will be useful for the implementation of NixOS/rfcs#42Ping @Profpatsch @rycee @danbst
Things done