1{ config, pkgs, lib, ... }:
2
3with lib;
4
5let
6 cfg = config.services.duplicati;
7in
8{
9 options = {
10 services.duplicati = {
11 enable = mkEnableOption (lib.mdDoc "Duplicati");
12
13 port = mkOption {
14 default = 8200;
15 type = types.port;
16 description = lib.mdDoc ''
17 Port serving the web interface
18 '';
19 };
20
21 dataDir = mkOption {
22 type = types.str;
23 default = "/var/lib/duplicati";
24 description = lib.mdDoc ''
25 The directory where Duplicati stores its data files.
26
27 ::: {.note}
28 If left as the default value this directory will automatically be created
29 before the Duplicati server starts, otherwise you are responsible for ensuring
30 the directory exists with appropriate ownership and permissions.
31 :::
32 '';
33 };
34
35 interface = mkOption {
36 default = "127.0.0.1";
37 type = types.str;
38 description = lib.mdDoc ''
39 Listening interface for the web UI
40 Set it to "any" to listen on all available interfaces
41 '';
42 };
43
44 user = mkOption {
45 default = "duplicati";
46 type = types.str;
47 description = lib.mdDoc ''
48 Duplicati runs as it's own user. It will only be able to backup world-readable files.
49 Run as root with special care.
50 '';
51 };
52 };
53 };
54
55 config = mkIf cfg.enable {
56 environment.systemPackages = [ pkgs.duplicati ];
57
58 systemd.services.duplicati = {
59 description = "Duplicati backup";
60 after = [ "network.target" ];
61 wantedBy = [ "multi-user.target" ];
62 serviceConfig = mkMerge [
63 {
64 User = cfg.user;
65 Group = "duplicati";
66 ExecStart = "${pkgs.duplicati}/bin/duplicati-server --webservice-interface=${cfg.interface} --webservice-port=${toString cfg.port} --server-datafolder=${cfg.dataDir}";
67 Restart = "on-failure";
68 }
69 (mkIf (cfg.dataDir == "/var/lib/duplicati") {
70 StateDirectory = "duplicati";
71 })
72 ];
73 };
74
75 users.users = lib.optionalAttrs (cfg.user == "duplicati") {
76 duplicati = {
77 uid = config.ids.uids.duplicati;
78 home = cfg.dataDir;
79 group = "duplicati";
80 };
81 };
82 users.groups.duplicati.gid = config.ids.gids.duplicati;
83
84 };
85}
86