2023-02-25 01:29:13 +01:00
|
|
|
{ config, pkgs, lib, ... }:
|
2023-03-11 00:30:24 +01:00
|
|
|
let
|
|
|
|
cfg = config.services.domeneshop-updater;
|
|
|
|
in
|
2023-02-25 01:29:13 +01:00
|
|
|
{
|
|
|
|
# auto domain update
|
|
|
|
|
2023-03-11 00:30:24 +01:00
|
|
|
options = with lib; {
|
2023-06-23 21:14:55 +02:00
|
|
|
services.domeneshop-updater.targets = mkOption {
|
|
|
|
type = with types; listOf str;
|
|
|
|
#default = [ config.networking.fqdn ];
|
2023-02-25 01:29:13 +01:00
|
|
|
};
|
|
|
|
};
|
2023-03-11 00:30:24 +01:00
|
|
|
|
|
|
|
config = {
|
|
|
|
|
|
|
|
systemd.services.domeneshop-updater = {
|
|
|
|
description = "domene.shop dyndns domain updater";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network-online.target" ];
|
|
|
|
wants = [ "network-online.target" ];
|
|
|
|
serviceConfig = let
|
|
|
|
prog = pkgs.writeShellApplication {
|
|
|
|
name = "domeneshop-dyndns-updater.sh";
|
|
|
|
runtimeInputs = with pkgs; [ curl yq ];
|
|
|
|
text = ''
|
|
|
|
test -s /var/lib/secrets/domeneshop.toml || {
|
|
|
|
>&2 echo "ERROR: /var/lib/secrets/domeneshop.toml not found!"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
DOMENESHOP_TOKEN="$( tomlq </var/lib/secrets/domeneshop.toml .secrets.DOMENESHOP_TOKEN --raw-output)"
|
|
|
|
DOMENESHOP_SECRET="$(tomlq </var/lib/secrets/domeneshop.toml .secrets.DOMENESHOP_SECRET --raw-output)"
|
2023-06-23 21:14:55 +02:00
|
|
|
${lib.concatMapStringsSep "\n" (target: ''
|
|
|
|
curl https://"$DOMENESHOP_TOKEN":"$DOMENESHOP_SECRET"@api.domeneshop.no/v0/dyndns/update?hostname=${target}
|
|
|
|
'') cfg.targets}
|
2023-03-11 00:30:24 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
User = "domeneshop";
|
|
|
|
Group = "domeneshop";
|
2023-10-03 14:11:23 +02:00
|
|
|
#DynamicUser = true; # maybe re-enable when sops-nix is in place?
|
2023-03-11 00:30:24 +01:00
|
|
|
ExecStart = "${prog}/bin/domeneshop-dyndns-updater.sh";
|
|
|
|
PrivateTmp = true;
|
|
|
|
};
|
2023-02-25 01:29:13 +01:00
|
|
|
};
|
2023-03-11 00:30:24 +01:00
|
|
|
systemd.timers.domeneshop-updater = let interval = "2h"; in {
|
|
|
|
description = "Update domene.shop every ${interval}";
|
|
|
|
wantedBy = [ "timers.target" ];
|
|
|
|
timerConfig = {
|
|
|
|
OnBootSec = "5m";
|
|
|
|
OnUnitInactiveSec = interval;
|
|
|
|
Unit = "domeneshop-updater.service";
|
|
|
|
};
|
|
|
|
};
|
2023-10-03 14:11:23 +02:00
|
|
|
users.users.domeneshop.isSystemUser = true;
|
|
|
|
users.users.group = "domeneshop";
|
|
|
|
users.groups.domeneshop = {};
|
2023-03-11 00:30:24 +01:00
|
|
|
|
2023-02-25 01:29:13 +01:00
|
|
|
};
|
|
|
|
}
|