From e769196105a142e67bac4f3ed7b5a337e539e54f Mon Sep 17 00:00:00 2001 From: Alois Wohlschlager Date: Sun, 10 Nov 2024 11:55:47 +0100 Subject: [PATCH] nix: make sure extra- settings are applied last All extra- settings should come after their unprefixed counterpart, because the entries of the config file are processed from top to bottom and appending should happen after overwriting. This is a port of https://github.com/NixOS/nixpkgs/pull/278064 . --- modules/misc/nix.nix | 17 ++++++++++++----- .../misc/nix/example-settings-expected.conf | 1 + 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/modules/misc/nix.nix b/modules/misc/nix.nix index 652d3eb89..64aa0510e 100644 --- a/modules/misc/nix.nix +++ b/modules/misc/nix.nix @@ -3,10 +3,11 @@ let inherit (lib) - boolToString concatStringsSep escape floatToString getVersion isBool - isConvertibleWithToString isDerivation isFloat isInt isList isString - literalExpression maintainers mapAttrsToList mkDefault mkEnableOption mkIf - mkMerge mkOption optionalString toPretty types versionAtLeast; + boolToString concatStringsSep escape filterAttrs floatToString getVersion + hasPrefix isBool isConvertibleWithToString isDerivation isFloat isInt isList + isString literalExpression maintainers mapAttrsToList mkDefault + mkEnableOption mkIf mkMerge mkOption optionalString toPretty types + versionAtLeast; cfg = config.nix; @@ -65,13 +66,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.settings option in # your Home Manager configuration at $XDG_CONFIG_HOME/nix/nix.conf. # 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 = diff --git a/tests/modules/misc/nix/example-settings-expected.conf b/tests/modules/misc/nix/example-settings-expected.conf index 2c2587fd6..dabc18b90 100644 --- a/tests/modules/misc/nix/example-settings-expected.conf +++ b/tests/modules/misc/nix/example-settings-expected.conf @@ -5,3 +5,4 @@ show-trace = true system-features = big-parallel kvm recursive-nix use-sandbox = true +