1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-26 21:19:45 +01:00

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
}:
with lib;
let
modules = [
@ -33,18 +35,39 @@ let
./systemd.nix
./xresources.nix
./xsession.nix
<nixpkgs/nixos/modules/misc/assertions.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 = {
config._module.args.pkgs = lib.mkForce pkgs;
config._module.args.baseModules = modules;
};
module = lib.evalModules {
module = showWarnings (
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
{