Skip to content

Commit

Permalink
Reformat duckdns.nix
Browse files Browse the repository at this point in the history
  • Loading branch information
notthebee committed Oct 26, 2024
1 parent 44ed6f9 commit cae5068
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions nixos/modules/services/misc/duckdns.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{ config, pkgs, lib, ... }:
{
config,
pkgs,
lib,
...
}:
let
cfg = config.services.duckdns;
cfg = config.services.duckdns;
in
{
options.services.duckdns = {
Expand All @@ -12,7 +17,7 @@ in
description = ''
The path to a file containing the token
used to authenticate with DuckDNS.
'';
'';
};

domains = lib.mkOption {
Expand All @@ -22,7 +27,7 @@ in
description = ''
The record(s) to update in DuckDNS
(without the .duckdns.org prefix)
'';
'';
};

domainsFile = lib.mkOption {
Expand All @@ -32,17 +37,17 @@ in
The path to a file containing a
newline-separated list of DuckDNS
domain(s) to be updated
'';
'';
};

};

config = lib.mkIf cfg.enable {
assertions = [
{
assertion = (cfg.domains != null || cfg.domainsFile != null);
message = "services.duckdns.domains or services.duckdns.domainsFile has to be defined";
}
{
assertion = (cfg.domains != null || cfg.domainsFile != null);
message = "services.duckdns.domains or services.duckdns.domainsFile has to be defined";
}
];
systemd.services.duckdns = {
description = "DuckDNS Dynamic DNS Client";
Expand All @@ -62,15 +67,17 @@ in
DynamicUser = true;
};
script = ''
export DUCKDNS_TOKEN=$(systemd-creds cat DUCKDNS_TOKEN_FILE)
${lib.optionalString (cfg.domains != null) ''
export DUCKDNS_DOMAINS='${lib.strings.concatStringsSep "," cfg.domains}'
''}
${lib.optionalString (cfg.domainsFile != null) ''
export DUCKDNS_DOMAINS=$(systemd-creds cat DUCKDNS_DOMAINS_FILE | sed -z 's/\n/,/g')
''}
curl --no-progress-meter -k "https://www.duckdns.org/update?domains=$DUCKDNS_DOMAINS&token=$DUCKDNS_TOKEN&ip=" | grep -v "KO"
'';
export DUCKDNS_TOKEN=$(systemd-creds cat DUCKDNS_TOKEN_FILE)
${
lib.optionalString (cfg.domains != null) ''
export DUCKDNS_DOMAINS='${lib.strings.concatStringsSep "," cfg.domains}'
''
}
${lib.optionalString (cfg.domainsFile != null) ''
export DUCKDNS_DOMAINS=$(systemd-creds cat DUCKDNS_DOMAINS_FILE | sed -z 's/\n/,/g')
''}
curl --no-progress-meter -k "https://www.duckdns.org/update?domains=$DUCKDNS_DOMAINS&token=$DUCKDNS_TOKEN&ip=" | grep -v "KO"
'';
};
};

Expand Down

0 comments on commit cae5068

Please sign in to comment.