fixup hostname for vpn

This commit is contained in:
Tim Schubert 2022-04-13 17:26:55 +02:00
parent 743b84363c
commit 38e910fb46
Signed by: dadada
GPG key ID: EEB8D1CE62C4DFEA
3 changed files with 54 additions and 28 deletions

47
nixos/modules/ddns.nix Normal file
View file

@ -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;
}

View file

@ -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;