+/config

my dotfiles and nix configuration

git clone https://git.julia.blue/+/config

Julia RyanUpdate webserver config7238195

main
2.0 KiB58 linesraw
1{ config, lib, pkgs, ... }: let
2  cfg = config.services.porkbun-ddns;
3  types = lib.types;
4in {
5  options.services.porkbun-ddns = {
6    enable = lib.mkEnableOption ''
7      Simple Dynamic DNS client for porkbun that points domains at your current ip
8    '';
9    domains = lib.mkOption {
10      type = types.listOf types.str;
11      description = "A list of domain names to update the DNS entries for";
12    };
13    api-key = lib.mkOption {
14      type = types.path;
15      description = "A file containing your porkbun api key";
16    };
17    secret-key = lib.mkOption {
18      type = types.path;
19      description = "A file containing your porkbun api secret";
20    };
21    ipv4 = lib.mkOption {
22      type = types.bool;
23      description = "Set A records for your domain(s)";
24      default = true;
25    };
26    ipv6 = lib.mkOption {
27      type = types.bool;
28      description = "Set AAAA records for your domain(s)";
29    };
30    ttl = lib.mkOption {
31      default = 21600;
32      type = types.ints.unsigned;
33      description = lib.mdDoc "The [Time to Live](https://developers.cloudflare.com/dns/manage-dns-records/reference/ttl/) for new DNS records in seconds";
34    };
35    frequency = lib.mkOption {
36      default = "00/6:00";
37      type = types.str;
38      description = lib.mdDoc ''
39        How often to run update the DNS records, specified as a [systemd calendar expression](https://www.freedesktop.org/software/systemd/man/latest/systemd.time.html#Calendar%20Events)
40      '';
41    };
42  };
43
44  config = lib.mkIf cfg.enable {
45    systemd.services.porkbun-ddns = {
46      description = "Update porkbun DNS entry to point to this computer";
47      startAt = cfg.frequency;
48      script = ''
49        export PORKBUN_API_KEY=`<${cfg.api-key}`
50        export PORKBUN_API_SECRET=`<${cfg.secret-key}`
51        ${lib.getExe pkgs.porkbun-ddns} \
52            ${if cfg.ipv4 then "-4" else ""} \
53            ${if cfg.ipv6 then "-6" else ""} \
54            --ttl ${toString cfg.ttl} \
55            ${builtins.concatStringsSep " " cfg.domains}'';
56    };
57  };
58}