at 23.11-pre 1.9 kB view raw
1{ config, pkgs, lib, ... }: 2 3with lib; 4 5let 6 cfg = config.services.cfdyndns; 7in 8{ 9 imports = [ 10 (mkRemovedOptionModule 11 [ "services" "cfdyndns" "apikey" ] 12 "Use services.cfdyndns.apikeyFile instead.") 13 ]; 14 15 options = { 16 services.cfdyndns = { 17 enable = mkEnableOption (lib.mdDoc "Cloudflare Dynamic DNS Client"); 18 19 email = mkOption { 20 type = types.str; 21 description = lib.mdDoc '' 22 The email address to use to authenticate to CloudFlare. 23 ''; 24 }; 25 26 apikeyFile = mkOption { 27 default = null; 28 type = types.nullOr types.str; 29 description = lib.mdDoc '' 30 The path to a file containing the API Key 31 used to authenticate with CloudFlare. 32 ''; 33 }; 34 35 records = mkOption { 36 default = []; 37 example = [ "host.tld" ]; 38 type = types.listOf types.str; 39 description = lib.mdDoc '' 40 The records to update in CloudFlare. 41 ''; 42 }; 43 }; 44 }; 45 46 config = mkIf cfg.enable { 47 systemd.services.cfdyndns = { 48 description = "CloudFlare Dynamic DNS Client"; 49 after = [ "network.target" ]; 50 wantedBy = [ "multi-user.target" ]; 51 startAt = "*:0/5"; 52 serviceConfig = { 53 Type = "simple"; 54 User = config.ids.uids.cfdyndns; 55 Group = config.ids.gids.cfdyndns; 56 }; 57 environment = { 58 CLOUDFLARE_EMAIL="${cfg.email}"; 59 CLOUDFLARE_RECORDS="${concatStringsSep "," cfg.records}"; 60 }; 61 script = '' 62 ${optionalString (cfg.apikeyFile != null) '' 63 export CLOUDFLARE_APIKEY="$(cat ${escapeShellArg cfg.apikeyFile})" 64 ''} 65 ${pkgs.cfdyndns}/bin/cfdyndns 66 ''; 67 }; 68 69 users.users = { 70 cfdyndns = { 71 group = "cfdyndns"; 72 uid = config.ids.uids.cfdyndns; 73 }; 74 }; 75 76 users.groups = { 77 cfdyndns = { 78 gid = config.ids.gids.cfdyndns; 79 }; 80 }; 81 }; 82}