[nix] allow configuration of triggers/actions in nix
This commit is contained in:
112
flake.nix
112
flake.nix
@@ -47,7 +47,7 @@
|
||||
nixosModules.gokill = { config, lib, pkgs, ... }:
|
||||
let
|
||||
cfg = config.services.gokill;
|
||||
configFile = pkgs.writeText "config.json" ''${cfg.extraConfig}'';
|
||||
configFile = pkgs.writeText "config.json" (builtins.toJSON cfg.triggers);
|
||||
gokill-pkg = self.packages.x86_64-linux.gokill;
|
||||
in
|
||||
{
|
||||
@@ -61,6 +61,45 @@
|
||||
'';
|
||||
};
|
||||
|
||||
triggers = lib.mkOption {
|
||||
description = "list of triggers";
|
||||
default = [];
|
||||
type = with lib.types; lib.types.listOf ( submodule {
|
||||
options = {
|
||||
type = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
};
|
||||
|
||||
name = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
};
|
||||
|
||||
options = lib.mkOption {
|
||||
type = lib.types.attrs;
|
||||
};
|
||||
|
||||
actions = lib.mkOption {
|
||||
description = "list of actions";
|
||||
type = with lib.types; lib.types.listOf ( submodule {
|
||||
options = {
|
||||
type = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
};
|
||||
|
||||
options = lib.mkOption {
|
||||
type = lib.types.attrs;
|
||||
};
|
||||
|
||||
stage = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
};
|
||||
};
|
||||
});
|
||||
};
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
extraConfig = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = lib.mdDoc ''
|
||||
@@ -92,53 +131,30 @@
|
||||
self.nixosModules.gokill
|
||||
{
|
||||
services.gokill.enable = true;
|
||||
services.gokill.extraConfig = ''
|
||||
[
|
||||
{
|
||||
"type": "Timeout",
|
||||
"name": "custom timeout",
|
||||
"options": {
|
||||
"duration": 30
|
||||
},
|
||||
"actions": [
|
||||
{
|
||||
"type": "Print",
|
||||
"options": {
|
||||
"message": "Stage 1 triggered. Waiting 25 seconds"
|
||||
},
|
||||
"stage": 1
|
||||
},
|
||||
{
|
||||
"type": "Timeout",
|
||||
"options": {
|
||||
"duration": 20
|
||||
},
|
||||
"stage": 1
|
||||
},
|
||||
{
|
||||
"type": "Timeout",
|
||||
"options": {
|
||||
"duration": 5
|
||||
},
|
||||
"stage": 2
|
||||
},
|
||||
{
|
||||
"type": "Print",
|
||||
"options": {
|
||||
"message": "Shutdown in 5 seconds..."
|
||||
},
|
||||
"stage": 2
|
||||
},
|
||||
{
|
||||
"type": "Shutdown",
|
||||
"options": {
|
||||
},
|
||||
"stage": 3
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
'';
|
||||
services.gokill.triggers = [
|
||||
{
|
||||
type = "Timeout";
|
||||
name = "custom timeout";
|
||||
options = {
|
||||
duration = 10;
|
||||
};
|
||||
actions = [
|
||||
{
|
||||
type = "Timeout";
|
||||
options = {
|
||||
duration = 5;
|
||||
};
|
||||
stage = 1;
|
||||
}
|
||||
{
|
||||
type = "Shutdown";
|
||||
options = {
|
||||
};
|
||||
stage = 2;
|
||||
}
|
||||
];
|
||||
}
|
||||
];
|
||||
users.users.root.password = "root";
|
||||
virtualisation.vmVariant.virtualisation.graphics = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user