diff --git a/nixos/ifrit/configuration.nix b/nixos/ifrit/configuration.nix index 882063b..ed63375 100644 --- a/nixos/ifrit/configuration.nix +++ b/nixos/ifrit/configuration.nix @@ -2,35 +2,11 @@ let hostAliases = [ "ifrit.dadada.li" - "bs.vpn.dadada.li" + "vpn.dadada.li" "media.dadada.li" - "backup.dadada.li" + "backup0.dadada.li" ]; backups = "/mnt/storage/backup"; - ddns = hostname: { - timers."ddns-${hostname}" = { - wantedBy = [ "timers.target" ]; - partOf = [ "ddns-${hostname}.service" ]; - timerConfig.OnCalendar = "hourly"; - }; - services."ddns-${hostname}" = { - serviceConfig.Type = "oneshot"; - script = '' - function url() { - echo "https://svc.joker.com/nic/update?username=$1&password=$2&hostname=$3" - } - - IFS=':' - read -r user password < /var/lib/ddns/credentials - unset IFS - - curl_url=$(url "$user" "$password" ${hostname}) - - ${pkgs.curl}/bin/curl -4 "$curl_url" - ${pkgs.curl}/bin/curl -6 "$curl_url" - ''; - }; - }; in { imports = [ @@ -72,6 +48,10 @@ in key = "5EaLm7uC8XzoN8+BaGzgGRUU4q5shM7gQJcs/d7n+Vo="; }; }; + ddns.domains = [ + "vpn.dadada.li" + "backup0.dadada.li" + ]; }; users.users.borg.home = "/mnt/storage/backup"; @@ -202,7 +182,5 @@ in environment.systemPackages = [ pkgs.curl ]; - systemd = (ddns "bs.vpn.dadada.li") // (ddns "backup0.dadada.li"); - system.stateVersion = "20.03"; } diff --git a/nixos/modules/ddns.nix b/nixos/modules/ddns.nix new file mode 100644 index 0000000..2c42ce4 --- /dev/null +++ b/nixos/modules/ddns.nix @@ -0,0 +1,47 @@ +{ config, pkgs, lib, ... }: +with lib; +let + cfg = config.dadada.ddns; + ddnsConfig = hostNames: { + systemd.timers = listToAttrs (forEach hostNames (hostname: nameValuePair "ddns-${hostname}" + { + wantedBy = [ "timers.target" ]; + partOf = [ "ddns-${hostname}.service" ]; + timerConfig.OnCalendar = "hourly"; + })); + + systemd.services = listToAttrs (forEach hostNames (hostname: nameValuePair "ddns-${hostname}" + { + serviceConfig.Type = "oneshot"; + script = '' + function url() { + echo "https://svc.joker.com/nic/update?username=$1&password=$2&hostname=$3" + } + + IFS=':' + read -r user password < /var/lib/ddns/credentials + unset IFS + + curl_url=$(url "$user" "$password" ${hostname}) + + ${pkgs.curl}/bin/curl -4 "$curl_url" + ${pkgs.curl}/bin/curl -6 "$curl_url" + ''; + })); + }; +in { + options = { + dadada.ddns.domains = mkOption { + type = types.listOf types.str; + description = '' + Enables DDNS for these domains. + ''; + example = '' + [ "example.com" ] + ''; + default = []; + }; + }; + + config = ddnsConfig cfg.domains; +} diff --git a/nixos/modules/default.nix b/nixos/modules/default.nix index 1930b23..bb3cf37 100644 --- a/nixos/modules/default.nix +++ b/nixos/modules/default.nix @@ -2,6 +2,7 @@ { admin = import ./admin.nix; backup = import ./backup.nix; + ddns = import ./ddns.nix; element = import ./element.nix; fido2 = import ./fido2.nix; fileShare = import ./fileShare.nix;