119 lines
2.8 KiB
Nix
119 lines
2.8 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
with lib;
|
|
let
|
|
cfg = config.services.ionos-dyndns;
|
|
ionos-dyndns = pkgs.callPackage ../packages/ionos-dyndns.nix {};
|
|
|
|
command = lib.concatStringsSep " " (
|
|
[
|
|
"${ionos-dyndns}/bin/ionos-dyndns"
|
|
"--api-prefix"
|
|
"$(cat ${cfg.apiPrefixPath})"
|
|
"--api-secret"
|
|
"$(cat ${cfg.apiSecretPath})"
|
|
"--fqdn"
|
|
cfg.fqdn
|
|
"--interface"
|
|
cfg.interface
|
|
]
|
|
++ lib.optionals cfg.a [ "--A" ]
|
|
++ lib.optionals cfg.aaaa [ "--AAAA" ]
|
|
);
|
|
in {
|
|
options = {
|
|
services.ionos-dyndns = {
|
|
enable = mkOption {
|
|
type = types.bool;
|
|
default = false;
|
|
description = ''
|
|
Whether to turn on the IONOS DynDNS timer.
|
|
'';
|
|
};
|
|
user = mkOption {
|
|
type = types.str;
|
|
default = "ionos-dyndns";
|
|
};
|
|
apiPrefixPath = mkOption {
|
|
type = types.path;
|
|
description = ''
|
|
Path of a file holding the API prefix.
|
|
'';
|
|
};
|
|
apiSecretPath = mkOption {
|
|
type = types.path;
|
|
description = ''
|
|
Path of a file holding the API secret.
|
|
'';
|
|
};
|
|
a = mkOption {
|
|
type = types.bool;
|
|
default = false;
|
|
description = ''
|
|
Whether to set the A record (IPv4).
|
|
'';
|
|
};
|
|
aaaa = mkOption {
|
|
type = types.bool;
|
|
default = false;
|
|
description = ''
|
|
Whether to set the AAAA record (IPv6).
|
|
'';
|
|
};
|
|
fqdn = mkOption {
|
|
type = types.str;
|
|
description = ''
|
|
Fully qualified domain name for this host.
|
|
'';
|
|
};
|
|
interface = mkOption {
|
|
type = types.str;
|
|
description = ''
|
|
Interface to get the IP address from.
|
|
'';
|
|
};
|
|
interval = mkOption {
|
|
type = types.str;
|
|
default = "14m";
|
|
description = "How often to run the update script in systemd.timers notation.";
|
|
};
|
|
serviceName = mkOption {
|
|
type = types.str;
|
|
default = "ionos-dyndns";
|
|
};
|
|
};
|
|
};
|
|
config = mkIf cfg.enable {
|
|
users = {
|
|
users = {
|
|
${cfg.user} = {
|
|
isSystemUser = true;
|
|
group = cfg.user;
|
|
description = "IONOS DynDNS user.";
|
|
};
|
|
};
|
|
groups = {
|
|
${cfg.user} = {
|
|
};
|
|
};
|
|
};
|
|
systemd = {
|
|
services.${cfg.serviceName} = {
|
|
serviceConfig = {
|
|
Type = "oneshot";
|
|
User = cfg.user;
|
|
# We assume that command doesn't contain any single quotes
|
|
ExecStart = "${pkgs.bash}/bin/bash -c '${command}'";
|
|
};
|
|
};
|
|
timers.${cfg.serviceName} = {
|
|
wantedBy = [ "timers.target" ];
|
|
timerConfig = {
|
|
Unit = "${cfg.serviceName}.service";
|
|
OnBootSec = "30s";
|
|
OnActiveSec = cfg.interval;
|
|
};
|
|
};
|
|
};
|
|
};
|
|
}
|