nixpkgs/nixos/modules/services/misc/cfdyndns.nix
Silvan Mosberger 4f0dadbf38 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build a08b3a4d19.tar.gz \
      --argstr baseRev b32a094368
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:26:33 +01:00

87 lines
2.2 KiB
Nix

{
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
'';
};
};
}