summaryrefslogtreecommitdiffstats
path: root/nixos/modules/services/networking/ddns-updater.nix
blob: 641325118945e8e577ead9e1563035e5e684a6b5 (plain)
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
{
  config,
  lib,
  pkgs,
  ...
}:

let
  cfg = config.services.ddns-updater;
in
{
  options.services.ddns-updater = {
    enable = lib.mkEnableOption "Container to update DNS records periodically with WebUI for many DNS providers";

    package = lib.mkPackageOption pkgs "ddns-updater" { };

    environment = lib.mkOption {
      type = lib.types.attrsOf lib.types.str;
      description = "Environment variables to be set for the ddns-updater service. DATADIR is ignored to enable using systemd DynamicUser. For full list see <https://github.com/qdm12/ddns-updater>";
      default = { };
    };
  };

  config = lib.mkIf cfg.enable {

    systemd.services.ddns-updater = {
      wantedBy = [ "multi-user.target" ];
      wants = [ "network-online.target" ];
      after = [ "network-online.target" ];
      environment = cfg.environment // {
        DATADIR = "%S/ddns-updater";
      };
      unitConfig = {
        Description = "DDNS-updater service";
      };
      serviceConfig = {
        TimeoutSec = "5min";
        ExecStart = lib.getExe cfg.package;
        RestartSec = 30;
        DynamicUser = true;
        StateDirectory = "ddns-updater";
        Restart = "on-failure";
      };
    };
  };
}