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