-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvaultwarden.nix
118 lines (107 loc) · 3.17 KB
/
vaultwarden.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
{
config,
globals,
lib,
...
}:
let
vaultwardenDomain = "pw.${globals.domains.personal}";
in
{
wireguard.proxy-sentinel = {
client.via = "sentinel";
firewallRuleForNode.sentinel.allowedTCPPorts = [ config.services.vaultwarden.config.rocketPort ];
};
age.secrets.vaultwarden-env = {
rekeyFile = config.node.secretsDir + "/vaultwarden-env.age";
mode = "440";
group = "vaultwarden";
};
environment.persistence."/persist".directories = [
{
directory = "/var/lib/vaultwarden";
user = "vaultwarden";
group = "vaultwarden";
mode = "0700";
}
];
globals.services.vaultwarden.domain = vaultwardenDomain;
globals.monitoring.http.vaultwarden = {
url = "https://${vaultwardenDomain}";
expectedBodyRegex = "Vaultwarden Web";
network = "internet";
};
nodes.sentinel = {
services.nginx = {
upstreams.vaultwarden = {
servers."${config.wireguard.proxy-sentinel.ipv4}:${toString config.services.vaultwarden.config.rocketPort}" =
{ };
extraConfig = ''
zone vaultwarden 64k;
keepalive 2;
'';
monitoring = {
enable = true;
expectedBodyRegex = "Vaultwarden Web";
};
};
virtualHosts.${vaultwardenDomain} = {
forceSSL = true;
useACMEWildcardHost = true;
extraConfig = ''
client_max_body_size 256M;
'';
locations."/" = {
proxyPass = "http://vaultwarden";
proxyWebsockets = true;
X-Frame-Options = "SAMEORIGIN";
};
};
};
};
services.vaultwarden = {
enable = true;
dbBackend = "sqlite";
# WARN: Careful! The backup script does not remove files in the backup location
# if they were removed in the original location! Therefore, we use a directory
# that is not persisted and thus clean on every reboot.
backupDir = "/var/cache/vaultwarden-backup";
config = {
dataFolder = lib.mkForce "/var/lib/vaultwarden";
extendedLogging = true;
useSyslog = true;
webVaultEnabled = true;
rocketAddress = "0.0.0.0";
rocketPort = 8012;
signupsAllowed = false;
passwordIterations = 1000000;
invitationsAllowed = true;
invitationOrgName = "Vaultwarden";
domain = "https://${vaultwardenDomain}";
smtpEmbedImages = true;
smtpSecurity = "force_tls";
smtpPort = 465;
};
environmentFile = config.age.secrets.vaultwarden-env.path;
};
# Replace uses of old name
systemd.services.backup-vaultwarden.environment.DATA_FOLDER = lib.mkForce "/var/lib/vaultwarden";
systemd.services.vaultwarden.serviceConfig = {
StateDirectory = lib.mkForce "vaultwarden";
RestartSec = "60"; # Retry every minute
};
# Needed so we don't run out of tmpfs space for large backups.
# Technically this could be cleared each boot but whatever.
environment.persistence."/state".directories = [
{
directory = config.services.vaultwarden.backupDir;
user = "vaultwarden";
group = "vaultwarden";
mode = "0700";
}
];
backups.storageBoxes.dusk = {
subuser = "vaultwarden";
paths = [ config.services.vaultwarden.backupDir ];
};
}