2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.restic.server;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
meta.maintainers = [ maintainers.bachp ];
|
|
|
|
|
|
|
|
options.services.restic.server = {
|
|
|
|
enable = mkEnableOption "Restic REST Server";
|
|
|
|
|
|
|
|
listenAddress = mkOption {
|
|
|
|
default = ":8000";
|
|
|
|
example = "127.0.0.1:8080";
|
|
|
|
type = types.str;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Listen on a specific IP address and port.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
dataDir = mkOption {
|
|
|
|
default = "/var/lib/restic";
|
|
|
|
type = types.path;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "The directory for storing the restic repository.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
appendOnly = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Enable append only mode.
|
|
|
|
This mode allows creation of new backups but prevents deletion and modification of existing backups.
|
|
|
|
This can be useful when backing up systems that have a potential of being hacked.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
privateRepos = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Enable private repos.
|
|
|
|
Grants access only when a subdirectory with the same name as the user is specified in the repository URL.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
prometheus = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Enable Prometheus metrics at /metrics.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extraFlags = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Extra commandline options to pass to Restic REST server.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
default = pkgs.restic-rest-server;
|
2021-10-06 13:57:05 +00:00
|
|
|
defaultText = literalExpression "pkgs.restic-rest-server";
|
2020-04-24 23:36:52 +00:00
|
|
|
type = types.package;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Restic REST server package to use.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.restic-rest-server = {
|
|
|
|
description = "Restic REST Server";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = ''
|
|
|
|
${cfg.package}/bin/rest-server \
|
|
|
|
--listen ${cfg.listenAddress} \
|
|
|
|
--path ${cfg.dataDir} \
|
|
|
|
${optionalString cfg.appendOnly "--append-only"} \
|
|
|
|
${optionalString cfg.privateRepos "--private-repos"} \
|
|
|
|
${optionalString cfg.prometheus "--prometheus"} \
|
|
|
|
${escapeShellArgs cfg.extraFlags} \
|
|
|
|
'';
|
|
|
|
Type = "simple";
|
|
|
|
User = "restic";
|
|
|
|
Group = "restic";
|
|
|
|
|
|
|
|
# Security hardening
|
|
|
|
ReadWritePaths = [ cfg.dataDir ];
|
|
|
|
PrivateTmp = true;
|
|
|
|
ProtectSystem = "strict";
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
PrivateDevices = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-01-03 16:56:52 +00:00
|
|
|
systemd.tmpfiles.rules = mkIf cfg.privateRepos [
|
|
|
|
"f ${cfg.dataDir}/.htpasswd 0700 restic restic -"
|
|
|
|
];
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
users.users.restic = {
|
|
|
|
group = "restic";
|
|
|
|
home = cfg.dataDir;
|
|
|
|
createHome = true;
|
|
|
|
uid = config.ids.uids.restic;
|
|
|
|
};
|
|
|
|
|
|
|
|
users.groups.restic.gid = config.ids.uids.restic;
|
|
|
|
};
|
|
|
|
}
|