1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-11-21 13:10:33 +00:00

lib/types: improve loaOf warning

Not all modules use name attribute as the name of the submodule, for example,
environment.etc uses target. We will need to maintain a list of exceptions.
This commit is contained in:
Jan Tojnar 2020-01-11 08:54:42 +01:00
parent e85b34c484
commit b0c2c96cbe
No known key found for this signature in database
GPG key ID: 7FAB2A15F7A607A4

View file

@ -340,18 +340,22 @@ rec {
let
padWidth = stringLength (toString (length def.value));
unnamed = i: unnamedPrefix + fixedWidthNumber padWidth i;
nameAttrs = {
"environment.etc" = "target";
};
nameAttr = nameAttrs.${option} or "name";
res =
{ inherit (def) file;
value = listToAttrs (
imap1 (elemIdx: elem:
{ name = elem.name or (unnamed elemIdx);
{ name = elem.${nameAttr} 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;
list = concatMapStrings (x: ''{ ${nameAttr} = "${x.${nameAttr} or "unnamed"}"; ...} '') sample;
set = concatMapStrings (x: ''${x.${nameAttr} or "unnamed"} = {...}; '') sample;
msg = ''
In file ${def.file}
a list is being assigned to the option config.${option}.