git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #39943 from bachp/restic-rest-server

restic-rest-server module: init

commitb051cdfd10b38b28ec2dbcd91c4231b87de8e7cd authorRobert Schütz <rschuetz17@gmail.com> dateFri 4 May 2018, 21:25 (9 years ago) parent91b09297f53ee8
3 files changed+110
nixos/modules/misc/ids.nix+2 nixos/modules/module-list.nix+1 nixos/modules/services/backup/restic-rest-server.nix+107
nixos/modules/misc/ids.nix+2
@@ -306,6 +306,7 @@
306306 ceph = 288;
307307 duplicati = 289;
308308 monetdb = 290;
309+ restic = 291;
309310
310311 # When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399!
311312
@@ -580,6 +581,7 @@
580581 ceph = 288;
581582 duplicati = 289;
582583 monetdb = 290;
584+ restic = 291;
583585
584586 # When adding a gid, make sure it doesn't match an existing
585587 # uid. Users and groups with the same name should have equal
nixos/modules/module-list.nix+1
@@ -167,6 +167,7 @@
167167 ./services/backup/mysql-backup.nix
168168 ./services/backup/postgresql-backup.nix
169169 ./services/backup/restic.nix
170+ ./services/backup/restic-rest-server.nix
170171 ./services/backup/rsnapshot.nix
171172 ./services/backup/tarsnap.nix
172173 ./services/backup/znapzend.nix
nixos/modules/services/backup/restic-rest-server.nixnew file+107
@@ -0,0 +1,107 @@
1+{ config, lib, pkgs, ... }:
2+
3+with lib;
4+
5+let
6+ cfg = config.services.restic.server;
7+in
8+{
9+ meta.maintainers = [ maintainers.bachp ];
10+
11+ options.services.restic.server = {
12+ enable = mkEnableOption "Restic REST Server";
13+
14+ listenAddress = mkOption {
15+ default = ":8000";
16+ example = "127.0.0.1:8080";
17+ type = types.str;
18+ description = "Listen on a specific IP address and port.";
19+ };
20+
21+ dataDir = mkOption {
22+ default = "/var/lib/restic";
23+ type = types.path;
24+ description = "The directory for storing the restic repository.";
25+ };
26+
27+ appendOnly = mkOption {
28+ default = false;
29+ type = types.bool;
30+ description = ''
31+ Enable append only mode.
32+ This mode allows creation of new backups but prevents deletion and modification of existing backups.
33+ This can be useful when backing up systems that have a potential of being hacked.
34+ '';
35+ };
36+
37+ privateRepos = mkOption {
38+ default = false;
39+ type = types.bool;
40+ description = ''
41+ Enable private repos.
42+ Grants access only when a subdirectory with the same name as the user is specified in the repository URL.
43+ '';
44+ };
45+
46+ prometheus = mkOption {
47+ default = false;
48+ type = types.bool;
49+ description = "Enable Prometheus metrics at /metrics.";
50+ };
51+
52+ extraFlags = mkOption {
53+ type = types.listOf types.str;
54+ default = [];
55+ description = ''
56+ Extra commandline options to pass to Restic REST server.
57+ '';
58+ };
59+
60+ package = mkOption {
61+ default = pkgs.restic-rest-server;
62+ defaultText = "pkgs.restic-rest-server";
63+ type = types.package;
64+ description = "Restic REST server package to use.";
65+ };
66+ };
67+
68+ config = mkIf cfg.enable {
69+ systemd.services.restic-rest-server = {
70+ description = "Restic REST Server";
71+ after = [ "network.target" ];
72+ wantedBy = [ "multi-user.target" ];
73+ serviceConfig = {
74+ ExecStart = ''
75+ ${cfg.package}/bin/rest-server \
76+ --listen ${cfg.listenAddress} \
77+ --path ${cfg.dataDir} \
78+ ${optionalString cfg.appendOnly "--append-only"} \
79+ ${optionalString cfg.privateRepos "--private-repos"} \
80+ ${optionalString cfg.prometheus "--prometheus"} \
81+ ${escapeShellArgs cfg.extraFlags} \
82+ '';
83+ Type = "simple";
84+ User = "restic";
85+ Group = "restic";
86+
87+ # Security hardening
88+ ReadWritePaths = [ cfg.dataDir ];
89+ PrivateTmp = true;
90+ ProtectSystem = "strict";
91+ ProtectKernelTunables = true;
92+ ProtectKernelModules = true;
93+ ProtectControlGroups = true;
94+ PrivateDevices = true;
95+ };
96+ };
97+
98+ users.extraUsers.restic = {
99+ group = "restic";
100+ home = cfg.dataDir;
101+ createHome = true;
102+ uid = config.ids.uids.restic;
103+ };
104+
105+ users.extraGroups.restic.gid = config.ids.uids.restic;
106+ };
107+}