1 { config, lib, pkgs, ... }:
6 cfg = config.services.oink;
7 makeOinkConfig = attrs: (pkgs.formats.json { }).generate
8 "oink.json" (mapAttrs' (k: v: nameValuePair (toLower k) v) attrs);
9 oinkConfig = makeOinkConfig {
10 global = cfg.settings;
11 domains = cfg.domains;
15 options.services.oink = {
16 enable = mkEnableOption "Oink, a dynamic DNS client for Porkbun";
17 package = mkPackageOption pkgs "oink" { };
21 description = "API key to use when modifying DNS records.";
23 secretApiKey = mkOption {
25 description = "Secret API key to use when modifying DNS records.";
28 # https://github.com/rlado/oink/blob/v1.1.1/src/main.go#L364
29 type = types.ints.between 60 172800; # 48 hours
31 description = "Seconds to wait before sending another request.";
34 type = types.ints.between 600 172800;
37 The TTL ("Time to Live") value to set for your DNS records.
39 The TTL controls how long in seconds your records will be cached
40 for. A smaller value will allow the record to update quicker.
45 type = with types; listOf (attrsOf anything);
59 List of attribute sets containing configuration for each domain.
61 Each attribute set must have two attributes, one named *domain*
62 and another named *subdomain*. The domain attribute must specify
63 the root domain that you want to configure, and the subdomain
64 attribute must specify its subdomain if any. If you want to
65 configure the root domain rather than a subdomain, leave the
66 subdomain attribute as an empty string.
68 Additionally, you can use attributes from *services.oink.settings*
69 to override settings per-domain.
71 Every domain listed here *must* have API access enabled in
72 Porkbun's control panel.
77 config = mkIf cfg.enable {
78 systemd.services.oink = {
79 description = "Dynamic DNS client for Porkbun";
80 after = [ "network.target" ];
81 wantedBy = [ "multi-user.target" ];
82 script = "${cfg.package}/bin/oink -c ${oinkConfig}";