domeneshop: don't set temporary ipv6

fucks you up on restart
This commit is contained in:
Peder Bergebakken Sundt 2024-10-30 17:02:21 +01:00
parent 5e261ca6d6
commit 60b890b566
1 changed files with 26 additions and 3 deletions

View File

@ -5,10 +5,12 @@ in
{ {
# auto domain update # auto domain update
# TODO: ensure dns64 does not interfere with this
options = with lib; { options = with lib; {
services.domeneshop-updater.targets = mkOption { services.domeneshop-updater.targets = mkOption {
type = with types; listOf str; type = with types; listOf str;
#default = [ config.networking.fqdn ]; example = [ config.networking.fqdn ];
}; };
}; };
@ -33,7 +35,7 @@ in
serviceConfig = let serviceConfig = let
prog = pkgs.writeShellApplication { prog = pkgs.writeShellApplication {
name = "domeneshop-dyndns-updater.sh"; name = "domeneshop-dyndns-updater.sh";
runtimeInputs = with pkgs; [ curl yq ]; runtimeInputs = with pkgs; [ curl iproute2 jq ];
text = '' text = ''
test -s /run/secrets/domeneshop/token || { test -s /run/secrets/domeneshop/token || {
>&2 echo "ERROR: /run/secrets/domeneshop/token not found!" >&2 echo "ERROR: /run/secrets/domeneshop/token not found!"
@ -45,8 +47,29 @@ in
} }
DOMENESHOP_TOKEN="$( cat /run/secrets/domeneshop/token)" DOMENESHOP_TOKEN="$( cat /run/secrets/domeneshop/token)"
DOMENESHOP_SECRET="$(cat /run/secrets/domeneshop/secret)" DOMENESHOP_SECRET="$(cat /run/secrets/domeneshop/secret)"
# get stable ipv6 addr, fallback to ipv4, fallback to curl default
IF=$(
ip -6 -json addr show scope global -temporary \
| jq '.[]| select(.ifname|contains("docker")|not) | .addr_info[].local | select(.==null|not)' -r \
| head -n1
)
if [[ -z "$IF" ]]; then
IF=$(
ip -4 -json addr show scope global -temporary \
| jq '.[]| select(.ifname|contains("docker")|not) | .addr_info[].local | select(.==null|not)' -r \
| head -n1
)
fi
if [[ -n "$IF" ]]; then
IF="--interface $IF"
else
IF=""
fi
${lib.concatMapStringsSep "\n" (target: '' ${lib.concatMapStringsSep "\n" (target: ''
curl https://"$DOMENESHOP_TOKEN":"$DOMENESHOP_SECRET"@api.domeneshop.no/v0/dyndns/update?hostname="${target}" # shellcheck disable=SC2086
curl $IF https://"$DOMENESHOP_TOKEN":"$DOMENESHOP_SECRET"@api.domeneshop.no/v0/dyndns/update?hostname="${target}"
'') cfg.targets} '') cfg.targets}
''; '';
}; };