1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-11-08 19:46:05 +01:00
This commit is contained in:
Ian Chamberlain 2025-11-06 21:09:14 +00:00 committed by GitHub
commit 14f4b95e5e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 94 additions and 2 deletions

View file

@ -103,6 +103,7 @@ let
${mkKeyValuePairs cfg.settings}
${cfg.extraOptions}
'';
passthru.doCheck = cfg.checkConfig;
checkPhase =
if pkgs.stdenv.hostPlatform != pkgs.stdenv.buildPlatform then
''
@ -120,7 +121,8 @@ let
NIX_CONF_DIR=$PWD \
${cfg.package}/bin/nix ${showCommand} ${optionalString (isNixAtLeast "2.3pre") "--no-net --option experimental-features nix-command"} \
|& sed -e 's/^warning:/error:/' \
| (! grep '${if cfg.checkConfig then "^error:" else "^error: unknown setting"}')
| ${if cfg.allowUnknownSettings then "grep -v '^error: unknown setting'" else "cat"} \
| (! grep '^error:')
set -o pipefail
'';
};
@ -294,7 +296,16 @@ in
default = true;
description = ''
If enabled (the default), checks for data type mismatches and that Nix
can parse the generated nix.conf.
can parse the generated {file}`nix.conf`.
'';
};
allowUnknownSettings = mkOption {
type = types.bool;
default = false;
description = ''
If enabled, unknown setting errors will be allowed when checking the
generated {file}`nix.conf`. This has no effect if {option}`checkConfig` is false.
'';
};

View file

@ -0,0 +1,6 @@
# 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!
and-another-one = hello
some-arbitrary-setting = true

View file

@ -0,0 +1,33 @@
{
config,
lib,
pkgs,
...
}:
{
nix = {
package = config.lib.test.mkStubPackage {
version = lib.getVersion pkgs.nixVersions.stable;
buildScript = ''
target=$out/bin/nix
mkdir -p "$(dirname "$target")"
echo -n "true" > "$target"
chmod +x "$target"
'';
};
settings = {
some-arbitrary-setting = true;
and-another-one = "hello";
};
checkConfig = false;
};
nmt.script = ''
assertFileContent \
home-files/.config/nix/nix.conf \
${./allow-unknown-settings-expected.conf}
'';
}

View file

@ -5,4 +5,6 @@
nix-keep-old-nix-path = ./keep-old-nix-path.nix;
nix-example-channels = ./example-channels.nix;
nix-example-channels-xdg = ./example-channels-xdg.nix;
nix-skip-check-settings = ./skip-check-settings.nix;
nix-allow-unknown-settings = ./allow-unknown-settings.nix;
}

View file

@ -0,0 +1,7 @@
# 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!
some! nonsense {
which should fail validation

View file

@ -0,0 +1,33 @@
{
config,
lib,
pkgs,
...
}:
{
nix = {
package = config.lib.test.mkStubPackage {
version = lib.getVersion pkgs.nixVersions.stable;
buildScript = ''
target=$out/bin/nix
mkdir -p "$(dirname "$target")"
echo -n "true" > "$target"
chmod +x "$target"
'';
};
extraOptions = ''
some! nonsense {
which should fail validation
'';
checkConfig = false;
};
nmt.script = ''
assertFileContent \
home-files/.config/nix/nix.conf \
${./skip-check-settings-expected.conf}
'';
}