Skip to content

Commit

Permalink
lib.showOption: allow arbitrary placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
hsjobeki committed Sep 24, 2024
1 parent 23ed287 commit 0e279d8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,12 @@ rec {
"*" # listOf (submodule {})
"<function body>" # functionTo
];
in if builtins.elem part specialIdentifiers
# If the part is a named placeholder of the form "<...>" don't escape it.
# Required for compatibility with: namedAttrsOf
# Can lead to wrong escaping if somebody uses literally "<...>" in their option names.
# This is the trade-off to allow for named placeholders in option names.
isNamedPlaceholder = builtins.match "\<(.*)\>" part != null;
in if builtins.elem part specialIdentifiers || isNamedPlaceholder
then part
else lib.strings.escapeNixIdentifier part;
in (concatStringsSep ".") (map escapeOptionPart parts);
Expand Down
2 changes: 1 addition & 1 deletion lib/types.nix
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ rec {
# Push down position info.
(map (def: mapAttrs (n: v: { inherit (def) file; value = v; }) def.value) defs)));
emptyValue = { value = {}; };
getSubOptions = prefix: elemType.getSubOptions (prefix ++ ["<${attrName}>"]);
getSubOptions = prefix: elemType.getSubOptions (prefix ++ ["{${attrName}}"]);
getSubModules = elemType.getSubModules;
substSubModules = m: namedAttrsOf attrName (elemType.substSubModules m);
functor = (defaultFunctor name) // { wrapped = elemType; };
Expand Down

0 comments on commit 0e279d8

Please sign in to comment.