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