nixos: top-level: evaluate assertions before warnings
or else at least the following config will fail with an evaluation error instead of an assert ``` { services.nixosManual.enable = false; services.nixosManual.showManual = true; } ```
This commit is contained in:
parent
0f3b89bbed
commit
fece91537b
@ -93,19 +93,12 @@ let
|
|||||||
${config.system.extraSystemBuilderCmds}
|
${config.system.extraSystemBuilderCmds}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
# Handle assertions
|
|
||||||
|
|
||||||
failed = map (x: x.message) (filter (x: !x.assertion) config.assertions);
|
|
||||||
|
|
||||||
showWarnings = res: fold (w: x: builtins.trace "[1;31mwarning: ${w}[0m" x) res config.warnings;
|
|
||||||
|
|
||||||
# Putting it all together. This builds a store path containing
|
# Putting it all together. This builds a store path containing
|
||||||
# symlinks to the various parts of the built configuration (the
|
# symlinks to the various parts of the built configuration (the
|
||||||
# kernel, systemd units, init scripts, etc.) as well as a script
|
# kernel, systemd units, init scripts, etc.) as well as a script
|
||||||
# `switch-to-configuration' that activates the configuration and
|
# `switch-to-configuration' that activates the configuration and
|
||||||
# makes it bootable.
|
# makes it bootable.
|
||||||
baseSystem = showWarnings (
|
baseSystem = pkgs.stdenvNoCC.mkDerivation {
|
||||||
if [] == failed then pkgs.stdenvNoCC.mkDerivation {
|
|
||||||
name = let hn = config.networking.hostName;
|
name = let hn = config.networking.hostName;
|
||||||
nn = if (hn != "") then hn else "unnamed";
|
nn = if (hn != "") then hn else "unnamed";
|
||||||
in "nixos-system-${nn}-${config.system.nixos.label}";
|
in "nixos-system-${nn}-${config.system.nixos.label}";
|
||||||
@ -130,12 +123,22 @@ let
|
|||||||
# Needed by switch-to-configuration.
|
# Needed by switch-to-configuration.
|
||||||
|
|
||||||
perl = "${pkgs.perl}/bin/perl " + (concatMapStringsSep " " (lib: "-I${lib}/${pkgs.perl.libPrefix}") (with pkgs.perlPackages; [ FileSlurp NetDBus XMLParser XMLTwig ]));
|
perl = "${pkgs.perl}/bin/perl " + (concatMapStringsSep " " (lib: "-I${lib}/${pkgs.perl.libPrefix}") (with pkgs.perlPackages; [ FileSlurp NetDBus XMLParser XMLTwig ]));
|
||||||
} else throw "\nFailed assertions:\n${concatStringsSep "\n" (map (x: "- ${x}") failed)}");
|
};
|
||||||
|
|
||||||
|
# Handle assertions and warnings
|
||||||
|
|
||||||
|
failedAssertions = map (x: x.message) (filter (x: !x.assertion) config.assertions);
|
||||||
|
|
||||||
|
showWarnings = res: fold (w: x: builtins.trace "[1;31mwarning: ${w}[0m" x) res config.warnings;
|
||||||
|
|
||||||
|
baseSystemAssertWarn = if failedAssertions != []
|
||||||
|
then throw "\nFailed assertions:\n${concatStringsSep "\n" (map (x: "- ${x}") failedAssertions)}"
|
||||||
|
else showWarnings baseSystem;
|
||||||
|
|
||||||
# Replace runtime dependencies
|
# Replace runtime dependencies
|
||||||
system = fold ({ oldDependency, newDependency }: drv:
|
system = fold ({ oldDependency, newDependency }: drv:
|
||||||
pkgs.replaceDependency { inherit oldDependency newDependency drv; }
|
pkgs.replaceDependency { inherit oldDependency newDependency drv; }
|
||||||
) baseSystem config.system.replaceRuntimeDependencies;
|
) baseSystemAssertWarn config.system.replaceRuntimeDependencies;
|
||||||
|
|
||||||
in
|
in
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user