Skip to content

Commit

Permalink
lib.types.attrsOf: deduplicate
Browse files Browse the repository at this point in the history
  • Loading branch information
hsjobeki committed Sep 24, 2024
1 parent b8b3edf commit 8176af5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 19 deletions.
2 changes: 1 addition & 1 deletion lib/options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ rec {
showOption = parts: let
# 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.
# Can lead to misleading 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 "\<(.*)\>";
escapeOptionPart = part:
Expand Down
19 changes: 1 addition & 18 deletions lib/types.nix
Original file line number Diff line number Diff line change
Expand Up @@ -568,24 +568,7 @@ rec {
substSubModules = m: nonEmptyListOf (elemType.substSubModules m);
};

attrsOf = elemType: mkOptionType rec {
name = "attrsOf";
description = "attribute set of ${optionDescriptionPhrase (class: class == "noun" || class == "composite") elemType}";
descriptionClass = "composite";
check = isAttrs;
merge = loc: defs:
mapAttrs (n: v: v.value) (filterAttrs (n: v: v ? value) (zipAttrsWith (name: defs:
(mergeDefinitions (loc ++ [name]) elemType defs).optionalValue
)
# Push down position info.
(map (def: mapAttrs (n: v: { inherit (def) file; value = v; }) def.value) defs)));
emptyValue = { value = {}; };
getSubOptions = prefix: elemType.getSubOptions (prefix ++ ["<name>"]);
getSubModules = elemType.getSubModules;
substSubModules = m: attrsOf (elemType.substSubModules m);
functor = (defaultFunctor name) // { wrapped = elemType; };
nestedTypes.elemType = elemType;
};
attrsOf = namedAttrsOf "name";

# A version of attrsOf that's lazy in its values at the expense of
# conditional definitions not working properly. E.g. defining a value with
Expand Down

0 comments on commit 8176af5

Please sign in to comment.