-
Notifications
You must be signed in to change notification settings - Fork 1
/
default.nix
86 lines (78 loc) · 2.09 KB
/
default.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
{ config, pkgs, lib, ...}: let
cfg = config.alexghr.b2-backup;
in with lib; {
options.alexghr.b2-backup = {
enable = mkEnableOption "backup configuration";
bucket = mkOption {
type = types.str;
description = "Bucket to backup to";
example = "some-bucket";
};
bucketPath = mkOption {
type = types.nullOr types.str;
description = "Where to store the backup on the bucket";
example = "/some-directory";
default = "/${config.networking.hostName}";
};
passwordFile = mkOption {
type = types.nullOr types.str;
description = "Where to find the password";
default = "/var/restic/password.txt";
};
environmentFile = mkOption {
type = types.nullOr types.str;
default = "/var/restic/b2.env";
description = "Credentials to connect to the bucket";
};
paths = mkOption {
type = types.nullOr (types.listOf types.str);
default = ["/"];
description = "Which paths to backup. Defaults to `/`";
example = ["/"];
};
exclude = mkOption {
type = types.nullOr (types.listOf types.str);
default = [
"/var/log"
"/var/run"
"/var/cache"
"/var/tmp"
"/nix"
"/opt"
"/usr"
"/bin"
"/sbin"
"/run"
"/proc"
"/dev"
"/boot"
"/sys"
"/tmp"
"**/cache"
"**/.cache"
"**/node_modules"
];
description = "Which paths avoid backing up";
example = ["**/.cache"];
};
when = mkOption {
type = types.nullOr types.str;
description = "When to run the backup command";
default = "00:01";
example = "00:05";
};
};
config = mkIf cfg.enable {
services.restic.backups.b2 = {
passwordFile = cfg.passwordFile;
environmentFile = cfg.environmentFile;
repository = "b2:${cfg.bucket}:${cfg.bucketPath}";
paths = cfg.paths;
extraBackupArgs = builtins.map (x: "--exclude ${x}") cfg.exclude;
initialize = true;
timerConfig = {
OnCalendar = cfg.when;
};
};
};
}