dyn-gandi/nix/module.nix

70 lines
1.5 KiB
Nix
Raw Normal View History

2023-08-13 12:00:02 +00:00
inputs: {
2023-08-03 21:14:04 +00:00
config,
lib,
pkgs,
2023-08-04 21:10:47 +00:00
system,
2023-08-03 21:14:04 +00:00
...
}: let
2023-08-13 12:00:02 +00:00
cfg = config.dyn-gandi;
package = inputs.self.packages.${pkgs.stdenv.hostPlatform.system}.default;
2023-08-04 21:10:47 +00:00
inherit (lib) mkIf mkEnableOption mkOption types;
2023-08-01 19:59:54 +00:00
in {
2023-08-13 12:00:02 +00:00
options.dyn-gandi = {
2023-08-04 21:10:47 +00:00
enable = mkEnableOption "dyn-gandi";
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;
2023-08-13 12:00:02 +00:00
default = throw "Please specify dyn-gandi.settings";
2023-08-04 21:10:47 +00:00
};
2023-08-01 19:59:54 +00:00
};
config = mkIf cfg.enable {
2023-08-04 21:10:47 +00:00
environment = {
systemPackages = [package];
2023-08-13 12:00:02 +00:00
etc."dyn-gandi.json" = {
text = builtins.toJSON cfg.settings;
};
2023-08-04 21:10:47 +00:00
};
systemd.services.dyn-gandi = mkIf (cfg.timer
!= null) {
2023-08-13 12:00:02 +00:00
script = "${package}/bin/dyn_gandi"; # TODO: add config file via command line options
2023-08-04 21:10:47 +00:00
2023-08-13 12:00:02 +00:00
serviceConfig = {
2023-08-04 21:10:47 +00:00
Type = "oneshot";
};
};
systemd.timers.dyn-gandi = mkIf (cfg.timer
!= null) {
2023-08-13 12:00:02 +00:00
wantedBy = ["timers.target"];
timerConfig = {
2023-08-04 21:10:47 +00:00
OnBootSec = "0s";
OnUnitActiveSec = "${toString cfg.timer}s";
Unit = "dyn-gandi.service";
};
};
2023-08-03 21:14:04 +00:00
};
}