Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nix: skip check completely when checkConfig=false #6293

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions modules/misc/nix.nix
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ let
${mkKeyValuePairs cfg.settings}
${cfg.extraOptions}
'';
passthru.doCheck = cfg.checkConfig;
checkPhase =
if pkgs.stdenv.hostPlatform != pkgs.stdenv.buildPlatform then ''
echo "Ignoring validation for cross-compilation"
Expand All @@ -92,9 +93,13 @@ let
"--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
'';
};
Expand Down Expand Up @@ -241,7 +246,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.
'';
};

Expand Down
6 changes: 6 additions & 0 deletions tests/modules/misc/nix/allow-unknown-settings-expected.conf
Original file line number Diff line number Diff line change
@@ -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

27 changes: 27 additions & 0 deletions tests/modules/misc/nix/allow-unknown-settings.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{ 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}
'';
}
2 changes: 2 additions & 0 deletions tests/modules/misc/nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
7 changes: 7 additions & 0 deletions tests/modules/misc/nix/skip-check-settings-expected.conf
Original file line number Diff line number Diff line change
@@ -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

27 changes: 27 additions & 0 deletions tests/modules/misc/nix/skip-check-settings.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{ 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}
'';
}
Loading