-
-
Notifications
You must be signed in to change notification settings - Fork 14k
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: init attrsWith #344216
Open
hsjobeki
wants to merge
11
commits into
NixOS:master
Choose a base branch
from
hsjobeki:lib/namedAttrsOf
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+291
−46
Open
lib.types: init attrsWith #344216
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
dc45ca2
lib.types: init attrsWith
hsjobeki 0a2f174
lib.attrsWith: init eval tests
hsjobeki 3bd01bc
lib/attrsWith: inline merge functions
hsjobeki 11a6fd8
lib.types.attrsWith: Improved type merging
infinisil a21dc4a
lib.types.attrsWith: format whitespaces
hsjobeki f910828
lib.types.attrsWith: init documentation
hsjobeki 2493726
lib.types.attrsWith: add required functor attributes
hsjobeki 95c2276
lib.types.attrsWith: doc add missing listing
hsjobeki 66f9d13
lib.types.attrsWith: add some more unit tests
hsjobeki ebe48f1
lib.types.defaultTypeMerge: change precedence of payload vs wrapped
hsjobeki 5a3d22c
types/attrsWith: rename parameter 'name' to 'placeholder'
hsjobeki 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 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 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 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 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,45 @@ | ||
# Check that AttrsWith { lazy = true; } is lazy | ||
{ lib, ... }: | ||
let | ||
inherit (lib) types mkOption; | ||
in | ||
{ | ||
imports = [ | ||
# Module A | ||
( | ||
{ ... }: | ||
{ | ||
options.mergedLazy = mkOption { | ||
# Same as lazyAttrsOf | ||
type = types.attrsWith { | ||
lazy = true; | ||
elemType = types.int; | ||
}; | ||
}; | ||
} | ||
) | ||
# Module B | ||
( | ||
{ ... }: | ||
{ | ||
options.mergedLazy = lib.mkOption { | ||
# Same as lazyAttrsOf | ||
type = types.attrsWith { | ||
lazy = true; | ||
elemType = types.int; | ||
}; | ||
}; | ||
} | ||
) | ||
# Result | ||
( | ||
{ config, ... }: | ||
{ | ||
# Can only evaluate if lazy | ||
config.mergedLazy.bar = config.mergedLazy.baz + 1; | ||
config.mergedLazy.baz = 10; | ||
options.result = mkOption { default = config.mergedLazy.bar; }; | ||
} | ||
) | ||
]; | ||
} |
This file contains 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,53 @@ | ||
# Check that AttrsWith { lazy = true; } is lazy | ||
{ lib, ... }: | ||
let | ||
inherit (lib) types mkOption; | ||
in | ||
{ | ||
imports = [ | ||
# Module A | ||
( | ||
{ ... }: | ||
{ | ||
options.mergedName = mkOption { | ||
default = { }; | ||
type = types.attrsWith { | ||
# Declare <name> = "id" | ||
name = "id"; | ||
elemType = types.submodule { | ||
options.nested = mkOption { | ||
type = types.int; | ||
default = 1; | ||
}; | ||
}; | ||
}; | ||
}; | ||
} | ||
) | ||
# Module B | ||
( | ||
{ ... }: | ||
{ | ||
options.mergedName = mkOption { | ||
# default: "<name>" | ||
type = types.attrsOf (types.submodule { }); | ||
# default = {}; | ||
}; | ||
} | ||
) | ||
|
||
# Output | ||
( | ||
{ | ||
options, | ||
... | ||
}: | ||
{ | ||
options.result = mkOption { | ||
default = lib.concatStringsSep "." (options.mergedName.type.getSubOptions options.mergedName.loc) | ||
.nested.loc; | ||
}; | ||
} | ||
) | ||
]; | ||
} |
This file contains 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,39 @@ | ||
# Non mergable attrsWith | ||
{ lib, ... }: | ||
let | ||
inherit (lib) types mkOption; | ||
in | ||
{ | ||
imports = [ | ||
# Module A | ||
( | ||
{ ... }: | ||
{ | ||
options.mergedName = mkOption { | ||
default = { }; | ||
type = types.attrsWith { | ||
name = "id"; | ||
elemType = types.submodule { | ||
options.nested = mkOption { | ||
type = types.int; | ||
default = 1; | ||
}; | ||
}; | ||
}; | ||
}; | ||
} | ||
) | ||
# Module B | ||
( | ||
{ ... }: | ||
{ | ||
options.mergedName = mkOption { | ||
type = types.attrsWith { | ||
name = "other"; | ||
elemType = types.submodule { }; | ||
}; | ||
}; | ||
} | ||
) | ||
]; | ||
} |
This file contains 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 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.
Right, we actually have two types of option paths: abstract ones containing placeholders, and real ones that are just data.
Treating them the same isn't quite correct, and merging a workaround could complicate a real fix.
Also note that some of these path items are not module options but attrsOf attributes, and
"*"
will occur as an attribute name in certain configurations to represent a "pattern" that matches everything; for example when an HTTP server doesn't responds for an unknown virtual host, etc.We could solve this in at least two ways
a. Leave the "option path" type as is, but use two functions
showOption
as is, suitable for concrete option pathsshowAbstractOption
, which implements these new rulesb. Only improve the representation
{ _type = "optionPathPlaceholder"; metaVariable = "name"; __toString = this: "<${this.metaVariable}>"; }
I think (b) may have good backward compatibility and it solves the problem for module options; not just attrsOf keys.
__toString
is mostly for compatibility with existing code that kind of works when a placeholder string is passed. This happens when generating option docs.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 pre-existing tech debt, so while this is a good opportunity to fix it before making it slightly worse, perhaps this should be done in a follow-up PR instead.
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'd prefer to do this in a follow up PR if you are okay with it. Should i remove the changes from this one?