aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorrnhmjoj <rnhmjoj@inventati.org>2020-08-23 01:28:45 +0200
committerrnhmjoj <rnhmjoj@inventati.org>2020-09-02 00:42:50 +0200
commit20d491a317d9956ddca80913f07d04bd234ea432 (patch)
treea48e09dd2688004debda35c36afa9196b2e39305 /lib
parentbfd706923e4d0781f4aad65beca9d5d7d167de6b (diff)
treewide: completely remove types.loaOf
Diffstat (limited to 'lib')
-rw-r--r--lib/modules.nix1
-rw-r--r--lib/types.nix117
2 files changed, 11 insertions, 107 deletions
diff --git a/lib/modules.nix b/lib/modules.nix
index 2ec346998095..decb96ffe111 100644
--- a/lib/modules.nix
+++ b/lib/modules.nix
@@ -613,7 +613,6 @@ rec {
if tp.name == "option set" || tp.name == "submodule" then
throw "The option ${showOption loc} uses submodules without a wrapping type, in ${showFiles opt.declarations}."
else if optionSetIn "attrsOf" then types.attrsOf (types.submodule options)
- else if optionSetIn "loaOf" then types.loaOf (types.submodule options)
else if optionSetIn "listOf" then types.listOf (types.submodule options)
else if optionSetIn "nullOr" then types.nullOr (types.submodule options)
else tp;
diff --git a/lib/types.nix b/lib/types.nix
index 1845b6ae339e..17e7a939fe3d 100644
--- a/lib/types.nix
+++ b/lib/types.nix
@@ -252,8 +252,8 @@ rec {
merge = mergeEqualOption;
};
- # drop this in the future:
- list = builtins.trace "`types.list` is deprecated; use `types.listOf` instead" types.listOf;
+ # TODO: drop this in the future:
+ list = builtins.trace "`types.list` has been removed; please use `types.listOf` instead" types.listOf;
listOf = elemType: mkOptionType rec {
name = "listOf";
@@ -326,110 +326,15 @@ rec {
functor = (defaultFunctor name) // { wrapped = elemType; };
};
- # List or attribute set of ...
- loaOf = elemType:
- let
- convertAllLists = loc: defs:
- let
- padWidth = stringLength (toString (length defs));
- unnamedPrefix = i: "unnamed-" + fixedWidthNumber padWidth i + ".";
- in
- imap1 (i: convertIfList loc (unnamedPrefix i)) defs;
- convertIfList = loc: unnamedPrefix: def:
- if isList def.value then
- let
- padWidth = stringLength (toString (length def.value));
- unnamed = i: unnamedPrefix + fixedWidthNumber padWidth i;
- anyString = placeholder "name";
- nameAttrs = [
- { path = [ "environment" "etc" ];
- name = "target";
- }
- { path = [ "containers" anyString "bindMounts" ];
- name = "mountPoint";
- }
- { path = [ "programs" "ssh" "knownHosts" ];
- # hostNames is actually a list so we would need to handle it only when singleton
- name = "hostNames";
- }
- { path = [ "fileSystems" ];
- name = "mountPoint";
- }
- { path = [ "boot" "specialFileSystems" ];
- name = "mountPoint";
- }
- { path = [ "services" "znapzend" "zetup" ];
- name = "dataset";
- }
- { path = [ "services" "znapzend" "zetup" anyString "destinations" ];
- name = "label";
- }
- { path = [ "services" "geoclue2" "appConfig" ];
- name = "desktopID";
- }
- ];
- matched = let
- equals = a: b: b == anyString || a == b;
- fallback = { name = "name"; };
- in findFirst ({ path, ... }: all (v: v == true) (zipListsWith equals loc path)) fallback nameAttrs;
- nameAttr = matched.name;
- nameValueOld = value:
- if isList value then
- if length value > 0 then
- "[ " + concatMapStringsSep " " escapeNixString value + " ]"
- else
- "[ ]"
- else
- escapeNixString value;
- nameValueNew = value: unnamed:
- if isList value then
- if length value > 0 then
- head value
- else
- unnamed
- else
- value;
- res =
- { inherit (def) file;
- value = listToAttrs (
- imap1 (elemIdx: elem:
- { name = nameValueNew (elem.${nameAttr} or (unnamed elemIdx)) (unnamed elemIdx);
- value = elem;
- }) def.value);
- };
- option = concatStringsSep "." loc;
- sample = take 3 def.value;
- more = lib.optionalString (length def.value > 3) "... ";
- list = concatMapStrings (x: ''{ ${nameAttr} = ${nameValueOld (x.${nameAttr} or "unnamed")}; ...} '') sample;
- set = concatMapStrings (x: ''${nameValueNew (x.${nameAttr} or "unnamed") "unnamed"} = {...}; '') sample;
- msg = ''
- In file ${def.file}
- a list is being assigned to the option config.${option}.
- This will soon be an error as type loaOf is deprecated.
- See https://github.com/NixOS/nixpkgs/pull/63103 for more information.
- Do
- ${option} =
- { ${set}${more}}
- instead of
- ${option} =
- [ ${list}${more}]
- '';
- in
- lib.warn msg res
- else
- def;
- attrOnly = attrsOf elemType;
- in mkOptionType rec {
- name = "loaOf";
- description = "list or attribute set of ${elemType.description}s";
- check = x: isList x || isAttrs x;
- merge = loc: defs: attrOnly.merge loc (convertAllLists loc defs);
- emptyValue = { value = {}; };
- getSubOptions = prefix: elemType.getSubOptions (prefix ++ ["<name?>"]);
- getSubModules = elemType.getSubModules;
- substSubModules = m: loaOf (elemType.substSubModules m);
- functor = (defaultFunctor name) // { wrapped = elemType; };
- };
+ # TODO: drop this in the future:
+ loaOf =
+ let msg =
+ ''
+ `types.loaOf` has been removed and mixing lists with attribute values
+ is no longer possible; please use `types.attrsOf` instead.
+ See https://github.com/NixOS/nixpkgs/issues/1800 for the motivation.
+ '';
+ in builtins.trace msg types.attrsOf;
# Value of given type but with no merging (i.e. `uniq list`s are not concatenated).
uniq = elemType: mkOptionType rec {