Files

73 lines
1.8 KiB
Nix

{ config
, pkgs
, lib
, ...
}:
{
options.services.backrest = {
enable = lib.mkEnableOption "Backrest web UI for restic backup";
port = lib.mkOption {
type = lib.types.port;
default = 9898;
description = "Port for the Backrest web UI";
};
host = lib.mkOption {
type = lib.types.str;
default = "127.0.0.1";
description = "Address to bind Backrest to";
};
dataDir = lib.mkOption {
type = lib.types.path;
default = "/var/lib/backrest";
description = "Directory for Backrest config and data";
};
openFirewall = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Open the firewall for the Backrest web UI";
};
};
config = lib.mkIf config.services.backrest.enable {
systemd.tmpfiles.rules = [
"d ${config.services.backrest.dataDir} 0700 backrest backrest -"
];
users.users.backrest = {
isSystemUser = true;
group = "backrest";
home = config.services.backrest.dataDir;
createHome = true;
};
users.groups.backrest = { };
systemd.services.backrest = {
description = "Backrest web UI for restic backup";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig = {
Type = "simple";
User = "backrest";
Group = "backrest";
ExecStart = ''
${pkgs.backrest}/bin/backrest \
-bind-address ${config.services.backrest.host}:${toString config.services.backrest.port} \
-data-dir ${config.services.backrest.dataDir} \
-restic-cmd ${pkgs.restic}/bin/restic
'';
Restart = "on-failure";
};
};
networking.firewall.allowedTCPPorts = lib.mkIf config.services.backrest.openFirewall [
config.services.backrest.port
];
};
}