From e85b34c484d2c38cad3eaffbb97e211fecf852bf Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sat, 11 Jan 2020 08:09:56 +0100 Subject: [PATCH 1/4] tree-wide: fix more warning related to loaOf deprecation --- nixos/modules/services/mail/postfix.nix | 5 +---- nixos/modules/services/mail/spamassassin.nix | 2 +- pkgs/os-specific/linux/rfkill/udev.nix | 22 ++++++++++---------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/nixos/modules/services/mail/postfix.nix b/nixos/modules/services/mail/postfix.nix index d7378821440..19e11b31d9c 100644 --- a/nixos/modules/services/mail/postfix.nix +++ b/nixos/modules/services/mail/postfix.nix @@ -612,10 +612,7 @@ in { environment = { - etc = singleton - { source = "/var/lib/postfix/conf"; - target = "postfix"; - }; + etc.postfix.source = "/var/lib/postfix/conf"; # This makes it comfortable to run 'postqueue/postdrop' for example. systemPackages = [ pkgs.postfix ]; diff --git a/nixos/modules/services/mail/spamassassin.nix b/nixos/modules/services/mail/spamassassin.nix index 07b3bf0420a..75442c7cdb5 100644 --- a/nixos/modules/services/mail/spamassassin.nix +++ b/nixos/modules/services/mail/spamassassin.nix @@ -124,7 +124,7 @@ in # Allow users to run 'spamc'. environment = { - etc = singleton { source = spamdEnv; target = "spamassassin"; }; + etc.spamassassin.source = spamdEnv; systemPackages = [ pkgs.spamassassin ]; }; diff --git a/pkgs/os-specific/linux/rfkill/udev.nix b/pkgs/os-specific/linux/rfkill/udev.nix index 41dd3da9d31..0575c46e28e 100644 --- a/pkgs/os-specific/linux/rfkill/udev.nix +++ b/pkgs/os-specific/linux/rfkill/udev.nix @@ -8,18 +8,18 @@ # udev.packages = [ pkgs.rfkill_udev ]; # # Add a hook script in the managed etc directory, e.g.: -# etc = [ -# { source = pkgs.writeScript "rtfkill.hook" '' -# #!${pkgs.runtimeShell} +# etc."rfkill.hook" = { +# mode = "0755"; +# text = '' +# #!${pkgs.runtimeShell} # -# if [ "$RFKILL_STATE" -eq "1" ]; then -# exec ${config.system.build.upstart}/sbin/initctl emit -n antenna-on -# else -# exec ${config.system.build.upstart}/sbin/initctl emit -n antenna-off -# fi -# ''; -# target = "rfkill.hook"; -# } +# if [ "$RFKILL_STATE" -eq "1" ]; then +# exec ${config.system.build.upstart}/sbin/initctl emit -n antenna-on +# else +# exec ${config.system.build.upstart}/sbin/initctl emit -n antenna-off +# fi +# ''; +# } # Note: this package does not need the binaries # in the rfkill package. From b0c2c96cbe12c5a3a280ffd2634ebe0c8507e8b0 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sat, 11 Jan 2020 08:54:42 +0100 Subject: [PATCH 2/4] 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. --- lib/types.nix | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/types.nix b/lib/types.nix index e86f6d36476..cbbea00058d 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -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}. From 6fc46fbb177e22d467c9d92d0fac8581afa81246 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sat, 11 Jan 2020 13:32:30 +0100 Subject: [PATCH 3/4] lib/types: only show ... in loaOf warning when necessary --- lib/types.nix | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/types.nix b/lib/types.nix index cbbea00058d..6eebc20829c 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -354,6 +354,7 @@ rec { }; option = concatStringsSep "." loc; sample = take 3 def.value; + more = lib.optionalString (length def.value > 3) "... "; list = concatMapStrings (x: ''{ ${nameAttr} = "${x.${nameAttr} or "unnamed"}"; ...} '') sample; set = concatMapStrings (x: ''${x.${nameAttr} or "unnamed"} = {...}; '') sample; msg = '' @@ -363,10 +364,10 @@ rec { See https://git.io/fj2zm for more information. Do ${option} = - { ${set}...} + { ${set}${more}} instead of ${option} = - [ ${list}...] + [ ${list}${more}] ''; in lib.warn msg res From 13633bd21ac92dce92f920fd68578f5e430c6c0d Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sat, 11 Jan 2020 15:02:57 +0100 Subject: [PATCH 4/4] lib/types: improve loaOf message even more Now we suggest correct names for all options in Nixpkgs and also home-manager at the time of writing. --- lib/types.nix | 71 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 64 insertions(+), 7 deletions(-) diff --git a/lib/types.nix b/lib/types.nix index 6eebc20829c..a090af78acd 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -340,23 +340,80 @@ rec { let padWidth = stringLength (toString (length def.value)); unnamed = i: unnamedPrefix + fixedWidthNumber padWidth i; - nameAttrs = { - "environment.etc" = "target"; - }; - nameAttr = nameAttrs.${option} or "name"; + 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"; + } + { path = [ "home-manager" "users" anyString "programs" "ssh" "matchBlocks" ]; + name = "host"; # https://github.com/rycee/home-manager/blob/e8dbc3561373b68d12decb3c0d7c1ba245f138f7/modules/programs/ssh.nix#L265 + } + { path = [ "home-manager" "users" anyString "home" "file" ]; + name = "target"; # https://github.com/rycee/home-manager/blob/0e9b7aab3c6c27bf020402e0e2ef20b65c040552/modules/files.nix#L33 + } + { path = [ "home-manager" "users" anyString "xdg" "configFile" ]; + name = "target"; # https://github.com/rycee/home-manager/blob/54de0e1d79a1370e57a8f23bef89f99f9b92ab67/modules/misc/xdg.nix#L41 + } + { path = [ "home-manager" "users" anyString "xdg" "dataFile" ]; + name = "target"; # https://github.com/rycee/home-manager/blob/54de0e1d79a1370e57a8f23bef89f99f9b92ab67/modules/misc/xdg.nix#L58 + } + ]; + 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 = elem.${nameAttr} or (unnamed elemIdx); + { 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} = "${x.${nameAttr} or "unnamed"}"; ...} '') sample; - set = concatMapStrings (x: ''${x.${nameAttr} or "unnamed"} = {...}; '') sample; + 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}.