2018-04-07 19:23:04 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.duplicati;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.duplicati = {
|
|
|
|
enable = mkEnableOption (lib.mdDoc "Duplicati");
|
2018-05-24 21:35:53 +00:00
|
|
|
|
2023-08-18 11:49:18 +00:00
|
|
|
package = mkPackageOptionMD pkgs "duplicati" { };
|
|
|
|
|
2018-05-24 21:35:53 +00:00
|
|
|
port = mkOption {
|
|
|
|
default = 8200;
|
2022-11-09 21:30:00 +00:00
|
|
|
type = types.port;
|
2018-05-24 21:35:53 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Port serving the web interface
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-12-24 22:04:39 +00:00
|
|
|
dataDir = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "/var/lib/duplicati";
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
The directory where Duplicati stores its data files.
|
|
|
|
|
|
|
|
::: {.note}
|
|
|
|
If left as the default value this directory will automatically be created
|
|
|
|
before the Duplicati server starts, otherwise you are responsible for ensuring
|
|
|
|
the directory exists with appropriate ownership and permissions.
|
2022-08-30 00:30:04 +00:00
|
|
|
:::
|
2021-12-24 22:04:39 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-05-24 21:35:53 +00:00
|
|
|
interface = mkOption {
|
2019-06-22 18:25:43 +00:00
|
|
|
default = "127.0.0.1";
|
2018-05-24 21:35:53 +00:00
|
|
|
type = types.str;
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
Listening interface for the web UI
|
|
|
|
Set it to "any" to listen on all available interfaces
|
|
|
|
'';
|
|
|
|
};
|
2019-06-25 12:28:03 +00:00
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
default = "duplicati";
|
|
|
|
type = types.str;
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
Duplicati runs as it's own user. It will only be able to backup world-readable files.
|
|
|
|
Run as root with special care.
|
|
|
|
'';
|
|
|
|
};
|
2018-04-07 19:23:04 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2023-08-18 11:49:18 +00:00
|
|
|
environment.systemPackages = [ cfg.package ];
|
2018-04-07 19:23:04 +00:00
|
|
|
|
|
|
|
systemd.services.duplicati = {
|
|
|
|
description = "Duplicati backup";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2021-12-24 22:04:39 +00:00
|
|
|
serviceConfig = mkMerge [
|
|
|
|
{
|
|
|
|
User = cfg.user;
|
|
|
|
Group = "duplicati";
|
2023-08-18 11:49:18 +00:00
|
|
|
ExecStart = "${cfg.package}/bin/duplicati-server --webservice-interface=${cfg.interface} --webservice-port=${toString cfg.port} --server-datafolder=${cfg.dataDir}";
|
2021-12-24 22:04:39 +00:00
|
|
|
Restart = "on-failure";
|
|
|
|
}
|
|
|
|
(mkIf (cfg.dataDir == "/var/lib/duplicati") {
|
|
|
|
StateDirectory = "duplicati";
|
|
|
|
})
|
|
|
|
];
|
2018-04-07 19:23:04 +00:00
|
|
|
};
|
|
|
|
|
2021-05-28 08:32:57 +00:00
|
|
|
users.users = lib.optionalAttrs (cfg.user == "duplicati") {
|
|
|
|
duplicati = {
|
|
|
|
uid = config.ids.uids.duplicati;
|
2021-12-24 22:04:39 +00:00
|
|
|
home = cfg.dataDir;
|
2021-05-28 08:32:57 +00:00
|
|
|
group = "duplicati";
|
|
|
|
};
|
2018-04-07 19:23:04 +00:00
|
|
|
};
|
2018-06-29 23:58:35 +00:00
|
|
|
users.groups.duplicati.gid = config.ids.gids.duplicati;
|
2018-04-07 19:23:04 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
}
|