at 25.11-pre 2.7 kB view raw
1{ 2 config, 3 lib, 4 pkgs, 5 ... 6}: 7let 8 cfg = config.services.oink; 9 makeOinkConfig = 10 attrs: 11 (pkgs.formats.json { }).generate "oink.json" ( 12 lib.mapAttrs' (k: v: lib.nameValuePair (lib.toLower k) v) attrs 13 ); 14 oinkConfig = makeOinkConfig { 15 global = cfg.settings; 16 domains = cfg.domains; 17 }; 18in 19{ 20 options.services.oink = { 21 enable = lib.mkEnableOption "Oink, a dynamic DNS client for Porkbun"; 22 package = lib.mkPackageOption pkgs "oink" { }; 23 settings = { 24 apiKey = lib.mkOption { 25 type = lib.types.str; 26 description = "API key to use when modifying DNS records."; 27 }; 28 secretApiKey = lib.mkOption { 29 type = lib.types.str; 30 description = "Secret API key to use when modifying DNS records."; 31 }; 32 interval = lib.mkOption { 33 # https://github.com/rlado/oink/blob/v1.1.1/src/main.go#L364 34 type = lib.types.ints.between 60 172800; # 48 hours 35 default = 900; 36 description = "Seconds to wait before sending another request."; 37 }; 38 ttl = lib.mkOption { 39 type = lib.types.ints.between 600 172800; 40 default = 600; 41 description = '' 42 The TTL ("Time to Live") value to set for your DNS records. 43 44 The TTL controls how long in seconds your records will be cached 45 for. A smaller value will allow the record to update quicker. 46 ''; 47 }; 48 }; 49 domains = lib.mkOption { 50 type = with lib.types; listOf (attrsOf anything); 51 default = [ ]; 52 example = [ 53 { 54 domain = "nixos.org"; 55 subdomain = ""; 56 ttl = 1200; 57 } 58 { 59 domain = "nixos.org"; 60 subdomain = "hydra"; 61 } 62 ]; 63 description = '' 64 List of attribute sets containing configuration for each domain. 65 66 Each attribute set must have two attributes, one named *domain* 67 and another named *subdomain*. The domain attribute must specify 68 the root domain that you want to configure, and the subdomain 69 attribute must specify its subdomain if any. If you want to 70 configure the root domain rather than a subdomain, leave the 71 subdomain attribute as an empty string. 72 73 Additionally, you can use attributes from *services.oink.settings* 74 to override settings per-domain. 75 76 Every domain listed here *must* have API access enabled in 77 Porkbun's control panel. 78 ''; 79 }; 80 }; 81 82 config = lib.mkIf cfg.enable { 83 systemd.services.oink = { 84 description = "Dynamic DNS client for Porkbun"; 85 after = [ "network.target" ]; 86 wantedBy = [ "multi-user.target" ]; 87 script = "${cfg.package}/bin/oink -c ${oinkConfig}"; 88 }; 89 }; 90}