mirror of
https://github.com/nix-community/home-manager
synced 2024-11-23 11:39:46 +01:00
Add support for assertions and warnings
This commit is contained in:
parent
ed9464258a
commit
beba608705
1 changed files with 26 additions and 3 deletions
|
@ -3,6 +3,8 @@
|
||||||
, lib ? pkgs.stdenv.lib
|
, lib ? pkgs.stdenv.lib
|
||||||
}:
|
}:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
modules = [
|
modules = [
|
||||||
|
@ -33,18 +35,39 @@ 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 "[1;31mwarning: ${w}[0m" 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 (
|
||||||
|
let
|
||||||
|
mod = lib.evalModules {
|
||||||
modules = [ configuration ] ++ modules ++ [ pkgsModule ];
|
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
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue