From 25c9699ac43d38de0a561887a73a4371eb97516f Mon Sep 17 00:00:00 2001 From: kiskaadee Date: Sun, 28 Jun 2026 13:46:04 -0500 Subject: [PATCH] refactor(infra): migrate ddclient configuration to standalone template - Extract hardcoded `ddclient.conf` into a dedicated file to improve readability and enable native syntax highlighting. - Refactor `dynu.nix` to use `builtins.readFile` and `builtins.replaceStrings` for dynamic secret injection. - Harden `ddclient` operational parameters: Remove `daemon=0` to force foreground execution and add `usev4=webv4` for explicit WAN IP discovery. Rationale: Eliminates fragile string-concatenation logic in Nix files and solves IP-resolution failures by ensuring the service executes in a controlled, foreground-reporting state. --- hosts/desktop/ddclient.conf | 11 +++++++++++ hosts/desktop/dynu.nix | 21 ++++++++------------- 2 files changed, 19 insertions(+), 13 deletions(-) create mode 100644 hosts/desktop/ddclient.conf diff --git a/hosts/desktop/ddclient.conf b/hosts/desktop/ddclient.conf new file mode 100644 index 0000000..4a6cb40 --- /dev/null +++ b/hosts/desktop/ddclient.conf @@ -0,0 +1,11 @@ +# General configuration +syslog=yes +pid=/run/ddclient/ddclient.pid +usev4=webv4 + +# Provider definition using credentials decrypted at runtime +protocol=dyndns2 +server=api.dynu.com +login=@dynu_user@ +password=@dynu_password@ +@dynu_domain@ diff --git a/hosts/desktop/dynu.nix b/hosts/desktop/dynu.nix index acd8edf..071d0e2 100644 --- a/hosts/desktop/dynu.nix +++ b/hosts/desktop/dynu.nix @@ -25,19 +25,14 @@ in # Assemble the ddclient config file securely at boot time in /run/secrets/ # Defaults to owner root:root (which avoids dynamic user evaluation issues) sops.templates."ddclient.conf" = { - content = '' - # General configuration - daemon=0 - syslog=yes - pid=/run/ddclient/ddclient.pid - - # Provider definition using credentials decrypted at runtime - protocol=dyndns2 - server=api.dynu.com - login=${config.sops.placeholder.dynu_user} - password=${config.sops.placeholder.dynu_password} - ${config.sops.placeholder.dynu_domain} - ''; + content = builtins.replaceStrings + [ "@dynu_user@" "@dynu_password@" "@dynu_domain@" ] + [ + config.sops.placeholder.dynu_user + config.sops.placeholder.dynu_password + config.sops.placeholder.dynu_domain + ] + (builtins.readFile ./ddclient.conf); }; # 2. Enable ddclient and feed it the decrypted configuration template via systemd credentials