burnham: Add domeneshop-dyndns, make it a module

This commit is contained in:
2024-09-08 01:22:36 +02:00
parent 162134d951
commit 65d5f14fc8
8 changed files with 114 additions and 30 deletions

View File

@@ -11,8 +11,9 @@
./services/wireguard.nix
# Other
./services/thelounge.nix
./services/dyndns.nix
./services/nginx.nix
./services/thelounge.nix
];
boot.loader.systemd-boot.enable = lib.mkForce false;
@@ -30,7 +31,7 @@
hostId = "8e24f235";
};
# sops.defaultSopsFile = ../../secrets/burnham/burnham.yaml;
sops.defaultSopsFile = ../../secrets/burnham/burnham.yaml;
environment.variables = { EDITOR = "vim"; };

View File

@@ -0,0 +1,11 @@
{ config, pkgs, lib, ... }:
{
sops.secrets."domeneshop/netrc" = { };
services.domeneshop-dyndns = {
enable = true;
domain = "site2.feal.no";
netrcFile = config.sops.secrets."domeneshop/netrc".path;
};
}

View File

@@ -1,26 +1,11 @@
{ config, pkgs, lib, ... }:
let
dnsname = "site3.feal.no";
in {
# Defines DDNS_TOKEN and DDNS_SECRET from https://domene.shop/admin?view=api
sops.secrets."domeneshop/env" = { };
{
sops.secrets."domeneshop/netrc" = { };
systemd.services.domeneshop-dyndns = {
serviceConfig.EnvironmentFile = config.sops.secrets."domeneshop/env".path;
startAt = "*/10 * * * *";
script = ''
DNSNAME="${dnsname}"
NEW_IP="$(${lib.getExe pkgs.curl} --silent https://ipinfo.io/ip)"
OLD_IP="$(${lib.getExe pkgs.getent} hosts "$DNSNAME" | ${lib.getExe pkgs.gawk} '{ print $1 }')"
if [[ "$NEW_IP" != "$OLD_IP" ]]; then
echo "Old IP ($OLD_IP) does not match new IP ($NEW_IP), updating..."
${lib.getExe pkgs.curl} --silent "https://$DDNS_TOKEN:$DDNS_SECRET@api.domeneshop.no/v0/dyndns/update?hostname=$DNSNAME&myip=$NEW_IP"
else
echo "Old IP ($OLD_IP) matches new IP ($NEW_IP), exiting..."
fi
'';
services.domeneshop-dyndns = {
enable = true;
domain = "site3.feal.no";
netrcFile = config.sops.secrets."domeneshop/netrc".path;
};
}