summaryrefslogtreecommitdiffstats
path: root/lib/types.nix
diff options
context:
space:
mode:
authorrnhmjoj <rnhmjoj@inventati.org>2019-06-14 10:07:18 +0200
committerworldofpeace <worldofpeace@protonmail.ch>2020-01-06 10:39:19 -0500
commit03309899eb41e50ef65001f63d6a4f078e3d4556 (patch)
treefc4ee91a915a09ad08bd3d076523399a0a220591 /lib/types.nix
parentcde46494c6960243bcb42aeda14f2a4212320bd6 (diff)
lib/types: warn loaOf is deprecated
Diffstat (limited to 'lib/types.nix')
-rw-r--r--lib/types.nix41
1 files changed, 29 insertions, 12 deletions
diff --git a/lib/types.nix b/lib/types.nix
index de3c4f0d6030..bb1b17e6beee 100644
--- a/lib/types.nix
+++ b/lib/types.nix
@@ -295,26 +295,43 @@ rec {
# List or attribute set of ...
loaOf = elemType:
let
- convertAllLists = defs:
+ convertAllLists = loc: defs:
let
padWidth = stringLength (toString (length defs));
unnamedPrefix = i: "unnamed-" + fixedWidthNumber padWidth i + ".";
in
- imap1 (i: convertIfList (unnamedPrefix i)) defs;
-
- convertIfList = unnamedPrefix: def:
+ 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;
+ res =
+ { inherit (def) file;
+ value = listToAttrs (
+ imap1 (elemIdx: elem:
+ { name = elem.name or (unnamed elemIdx);
+ value = elem;
+ }) def.value);
+ };
+ option = concatStringsSep "." loc;
+ sample = take 3 def.value;
+ list = concatMapStrings (x: ''{ name = "${x.name or "unnamed"}"; ...} '') sample;
+ set = concatMapStrings (x: ''${x.name or "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://git.io/fj2zm for more information.
+ Do
+ ${option} =
+ { ${set}...}
+ instead of
+ ${option} =
+ [ ${list}...]
+ '';
in
- { inherit (def) file;
- value = listToAttrs (
- imap1 (elemIdx: elem:
- { name = elem.name or (unnamed elemIdx);
- value = elem;
- }) def.value);
- }
+ lib.warn msg res
else
def;
attrOnly = attrsOf elemType;
@@ -322,7 +339,7 @@ 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 defs);
+ merge = loc: defs: attrOnly.merge loc (convertAllLists loc defs);
getSubOptions = prefix: elemType.getSubOptions (prefix ++ ["<name?>"]);
getSubModules = elemType.getSubModules;
substSubModules = m: loaOf (elemType.substSubModules m);