NixOS/modules/scripts/update-dns.nix

51 lines
1.2 KiB
Nix

{
config,
pkgs,
lib,
...
}:
{
imports = [ ./base.nix ];
config = {
sops.secrets = {
cloudflare-api.sopsFile = ../../secrets/env.yaml;
dns = {
sopsFile = ../../secrets/env.yaml;
owner = config.users.users.jawz.name;
inherit (config.users.users.jawz) group;
};
};
services.cloudflare-dyndns = {
inherit (config.my.scripts.update-dns) enable;
ipv4 = true;
ipv6 = false;
proxied = false;
domains = [
config.my.domain
"wedsgk5ac2qcaf9yb.click"
];
apiTokenFile = config.sops.secrets.cloudflare-api.path;
};
my.scripts.update-dns = {
enable = lib.mkDefault false;
install = true;
service = true;
name = "update-dns";
timer = "*:0/30";
description = "Updates the IP of all my domains";
package =
let
update-dns = pkgs.writeScriptBin "update-dns" (builtins.readFile ../../scripts/update-dns.sh);
in
pkgs.writeScriptBin "update-dns" ''
#!/usr/bin/env nix-shell
#! nix-shell -i bash -p bash curl
set -a
source ${config.sops.secrets.dns.path}
set -a
${update-dns}/bin/update-dns
'';
};
};
}