dyn-gandi/nix/hm-module.nix

72 lines
1.7 KiB
Nix
Raw Normal View History

2023-08-01 19:59:54 +00:00
self: {
config,
lib,
pkgs,
...
}: let
cfg = config.services.dyn-gandi;
2023-08-04 21:10:47 +00:00
package = self.packages.${pkgs.stdenv.hostPlatform.system}.default;
2023-08-01 19:59:54 +00:00
inherit (lib) mkIf mkEnableOption mkOption types;
in {
2023-08-01 19:59:54 +00:00
options.services.dyn-gandi = {
enable = mkEnableOption "dyn-gandi";
2023-08-01 19:59:54 +00:00
timer = lib.mkOption {
2023-08-04 21:10:47 +00:00
type = types.nullOr types.int;
default = null;
2023-08-01 19:59:54 +00:00
description = lib.mdDoc ''
The time intervall in seconds the script should be repeated.
'';
};
settings = mkOption {
type = with types; let
valueType = nullOr (oneOf [
2023-08-04 21:10:47 +00:00
# TODO: restrict type to actual config file structure
2023-08-01 19:59:54 +00:00
bool
int
float
str
path
(attrsOf valueType)
(listOf valueType)
]);
in
valueType;
2023-08-04 21:10:47 +00:00
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
home.packages = [package]; # TODO: make this architecture independent
2023-08-01 19:59:54 +00:00
xdg.configFile."dyn-gandi/config.json" = {
text = builtins.toJSON cfg.settings;
};
2023-08-04 21:10:47 +00:00
systemd.user.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
2023-08-01 19:59:54 +00:00
};
2023-08-04 21:10:47 +00:00
};
systemd.user.timers.dyn-gandi = mkIf (cfg.timer
!= null) {
Install = {WantedBy = ["timers.target"];};
Timer = {
2023-08-01 19:59:54 +00:00
OnBootSec = "0s";
2023-08-04 21:10:47 +00:00
OnUnitActiveSec = "${toString cfg.timer}s";
2023-08-01 19:59:54 +00:00
Unit = "dyn-gandi.service";
};
};
};
}