1{ config, pkgs, lib, ... }: 2 3with lib; 4 5let 6 cfg = config.services.cfdyndns; 7in 8{ 9 options = { 10 services.cfdyndns = { 11 enable = mkEnableOption "Cloudflare Dynamic DNS Client"; 12 13 email = mkOption { 14 type = types.str; 15 description = '' 16 The email address to use to authenticate to CloudFlare. 17 ''; 18 }; 19 20 apikey = mkOption { 21 type = types.str; 22 description = '' 23 The API Key to use to authenticate to CloudFlare. 24 ''; 25 }; 26 27 records = mkOption { 28 default = []; 29 example = [ "host.tld" ]; 30 type = types.listOf types.str; 31 description = '' 32 The records to update in CloudFlare. 33 ''; 34 }; 35 }; 36 }; 37 38 config = mkIf cfg.enable { 39 systemd.services.cfdyndns = { 40 description = "CloudFlare Dynamic DNS Client"; 41 after = [ "network.target" ]; 42 wantedBy = [ "multi-user.target" ]; 43 startAt = "5 minutes"; 44 serviceConfig = { 45 Type = "simple"; 46 User = config.ids.uids.cfdyndns; 47 Group = config.ids.gids.cfdyndns; 48 ExecStart = "/bin/sh -c '${pkgs.cfdyndns}/bin/cfdyndns'"; 49 }; 50 environment = { 51 CLOUDFLARE_EMAIL="${cfg.email}"; 52 CLOUDFLARE_APIKEY="${cfg.apikey}"; 53 CLOUDFLARE_RECORDS="${concatStringsSep "," cfg.records}"; 54 }; 55 }; 56 57 users.extraUsers = { 58 cfdyndns = { 59 group = "cfdyndns"; 60 uid = config.ids.uids.cfdyndns; 61 }; 62 }; 63 64 users.extraGroups = { 65 cfdyndns = { 66 gid = config.ids.gids.cfdyndns; 67 }; 68 }; 69 }; 70}