dyn-gandi/nix/module.nix

75 lines
1.7 KiB
Nix
Raw Normal View History

2023-08-04 21:10:47 +00:00
self: {
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-01 19:59:54 +00:00
cfg = config.services.dyn-gandi;
2023-08-04 21:10:47 +00:00
package = self.packages.${pkgs.stdenv.hostPlatform.system}.default;
inherit (lib) mkIf mkEnableOption mkOption types;
2023-08-01 19:59:54 +00:00
in {
options.services.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;
default = throw "Please specify services.dyn-gandi.settings";
};
2023-08-01 19:59:54 +00:00
};
config = mkIf cfg.enable {
2023-08-04 21:10:47 +00:00
environment = {
systemPackages = [package];
}; # TODO: make this architecture independent
xdg.configFile."dyn-gandi/config.json" = {
text = builtins.toJSON cfg.settings;
};
systemd.services.dyn-gandi = mkIf (cfg.timer
!= null) {
Unit = {
After = ["network.target"];
};
Install = {WantedBy = ["default.target"];};
Service = {
Type = "oneshot";
ExecStart = "${package}/bin/dyn_gandi"; # TODO: add config file via command line options
};
};
systemd.timers.dyn-gandi = mkIf (cfg.timer
!= null) {
Install = {WantedBy = ["timers.target"];};
Timer = {
OnBootSec = "0s";
OnUnitActiveSec = "${toString cfg.timer}s";
Unit = "dyn-gandi.service";
};
};
2023-08-03 21:14:04 +00:00
};
}