finished and working
This commit is contained in:
66
nix/module.nix
Normal file
66
nix/module.nix
Normal file
@ -0,0 +1,66 @@
|
||||
inputs: {
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
system,
|
||||
...
|
||||
}: let
|
||||
cfg = config.outage-detector;
|
||||
package = inputs.self.packages.${pkgs.stdenv.hostPlatform.system}.default;
|
||||
inherit (lib) mkIf mkEnableOption mkOption types;
|
||||
|
||||
format = pkgs.formats.json {};
|
||||
configFile = format.generate "config.json" cfg.settings;
|
||||
in {
|
||||
options.outage-detector = {
|
||||
enable = mkEnableOption "outage-detector";
|
||||
|
||||
timer = lib.mkOption {
|
||||
type = types.nullOr types.int;
|
||||
default = null;
|
||||
description = lib.mdDoc ''
|
||||
The time intervall in seconds the script should be repeated.
|
||||
'';
|
||||
};
|
||||
|
||||
settings = mkOption {
|
||||
type = with types; let
|
||||
valueType = nullOr (oneOf [
|
||||
# TODO: restrict type to actual config file structure
|
||||
bool
|
||||
int
|
||||
float
|
||||
str
|
||||
path
|
||||
(attrsOf valueType)
|
||||
(listOf valueType)
|
||||
]);
|
||||
in
|
||||
valueType;
|
||||
default = throw "Please specify outage-detector.settings";
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
environment.systemPackages = [package];
|
||||
|
||||
systemd.services.outage-detector = mkIf (cfg.timer
|
||||
!= null) {
|
||||
script = "${package}/bin/outage_detector --config ${configFile}";
|
||||
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
};
|
||||
};
|
||||
|
||||
systemd.timers.outage-detector = mkIf (cfg.timer
|
||||
!= null) {
|
||||
wantedBy = ["timers.target"];
|
||||
timerConfig = {
|
||||
OnBootSec = "0s";
|
||||
OnUnitActiveSec = "${toString cfg.timer}s";
|
||||
Unit = "outage-detector.service";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user