Add the possibility to define assertions to be checked before activation.

This commit is contained in:
r-vdp 2023-03-22 15:52:56 +01:00
parent 02a0e81d6d
commit c9a47913f4
No known key found for this signature in database
3 changed files with 105 additions and 2 deletions

View file

@ -14,6 +14,24 @@
type = with lib.types; listOf str;
default = [ ];
};
preActivationAssertions = lib.mkOption {
type = with lib.types; attrsOf (submodule ({ name, ... }: {
options = {
enable = lib.mkEnableOption "the assertion";
name = lib.mkOption {
type = lib.types.str;
default = name;
};
script = lib.mkOption {
type = lib.types.str;
};
};
}));
default = { };
};
};
config = {
@ -46,6 +64,27 @@
}
);
system-manager.preActivationAssertions = {
osVersion =
let
supportedIds = [ "nixos" "ubuntu" ];
in
{
enable = true;
script = ''
source /etc/os-release
${lib.concatStringsSep "\n" (lib.flip map supportedIds (supportedId: ''
if [ $ID = "${supportedId}" ]; then
exit 0
fi
''))}
echo "This OS is not currently supported."
echo "Supported OSs are: ${lib.concatStringsSep ", " supportedIds}"
exit 1
'';
};
};
# Add the system directory for systemd
system-manager.etcFiles = [ "systemd/system" ];