forked from DGNum/liminix
fix(assertions): wire up the assertion system
Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
This commit is contained in:
parent
8a6709e91b
commit
561d47822a
3 changed files with 45 additions and 3 deletions
|
@ -18,6 +18,7 @@ in
|
||||||
"${modulesPath}/users.nix"
|
"${modulesPath}/users.nix"
|
||||||
"${modulesPath}/outputs.nix"
|
"${modulesPath}/outputs.nix"
|
||||||
"${modulesPath}/nixpkgs.nix"
|
"${modulesPath}/nixpkgs.nix"
|
||||||
|
"${modulesPath}/misc/assertions.nix"
|
||||||
# FIXME: we should let the caller inject `pkgs` and `lim` ideally...
|
# FIXME: we should let the caller inject `pkgs` and `lim` ideally...
|
||||||
];
|
];
|
||||||
})
|
})
|
||||||
|
|
35
modules/misc/assertions.nix
Normal file
35
modules/misc/assertions.nix
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
# Taken from NixOS.
|
||||||
|
{ lib, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
options = {
|
||||||
|
|
||||||
|
assertions = mkOption {
|
||||||
|
type = types.listOf types.unspecified;
|
||||||
|
internal = true;
|
||||||
|
default = [];
|
||||||
|
example = [ { assertion = false; message = "you can't enable this for that reason"; } ];
|
||||||
|
description = ''
|
||||||
|
This option allows modules to express conditions that must
|
||||||
|
hold for the evaluation of the system configuration to
|
||||||
|
succeed, along with associated error messages for the user.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
warnings = mkOption {
|
||||||
|
internal = true;
|
||||||
|
default = [];
|
||||||
|
type = types.listOf types.str;
|
||||||
|
example = [ "The `foo' service is deprecated and will go away soon!" ];
|
||||||
|
description = ''
|
||||||
|
This option allows modules to show warnings to users during
|
||||||
|
the evaluation of the system configuration.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
# impl of assertions is in <nixpkgs/nixos/modules/system/activation/top-level.nix>
|
||||||
|
}
|
|
@ -5,9 +5,15 @@
|
||||||
, ...
|
, ...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
inherit (lib) mkOption types concatStringsSep;
|
inherit (lib) mkOption types concatStringsSep filter;
|
||||||
inherit (pkgs) liminix callPackage writeText;
|
inherit (pkgs) liminix callPackage writeText;
|
||||||
o = config.system.outputs;
|
o = config.system.outputs;
|
||||||
|
# Handle assertions and warnings
|
||||||
|
|
||||||
|
failedAssertions = map (x: x.message) (filter (x: !x.assertion) config.assertions);
|
||||||
|
baseSystemConfiguration = if failedAssertions != []
|
||||||
|
then throw "\nFailed assertions:\n${concatStringsSep "\n" (map (x: "- ${x}") failedAssertions)}"
|
||||||
|
else lib.showWarnings config.warnings o.systemConfiguration;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
|
@ -121,10 +127,10 @@ in
|
||||||
inherit (pkgs.pkgsBuildBuild) runCommand;
|
inherit (pkgs.pkgsBuildBuild) runCommand;
|
||||||
in runCommand "mktree" { } ''
|
in runCommand "mktree" { } ''
|
||||||
mkdir -p $out/nix/store/ $out/secrets $out/boot
|
mkdir -p $out/nix/store/ $out/secrets $out/boot
|
||||||
cp ${o.systemConfiguration}/bin/activate $out/activate
|
cp ${baseSystemConfiguration}/bin/activate $out/activate
|
||||||
ln -s ${pkgs.s6-init-bin}/bin/init $out/init
|
ln -s ${pkgs.s6-init-bin}/bin/init $out/init
|
||||||
mkdir -p $out/nix/store
|
mkdir -p $out/nix/store
|
||||||
for path in $(cat ${o.systemConfiguration}/etc/nix-store-paths) ; do
|
for path in $(cat ${baseSystemConfiguration}/etc/nix-store-paths) ; do
|
||||||
(cd $out && cp -a $path .$path)
|
(cd $out && cp -a $path .$path)
|
||||||
done
|
done
|
||||||
'';
|
'';
|
||||||
|
|
Loading…
Reference in a new issue