1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7
8with lib;
9
10let
11 cfg = config.services.r53-ddns;
12 pkg = pkgs.r53-ddns;
13in
14{
15 options = {
16 services.r53-ddns = {
17
18 enable = mkEnableOption "r53-ddyns";
19
20 interval = mkOption {
21 type = types.str;
22 default = "15min";
23 description = "How often to update the entry";
24 };
25
26 zoneID = mkOption {
27 type = types.str;
28 description = "The ID of your zone in Route53";
29 };
30
31 domain = mkOption {
32 type = types.str;
33 description = "The name of your domain in Route53";
34 };
35
36 hostname = mkOption {
37 type = types.str;
38 description = ''
39 Manually specify the hostname. Otherwise the tool will try to use the name
40 returned by the OS (Call to gethostname)
41 '';
42 };
43
44 ttl = mkOption {
45 type = types.int;
46 description = "The TTL for the generated record";
47 };
48
49 environmentFile = mkOption {
50 type = types.str;
51 description = ''
52 File containing the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
53 in the format of an EnvironmentFile as described by {manpage}`systemd.exec(5)`
54 '';
55 };
56
57 };
58 };
59
60 config = mkIf cfg.enable {
61
62 systemd.timers.r53-ddns = {
63 description = "r53-ddns timer";
64 wantedBy = [ "timers.target" ];
65 timerConfig = {
66 OnBootSec = cfg.interval;
67 OnUnitActiveSec = cfg.interval;
68 };
69 };
70
71 systemd.services.r53-ddns = {
72 description = "r53-ddns service";
73 serviceConfig = {
74 ExecStart =
75 "${pkg}/bin/r53-ddns -zone-id ${cfg.zoneID} -domain ${cfg.domain}"
76 + lib.optionalString (cfg.hostname != null) " -hostname ${cfg.hostname}"
77 + lib.optionalString (cfg.ttl != null) " -ttl ${toString cfg.ttl}";
78 EnvironmentFile = "${cfg.environmentFile}";
79 DynamicUser = true;
80 };
81 };
82
83 };
84}