2020-04-24 23:36:52 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.duplicati;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.duplicati = {
|
|
|
|
enable = mkEnableOption "Duplicati";
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
default = 8200;
|
|
|
|
type = types.int;
|
|
|
|
description = ''
|
|
|
|
Port serving the web interface
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-12-30 13:39:12 +00:00
|
|
|
dataDir = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "/var/lib/duplicati";
|
|
|
|
description = ''
|
|
|
|
The directory where Duplicati stores its data files.
|
|
|
|
|
|
|
|
<note><para>
|
|
|
|
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.
|
|
|
|
</para></note>
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
interface = mkOption {
|
|
|
|
default = "127.0.0.1";
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
Listening interface for the web UI
|
|
|
|
Set it to "any" to listen on all available interfaces
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
default = "duplicati";
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
Duplicati runs as it's own user. It will only be able to backup world-readable files.
|
|
|
|
Run as root with special care.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
environment.systemPackages = [ pkgs.duplicati ];
|
|
|
|
|
|
|
|
systemd.services.duplicati = {
|
|
|
|
description = "Duplicati backup";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2021-12-30 13:39:12 +00:00
|
|
|
serviceConfig = mkMerge [
|
|
|
|
{
|
|
|
|
User = cfg.user;
|
|
|
|
Group = "duplicati";
|
|
|
|
ExecStart = "${pkgs.duplicati}/bin/duplicati-server --webservice-interface=${cfg.interface} --webservice-port=${toString cfg.port} --server-datafolder=${cfg.dataDir}";
|
|
|
|
Restart = "on-failure";
|
|
|
|
}
|
|
|
|
(mkIf (cfg.dataDir == "/var/lib/duplicati") {
|
|
|
|
StateDirectory = "duplicati";
|
|
|
|
})
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2021-05-29 03:34:57 +00:00
|
|
|
users.users = lib.optionalAttrs (cfg.user == "duplicati") {
|
|
|
|
duplicati = {
|
|
|
|
uid = config.ids.uids.duplicati;
|
2021-12-30 13:39:12 +00:00
|
|
|
home = cfg.dataDir;
|
2021-05-29 03:34:57 +00:00
|
|
|
group = "duplicati";
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
users.groups.duplicati.gid = config.ids.gids.duplicati;
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|