git.iko.soy/typeable/nixpkgs
on master help sign in
Merge reording asserts in NixOS eval (#47293)

Changes the evaluation order in that it evaluates assertions before warnings, so that eg. the following would work: { config, lib, ... }: { options.foo = lib.mkOption { type = lib.types.bool; default = true; description = "..."; }; options.bar = lib.mkOption { type = lib.types.bool; default = false; description = "..."; }; config = lib.mkMerge [ (lib.mkIf config.bar { system.build.bar = "foobar"; }) (lib.mkIf config.foo { assertions = lib.singleton { assertion = config.bar; message = "Bar needs to be enabled"; }; systemd.services.foo = { description = "Foo"; serviceConfig.ExecStart = config.system.build.bar; }; }) ]; } This is because the systemd module includes definitions for warnings that would trigger evaluation of the config.system.build.bar definition. The original pull request references a breakage due to the following: { services.nixosManual.enable = false; services.nixosManual.showManual = true; } However, changing the eval order between asserts and warnings clearly is a corner case here and it only happens because of the aforementioned usage of warnings in the systemd module and needs more discussion. Nevertheless, this is still useful because it lowers the evaluation time whenever an assertion is hit, which is a hard failure anyway.

commit9bfd864c592a0e1d04e0224fb4427965cba1d78d authoraszlig <aszlig@nix.build> dateWed 26 Sep 2018, 01:04 (8 years ago) parent14a1907563d5b1
1 file changed+37−34
nixos/modules/system/activation/top-level.nix+37−34
nixos/modules/system/activation/top-level.nix+37−34
@@ -93,49 +93,52 @@ let
9393 ${config.system.extraSystemBuilderCmds}
9494 '';
9595
96− # Handle assertions
97−
98− failed = map (x: x.message) (filter (x: !x.assertion) config.assertions);
99−
100− showWarnings = res: fold (w: x: builtins.trace "warning: ${w}" x) res config.warnings;
101−
10296 # Putting it all together. This builds a store path containing
10397 # symlinks to the various parts of the built configuration (the
10498 # kernel, systemd units, init scripts, etc.) as well as a script
10599 # `switch-to-configuration' that activates the configuration and
106100 # makes it bootable.
107− baseSystem = showWarnings (
108− if [] == failed then pkgs.stdenvNoCC.mkDerivation {
109− name = let hn = config.networking.hostName;
110− nn = if (hn != "") then hn else "unnamed";
111− in "nixos-system-${nn}-${config.system.nixos.label}";
112− preferLocalBuild = true;
113− allowSubstitutes = false;
114− buildCommand = systemBuilder;
115−
116− inherit (pkgs) utillinux coreutils;
117− systemd = config.systemd.package;
118− shell = "${pkgs.bash}/bin/sh";
119−
120− inherit children;
121− kernelParams = config.boot.kernelParams;
122− installBootLoader =
123− config.system.build.installBootLoader
124− or "echo 'Warning: do not know how to make this configuration bootable; please enable a boot loader.' 1>&2; true";
125− activationScript = config.system.activationScripts.script;
126− nixosLabel = config.system.nixos.label;
127−
128− configurationName = config.boot.loader.grub.configurationName;
129−
130− # Needed by switch-to-configuration.
131−
132− perl = "${pkgs.perl}/bin/perl " + (concatMapStringsSep " " (lib: "-I${lib}/${pkgs.perl.libPrefix}") (with pkgs.perlPackages; [ FileSlurp NetDBus XMLParser XMLTwig ]));
133− } else throw "\nFailed assertions:\n${concatStringsSep "\n" (map (x: "- ${x}") failed)}");
101+ baseSystem = pkgs.stdenvNoCC.mkDerivation {
102+ name = let hn = config.networking.hostName;
103+ nn = if (hn != "") then hn else "unnamed";
104+ in "nixos-system-${nn}-${config.system.nixos.label}";
105+ preferLocalBuild = true;
106+ allowSubstitutes = false;
107+ buildCommand = systemBuilder;
108+
109+ inherit (pkgs) utillinux coreutils;
110+ systemd = config.systemd.package;
111+ shell = "${pkgs.bash}/bin/sh";
112+
113+ inherit children;
114+ kernelParams = config.boot.kernelParams;
115+ installBootLoader =
116+ config.system.build.installBootLoader
117+ or "echo 'Warning: do not know how to make this configuration bootable; please enable a boot loader.' 1>&2; true";
118+ activationScript = config.system.activationScripts.script;
119+ nixosLabel = config.system.nixos.label;
120+
121+ configurationName = config.boot.loader.grub.configurationName;
122+
123+ # Needed by switch-to-configuration.
124+
125+ perl = "${pkgs.perl}/bin/perl " + (concatMapStringsSep " " (lib: "-I${lib}/${pkgs.perl.libPrefix}") (with pkgs.perlPackages; [ FileSlurp NetDBus XMLParser XMLTwig ]));
126+ };
127+
128+ # Handle assertions and warnings
129+
130+ failedAssertions = map (x: x.message) (filter (x: !x.assertion) config.assertions);
131+
132+ showWarnings = res: fold (w: x: builtins.trace "warning: ${w}" x) res config.warnings;
133+
134+ baseSystemAssertWarn = if failedAssertions != []
135+ then throw "\nFailed assertions:\n${concatStringsSep "\n" (map (x: "- ${x}") failedAssertions)}"
136+ else showWarnings baseSystem;
134137
135138 # Replace runtime dependencies
136139 system = fold ({ oldDependency, newDependency }: drv:
137140 pkgs.replaceDependency { inherit oldDependency newDependency drv; }
138− ) baseSystem config.system.replaceRuntimeDependencies;
141+ ) baseSystemAssertWarn config.system.replaceRuntimeDependencies;
139142
140143in
141144