nixos: evaluate assertions at toplevel, not at systemPackages

Fixes #2340
This commit is contained in:
Shea Levy 2014-04-21 11:46:16 -04:00
parent 5ba24cc8ea
commit 7d1ddae58e
2 changed files with 24 additions and 36 deletions

View file

@ -2,14 +2,6 @@
with lib;
let
failed = map (x: x.message) (filter (x: !x.assertion) config.assertions);
showWarnings = res: fold (w: x: builtins.trace "warning: ${w}" x) res config.warnings;
in
{
options = {
@ -38,15 +30,5 @@ in
};
};
config = {
# This option is evaluated always. Thus the assertions are checked
# as well. Hacky!
environment.systemPackages = showWarnings (
if [] == failed then []
else throw "\nFailed assertions:\n${concatStringsSep "\n" (map (x: "- ${x}") failed)}");
};
# impl of assertions is in <nixos/modules/system/activation/top-level.nix>
}

View file

@ -84,33 +84,39 @@ let
${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
# symlinks to the various parts of the built configuration (the
# kernel, systemd units, init scripts, etc.) as well as a script
# `switch-to-configuration' that activates the configuration and
# makes it bootable.
system = pkgs.stdenv.mkDerivation {
name = "nixos-${config.system.nixosVersion}";
preferLocalBuild = true;
buildCommand = systemBuilder;
system = showWarnings (
if [] == failed then pkgs.stdenv.mkDerivation {
name = "nixos-${config.system.nixosVersion}";
preferLocalBuild = true;
buildCommand = systemBuilder;
inherit (pkgs) utillinux coreutils;
systemd = config.systemd.package;
inherit (pkgs) utillinux coreutils;
systemd = config.systemd.package;
inherit children;
kernelParams = config.boot.kernelParams;
installBootLoader =
config.system.build.installBootLoader
or "echo 'Warning: do not know how to make this configuration bootable; please enable a boot loader.' 1>&2; true";
activationScript = config.system.activationScripts.script;
nixosVersion = config.system.nixosVersion;
inherit children;
kernelParams = config.boot.kernelParams;
installBootLoader =
config.system.build.installBootLoader
or "echo 'Warning: do not know how to make this configuration bootable; please enable a boot loader.' 1>&2; true";
activationScript = config.system.activationScripts.script;
nixosVersion = config.system.nixosVersion;
configurationName = config.boot.loader.grub.configurationName;
configurationName = config.boot.loader.grub.configurationName;
# Needed by switch-to-configuration.
perl = "${pkgs.perl}/bin/perl -I${pkgs.perlPackages.FileSlurp}/lib/perl5/site_perl";
};
# Needed by switch-to-configuration.
perl = "${pkgs.perl}/bin/perl -I${pkgs.perlPackages.FileSlurp}/lib/perl5/site_perl";
} else throw "\nFailed assertions:\n${concatStringsSep "\n" (map (x: "- ${x}") failed)}");
in