1 { pkgs, lib, config, hosts, ... }:
3 inherit (config.security) gnupg;
4 inherit (config.users) users groups;
5 inherit (config.networking) domain;
8 systemd.services.nsupdate = {
10 "network-online.target"
11 gnupg.secrets."knot/tsig/${domain}/bureau1.key".service
14 gnupg.secrets."knot/tsig/${domain}/bureau1.key".service
16 wantedBy = [ "multi-user.target" ];
17 startAt = "*:0/5"; # every 5 min
20 ExecStart = pkgs.writeShellScript "nsupdate" ''
22 publicIPv4=$(${pkgs.curl}/bin/curl -s4 https://whoami.sourcephile.fr/addr || true)
23 publicIPv6=$(${pkgs.curl}/bin/curl -s6L https://icanhazip.com || true)
24 privateIPv4=$(${pkgs.miniupnpc}/bin/upnpc -s | sed -ne 's/^Local LAN ip address : //p')
25 ${pkgs.knot-dns}/bin/knsupdate -k ${gnupg.secrets."knot/tsig/${domain}/bureau1.key".path} <<EOF
26 server ns.sourcephile.fr
29 update delete bureau1 A
30 ''${publicIPv4:+update add bureau1 300 A $publicIPv4}
31 update delete bureau1 AAAA
32 ''${publicIPv6:+update add bureau1 300 AAAA $publicIPv6}
33 update delete lan.losurdo A
34 ''${privateIPv4:+update add lan.losurdo 300 A $privateIPv4}
39 Restart = "on-failure";
42 User = users."nsupdate".name;
45 users.users."nsupdate".isSystemUser = true;
46 users.users."nsupdate".extraGroups = [ groups."keys".name ];
47 security.gnupg.secrets."knot/tsig/${domain}/bureau1.key" = {
48 user = users."nsupdate".name;