diff options
author | Robert Hensing <robert@roberthensing.nl> | 2023-07-05 13:03:32 +0200 |
---|---|---|
committer | Robert Hensing <robert@roberthensing.nl> | 2023-07-05 13:03:32 +0200 |
commit | 6649d1e3696e7148f3575de0c015630567224a4e (patch) | |
tree | 982789aaa120bebc4865ac3ce3efcba6906f0a14 | |
parent | 2fa416732c3a3c9cadc9d6833abc9a11d87f8f12 (diff) | |
download | nixpkgs-6649d1e3696e7148f3575de0c015630567224a4e.tar nixpkgs-6649d1e3696e7148f3575de0c015630567224a4e.tar.gz nixpkgs-6649d1e3696e7148f3575de0c015630567224a4e.tar.bz2 nixpkgs-6649d1e3696e7148f3575de0c015630567224a4e.tar.lz nixpkgs-6649d1e3696e7148f3575de0c015630567224a4e.tar.xz nixpkgs-6649d1e3696e7148f3575de0c015630567224a4e.tar.zst nixpkgs-6649d1e3696e7148f3575de0c015630567224a4e.zip |
nixos/config/nix: Move nixConf
-rw-r--r-- | nixos/modules/config/nix.nix | 76 | ||||
-rw-r--r-- | nixos/modules/services/misc/nix-daemon.nix | 52 |
2 files changed, 74 insertions, 54 deletions
diff --git a/nixos/modules/config/nix.nix b/nixos/modules/config/nix.nix index 78cab3c7f8c..c740f8ccc32 100644 --- a/nixos/modules/config/nix.nix +++ b/nixos/modules/config/nix.nix @@ -4,14 +4,33 @@ { config, lib, pkgs, ... }: let - - cfg = config.nix; - inherit (lib) + concatStringsSep + boolToString + escape + floatToString + getVersion + isBool + isDerivation + isFloat + isInt + isList + isString mapAttrsToList + mkIf mkRenamedOptionModuleWith + optionalString + strings + toPretty + versionAtLeast ; + cfg = config.nix; + + nixPackage = cfg.package.out; + + isNixAtLeast = versionAtLeast (getVersion nixPackage); + legacyConfMappings = { useSandbox = "sandbox"; buildCores = "cores"; @@ -27,6 +46,54 @@ let systemFeatures = "system-features"; }; + nixConf = + assert isNixAtLeast "2.2"; + let + + mkValueString = v: + if v == null then "" + else if isInt v then toString v + else if isBool v then boolToString v + else if isFloat v then floatToString v + else if isList v then toString v + else if isDerivation v then toString v + else if builtins.isPath v then toString v + else if isString v then v + else if strings.isConvertibleWithToString v then toString v + else abort "The nix conf value: ${toPretty {} v} can not be encoded"; + + mkKeyValue = k: v: "${escape [ "=" ] k} = ${mkValueString v}"; + + mkKeyValuePairs = attrs: concatStringsSep "\n" (mapAttrsToList mkKeyValue attrs); + + in + pkgs.writeTextFile { + name = "nix.conf"; + 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} + ${cfg.extraOptions} + ''; + checkPhase = lib.optionalString cfg.checkConfig ( + if pkgs.stdenv.hostPlatform != pkgs.stdenv.buildPlatform then '' + echo "Ignoring validation for cross-compilation" + '' + else '' + echo "Validating generated nix.conf" + ln -s $out ./nix.conf + set -e + set +o pipefail + NIX_CONF_DIR=$PWD \ + ${cfg.package}/bin/nix show-config ${optionalString (isNixAtLeast "2.3pre") "--no-net"} \ + ${optionalString (isNixAtLeast "2.4pre") "--option experimental-features nix-command"} \ + |& sed -e 's/^warning:/error:/' \ + | (! grep '${if cfg.checkAllErrors then "^error:" else "^error: unknown setting"}') + set -o pipefail + ''); + }; + in { imports = @@ -39,4 +106,7 @@ in }) legacyConfMappings; + config = mkIf cfg.enable { + environment.etc."nix/nix.conf".source = nixConf; + }; } diff --git a/nixos/modules/services/misc/nix-daemon.nix b/nixos/modules/services/misc/nix-daemon.nix index 95ee75922da..b4b909a48d5 100644 --- a/nixos/modules/services/misc/nix-daemon.nix +++ b/nixos/modules/services/misc/nix-daemon.nix @@ -29,54 +29,6 @@ let nixbldUsers = listToAttrs (map makeNixBuildUser (range 1 cfg.nrBuildUsers)); - nixConf = - assert isNixAtLeast "2.2"; - let - - mkValueString = v: - if v == null then "" - else if isInt v then toString v - else if isBool v then boolToString v - else if isFloat v then floatToString v - else if isList v then toString v - else if isDerivation v then toString v - else if builtins.isPath v then toString v - else if isString v then v - else if strings.isConvertibleWithToString v then toString v - else abort "The nix conf value: ${toPretty {} v} can not be encoded"; - - mkKeyValue = k: v: "${escape [ "=" ] k} = ${mkValueString v}"; - - mkKeyValuePairs = attrs: concatStringsSep "\n" (mapAttrsToList mkKeyValue attrs); - - in - pkgs.writeTextFile { - name = "nix.conf"; - 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} - ${cfg.extraOptions} - ''; - checkPhase = lib.optionalString cfg.checkConfig ( - if pkgs.stdenv.hostPlatform != pkgs.stdenv.buildPlatform then '' - echo "Ignoring validation for cross-compilation" - '' - else '' - echo "Validating generated nix.conf" - ln -s $out ./nix.conf - set -e - set +o pipefail - NIX_CONF_DIR=$PWD \ - ${cfg.package}/bin/nix show-config ${optionalString (isNixAtLeast "2.3pre") "--no-net"} \ - ${optionalString (isNixAtLeast "2.4pre") "--option experimental-features nix-command"} \ - |& sed -e 's/^warning:/error:/' \ - | (! grep '${if cfg.checkAllErrors then "^error:" else "^error: unknown setting"}') - set -o pipefail - ''); - }; - semanticConfType = with types; let confAtom = nullOr @@ -659,8 +611,6 @@ in ] ++ optional (config.programs.bash.enableCompletion) pkgs.nix-bash-completions; - environment.etc."nix/nix.conf".source = nixConf; - environment.etc."nix/registry.json".text = builtins.toJSON { version = 2; flakes = mapAttrsToList (n: v: { inherit (v) from to exact; }) cfg.registry; @@ -737,7 +687,7 @@ in LimitNOFILE = 1048576; }; - restartTriggers = [ nixConf ]; + restartTriggers = [ config.environment.etc."nix/nix.conf".source ]; # `stopIfChanged = false` changes to switch behavior # from stop -> update units -> start |