about summary refs log tree commit diff
path: root/nixos/modules/config/nix.nix
diff options
context:
space:
mode:
authorGuillaume Girol <symphorien+git@xlumurb.eu>2024-01-01 12:00:00 +0000
committerGuillaume Girol <symphorien+git@xlumurb.eu>2024-03-03 17:03:46 +0100
commit5b274d5f017ba4d610e495a6fae8a193966e9d25 (patch)
tree22a287f6ad3a98be093f7e7de46adbd3675432b9 /nixos/modules/config/nix.nix
parentcfc3698c31b1fb9cdcf10f36c9643460264d0ca8 (diff)
nixos/nix: add workaround for https://github.com/NixOS/nix/issues/9487
Nix has a suprising behavior where if the option `extra-foo` is set before `foo`, then setting `foo` overwrites the setting for `extra-foo`. This is reported as https://github.com/NixOS/nix/issues/9487, and will likely not be fixed any time soon.

This works around this issue by always putting `extra-*` settings after non-extra ones in the nixos-generated `/etc/nix.conf`.
Diffstat (limited to 'nixos/modules/config/nix.nix')
-rw-r--r--nixos/modules/config/nix.nix9
1 files changed, 8 insertions, 1 deletions
diff --git a/nixos/modules/config/nix.nix b/nixos/modules/config/nix.nix
index 2769d8b25ef6f..dc39b06013d83 100644
--- a/nixos/modules/config/nix.nix
+++ b/nixos/modules/config/nix.nix
@@ -14,8 +14,10 @@ let
     concatStringsSep
     boolToString
     escape
+    filterAttrs
     floatToString
     getVersion
+    hasPrefix
     isBool
     isDerivation
     isFloat
@@ -95,14 +97,19 @@ let
 
       mkKeyValuePairs = attrs: concatStringsSep "\n" (mapAttrsToList mkKeyValue attrs);
 
+      isExtra = key: hasPrefix "extra-" key;
+
     in
     pkgs.writeTextFile {
       name = "nix.conf";
+      # workaround for https://github.com/NixOS/nix/issues/9487
+      # extra-* settings must come after their non-extra counterpart
       text = ''
         # WARNING: this file is generated from the nix.* options in
         # your NixOS configuration, typically
         # /etc/nixos/configuration.nix.  Do not edit it!
-        ${mkKeyValuePairs cfg.settings}
+        ${mkKeyValuePairs (filterAttrs (key: value: !(isExtra key)) cfg.settings)}
+        ${mkKeyValuePairs (filterAttrs (key: value: isExtra key) cfg.settings)}
         ${cfg.extraOptions}
       '';
       checkPhase = lib.optionalString cfg.checkConfig (