-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
/
Copy pathcfdyndns.nix
87 lines (81 loc) · 2.21 KB
/
cfdyndns.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
{
config,
pkgs,
lib,
...
}:
let
cfg = config.services.cfdyndns;
in
{
imports = [
(lib.mkRemovedOptionModule [
"services"
"cfdyndns"
"apikey"
] "Use services.cfdyndns.apikeyFile instead.")
];
options = {
services.cfdyndns = {
enable = lib.mkEnableOption "Cloudflare Dynamic DNS Client";
email = lib.mkOption {
type = lib.types.str;
description = ''
The email address to use to authenticate to CloudFlare.
'';
};
apiTokenFile = lib.mkOption {
default = null;
type = lib.types.nullOr lib.types.str;
description = ''
The path to a file containing the API Token
used to authenticate with CloudFlare.
'';
};
apikeyFile = lib.mkOption {
default = null;
type = lib.types.nullOr lib.types.str;
description = ''
The path to a file containing the API Key
used to authenticate with CloudFlare.
'';
};
records = lib.mkOption {
default = [ ];
example = [ "host.tld" ];
type = lib.types.listOf lib.types.str;
description = ''
The records to update in CloudFlare.
'';
};
};
};
config = lib.mkIf cfg.enable {
systemd.services.cfdyndns = {
description = "CloudFlare Dynamic DNS Client";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
startAt = "*:0/5";
serviceConfig = {
Type = "simple";
LoadCredential = lib.optional (
cfg.apiTokenFile != null
) "CLOUDFLARE_APITOKEN_FILE:${cfg.apiTokenFile}";
DynamicUser = true;
};
environment = {
CLOUDFLARE_RECORDS = "${lib.concatStringsSep "," cfg.records}";
};
script = ''
${lib.optionalString (cfg.apikeyFile != null) ''
export CLOUDFLARE_APIKEY="$(cat ${lib.escapeShellArg cfg.apikeyFile})"
export CLOUDFLARE_EMAIL="${cfg.email}"
''}
${lib.optionalString (cfg.apiTokenFile != null) ''
export CLOUDFLARE_APITOKEN=$(${pkgs.systemd}/bin/systemd-creds cat CLOUDFLARE_APITOKEN_FILE)
''}
${pkgs.cfdyndns}/bin/cfdyndns
'';
};
};
}