Add support for assertions and warnings

This commit is contained in:
Robert Helgesson 2017-02-21 21:39:53 +01:00
parent ed9464258a
commit beba608705
No known key found for this signature in database
GPG key ID: C3DB11069E65DC86

View file

@ -3,6 +3,8 @@
, lib ? pkgs.stdenv.lib , lib ? pkgs.stdenv.lib
}: }:
with lib;
let let
modules = [ modules = [
@ -33,17 +35,38 @@ let
./systemd.nix ./systemd.nix
./xresources.nix ./xresources.nix
./xsession.nix ./xsession.nix
<nixpkgs/nixos/modules/misc/assertions.nix>
<nixpkgs/nixos/modules/misc/meta.nix> <nixpkgs/nixos/modules/misc/meta.nix>
]; ];
collectFailed = cfg:
map (x: x.message) (filter (x: !x.assertion) cfg.assertions);
showWarnings = res:
let
f = w: x: builtins.trace "warning: ${w}" x;
in
fold f res res.config.warnings;
pkgsModule = { pkgsModule = {
config._module.args.pkgs = lib.mkForce pkgs; config._module.args.pkgs = lib.mkForce pkgs;
config._module.args.baseModules = modules; config._module.args.baseModules = modules;
}; };
module = lib.evalModules { module = showWarnings (
modules = [ configuration ] ++ modules ++ [ pkgsModule ]; let
}; mod = lib.evalModules {
modules = [ configuration ] ++ modules ++ [ pkgsModule ];
};
failed = collectFailed mod.config;
failedStr = concatStringsSep "\n" (map (x: "- ${x}") failed);
in
if failed == []
then mod
else throw "\nFailed assertions:\n${failedStr}"
);
in in