fix(dyndns): finally make it work

This commit is contained in:
2026-02-09 18:16:32 +01:00
parent 037a3c0f10
commit 0ddfd2d3ec
2 changed files with 13 additions and 9 deletions
+9 -6
View File
@@ -3,15 +3,18 @@
pkgs, pkgs,
... ...
}: }:
let
pyenv = pkgs.python3.withPackages (ps: with ps; [ nc-dnsapi ]);
in
{ {
users.groups.dyndns = { }; users.groups.dyndns = { };
users.users.dyndns = { users.users.dyndns = {
isSystemUser = true; isSystemUser = true;
group = "dyndns"; group = "dyndns";
packages = [ pkgs.python313Packages.nc-dnsapi ];
}; };
systemd.timers."dyndns" = { systemd.timers."dyndns" = {
requires = [ "network-online.target" ];
wantedBy = [ "timers.target" ]; wantedBy = [ "timers.target" ];
timerConfig = { timerConfig = {
OnBootSec = "5m"; OnBootSec = "5m";
@@ -22,11 +25,11 @@
systemd.services."dyndns" = { systemd.services."dyndns" = {
script = '' script = ''
NC_CUSTOMER=${"$(cat " + config.age.secrets.nc_customer.path + ")"} NC_CUSTOMER=${"$(cat " + config.age.secrets.nc_customer.path + ")"} \
NC_API_PASSWORD=${"$(cat " + config.age.secrets.nc_api_password.path + ")"} NC_API_PASSWORD=${"$(cat " + config.age.secrets.nc_api_password.path + ")"} \
NC_API_KEY=${"$(cat " + config.age.secrets.nc_api_key.path + ")"} NC_API_KEY=${"$(cat " + config.age.secrets.nc_api_key.path + ")"} \
NC_DOMAIN=${"$(cat " + config.age.secrets.nc_domain.path + ")"} NC_DOMAIN=${"$(cat " + config.age.secrets.nc_domain.path + ")"} \
${pkgs.python313}/bin/python3 -c "${builtins.readFile ./dyndns.py}" ${pyenv.interpreter} ${./dyndns.py}
''; '';
serviceConfig = { serviceConfig = {
Type = "oneshot"; Type = "oneshot";
+4 -3
View File
@@ -6,7 +6,7 @@ api_password = os.environ["NC_API_PASSWORD"]
api_key = os.environ["NC_API_KEY"] api_key = os.environ["NC_API_KEY"]
domain = os.environ["NC_DOMAIN"] domain = os.environ["NC_DOMAIN"]
ip = str(urllib3.request("GET", "https://api.ipify.org").data) ip = urllib3.request("GET", "https://api.ipify.org").data.decode("ascii")
with Client(customer, api_key, api_password) as api: with Client(customer, api_key, api_password) as api:
to_be_updated = [] to_be_updated = []
@@ -21,5 +21,6 @@ with Client(customer, api_key, api_password) as api:
api.update_dns_records(domain, to_be_updated) api.update_dns_records(domain, to_be_updated)
zone = api.dns_zone(domain) zone = api.dns_zone(domain)
zone.ttl = 300 if zone.ttl != 300:
api.update_dns_zone(domain, zone) zone.ttl = 300
api.update_dns_zone(domain, zone)