nixpkgs/nixos/modules/services/misc/cfdyndns.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

79 lines
2.2 KiB
Nix
Raw Normal View History

2016-01-17 12:11:09 +00:00
{ config, pkgs, lib, ... }:
let
cfg = config.services.cfdyndns;
in
{
imports = [
(lib.mkRemovedOptionModule
[ "services" "cfdyndns" "apikey" ]
"Use services.cfdyndns.apikeyFile instead.")
];
2016-01-17 12:11:09 +00:00
options = {
services.cfdyndns = {
enable = lib.mkEnableOption "Cloudflare Dynamic DNS Client";
2016-01-17 12:11:09 +00:00
email = lib.mkOption {
type = lib.types.str;
2016-01-17 12:11:09 +00:00
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;
2016-01-17 12:11:09 +00:00
description = ''
The path to a file containing the API Key
used to authenticate with CloudFlare.
2016-01-17 12:11:09 +00:00
'';
};
records = lib.mkOption {
2016-01-17 12:11:09 +00:00
default = [];
example = [ "host.tld" ];
type = lib.types.listOf lib.types.str;
2016-01-17 12:11:09 +00:00
description = ''
The records to update in CloudFlare.
'';
};
};
};
config = lib.mkIf cfg.enable {
2016-01-17 12:11:09 +00:00
systemd.services.cfdyndns = {
description = "CloudFlare Dynamic DNS Client";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
startAt = "*:0/5";
2016-01-17 12:11:09 +00:00
serviceConfig = {
Type = "simple";
LoadCredential = lib.optional (cfg.apiTokenFile != null) "CLOUDFLARE_APITOKEN_FILE:${cfg.apiTokenFile}";
DynamicUser = true;
2016-01-17 12:11:09 +00:00
};
environment = {
CLOUDFLARE_RECORDS="${lib.concatStringsSep "," cfg.records}";
2016-01-17 12:11:09 +00:00
};
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
'';
2016-01-17 12:11:09 +00:00
};
};
}