1 { config, pkgs, lib, ... }:
6 cfg = config.services.cloudflare-dyndns;
10 services.cloudflare-dyndns = {
11 enable = mkEnableOption (lib.mdDoc "Cloudflare Dynamic DNS Client");
13 apiTokenFile = mkOption {
14 type = types.nullOr types.str;
16 description = lib.mdDoc ''
17 The path to a file containing the CloudFlare API token.
19 The file must have the form `CLOUDFLARE_API_TOKEN=...`
24 type = types.listOf types.str;
26 description = lib.mdDoc ''
27 List of domain names to update records for.
34 description = lib.mdDoc ''
35 Whether this is a DNS-only record, or also being proxied through CloudFlare.
42 description = lib.mdDoc ''
43 Whether to enable setting IPv4 A records.
50 description = lib.mdDoc ''
51 Whether to enable setting IPv6 AAAA records.
55 deleteMissing = mkOption {
58 description = lib.mdDoc ''
59 Whether to delete the record when no IP address is found.
65 config = mkIf cfg.enable {
66 systemd.services.cloudflare-dyndns = {
67 description = "CloudFlare Dynamic DNS Client";
68 after = [ "network.target" ];
69 wantedBy = [ "multi-user.target" ];
73 CLOUDFLARE_DOMAINS = toString cfg.domains;
79 StateDirectory = "cloudflare-dyndns";
80 EnvironmentFile = cfg.apiTokenFile;
83 args = [ "--cache-file /var/lib/cloudflare-dyndns/ip.cache" ]
84 ++ (if cfg.ipv4 then [ "-4" ] else [ "-no-4" ])
85 ++ (if cfg.ipv6 then [ "-6" ] else [ "-no-6" ])
86 ++ optional cfg.deleteMissing "--delete-missing"
87 ++ optional cfg.proxied "--proxied";
89 "${pkgs.cloudflare-dyndns}/bin/cloudflare-dyndns ${toString args}";