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 ||
23 ${pkgs.curl}/bin/curl -s4L https://icanhazip.com || true)
24 publicIPv6=$(${pkgs.curl}/bin/curl -s6L https://icanhazip.com || true)
25 privateIPv4=$(${pkgs.miniupnpc}/bin/upnpc -s | sed -ne 's/^Local LAN ip address : //p')
26 ${pkgs.knot-dns}/bin/knsupdate -k ${gnupg.secrets."knot/tsig/${domain}/bureau1.key".path} <<EOF
27 server ns.sourcephile.fr
30 update delete bureau1 A
31 ''${publicIPv4:+update add bureau1 300 A $publicIPv4}
32 update delete bureau1 AAAA
33 ''${publicIPv6:+update add bureau1 300 AAAA $publicIPv6}
34 update delete lan.losurdo A
35 ''${privateIPv4:+update add lan.losurdo 300 A $privateIPv4}
40 Restart = "on-failure";
43 User = users."nsupdate".name;
46 users.users."nsupdate".isSystemUser = true;
47 users.groups."keys".members = [users."nsupdate".name];
48 security.gnupg.secrets."knot/tsig/${domain}/bureau1.key" = {
49 user = users."nsupdate".name;