2016-01-17 12:11:09 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.cfdyndns;
|
|
|
|
in
|
|
|
|
{
|
2020-11-01 18:26:15 +00:00
|
|
|
imports = [
|
|
|
|
(mkRemovedOptionModule
|
|
|
|
[ "services" "cfdyndns" "apikey" ]
|
|
|
|
"Use services.cfdyndns.apikeyFile instead.")
|
|
|
|
];
|
|
|
|
|
2016-01-17 12:11:09 +00:00
|
|
|
options = {
|
|
|
|
services.cfdyndns = {
|
|
|
|
enable = mkEnableOption "Cloudflare Dynamic DNS Client";
|
|
|
|
|
|
|
|
email = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
The email address to use to authenticate to CloudFlare.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-11-01 18:26:15 +00:00
|
|
|
apikeyFile = mkOption {
|
|
|
|
default = null;
|
|
|
|
type = types.nullOr types.str;
|
2016-01-17 12:11:09 +00:00
|
|
|
description = ''
|
2020-11-01 18:26:15 +00:00
|
|
|
The path to a file containing the API Key
|
|
|
|
used to authenticate with CloudFlare.
|
2016-01-17 12:11:09 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
records = mkOption {
|
|
|
|
default = [];
|
|
|
|
example = [ "host.tld" ];
|
|
|
|
type = types.listOf types.str;
|
|
|
|
description = ''
|
|
|
|
The records to update in CloudFlare.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.cfdyndns = {
|
|
|
|
description = "CloudFlare Dynamic DNS Client";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2021-10-03 06:06:37 +01:00
|
|
|
startAt = "*:0/5";
|
2016-01-17 12:11:09 +00:00
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
|
|
|
User = config.ids.uids.cfdyndns;
|
|
|
|
Group = config.ids.gids.cfdyndns;
|
|
|
|
};
|
|
|
|
environment = {
|
|
|
|
CLOUDFLARE_EMAIL="${cfg.email}";
|
|
|
|
CLOUDFLARE_RECORDS="${concatStringsSep "," cfg.records}";
|
|
|
|
};
|
2020-11-01 18:26:15 +00:00
|
|
|
script = ''
|
|
|
|
${optionalString (cfg.apikeyFile != null) ''
|
|
|
|
export CLOUDFLARE_APIKEY="$(cat ${escapeShellArg cfg.apikeyFile})"
|
|
|
|
''}
|
|
|
|
${pkgs.cfdyndns}/bin/cfdyndns
|
|
|
|
'';
|
2016-01-17 12:11:09 +00:00
|
|
|
};
|
|
|
|
|
2018-06-30 00:58:35 +01:00
|
|
|
users.users = {
|
2016-01-17 12:11:09 +00:00
|
|
|
cfdyndns = {
|
|
|
|
group = "cfdyndns";
|
|
|
|
uid = config.ids.uids.cfdyndns;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-06-30 00:58:35 +01:00
|
|
|
users.groups = {
|
2016-01-17 12:11:09 +00:00
|
|
|
cfdyndns = {
|
|
|
|
gid = config.ids.gids.cfdyndns;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|