nix-config/config/services/vaultwarden.nix

131 lines
3.7 KiB
Nix
Raw Normal View History

2024-01-12 17:16:37 +01:00
{
config,
lib,
nodes,
2024-01-12 17:16:37 +01:00
...
2024-07-26 22:12:48 +02:00
}:
let
2024-01-12 17:16:37 +01:00
vaultwardenDomain = "pw.${config.secrets.secrets.global.domains.web}";
2024-07-26 22:12:48 +02:00
in
{
2024-01-12 17:16:37 +01:00
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";
}
];
2024-01-15 02:13:46 +01:00
age.secrets.resticpasswd = {
generator.script = "alnum";
};
age.secrets.vaultwardenHetznerSsh = {
generator.script = "ssh-ed25519";
};
services.restic.backups = {
main = {
2024-01-20 21:07:00 +01:00
user = "root";
2024-01-15 02:13:46 +01:00
timerConfig = {
OnCalendar = "06:00";
Persistent = true;
RandomizedDelaySec = "3h";
};
initialize = true;
passwordFile = config.age.secrets.resticpasswd.path;
hetznerStorageBox = {
enable = true;
inherit (config.secrets.secrets.global.hetzner) mainUser;
inherit (config.secrets.secrets.global.hetzner.users.vaultwarden) subUid path;
sshAgeSecret = "vaultwardenHetznerSsh";
};
2024-07-26 22:12:48 +02:00
paths = [ config.services.vaultwarden.backupDir ];
2024-08-08 20:08:01 +02:00
#pruneOpts = [
# "--keep-daily 10"
# "--keep-weekly 7"
# "--keep-monthly 12"
# "--keep-yearly 75"
#];
2024-01-15 02:13:46 +01:00
};
};
age.secrets.maddyPasswd = {
generator.script = "alnum";
group = "vaultwarden";
};
nodes.maddy = {
age.secrets.vaultwardenPasswd = {
inherit (config.age.secrets.maddyPasswd) rekeyFile;
inherit (nodes.maddy.config.services.maddy) group;
mode = "640";
};
services.maddy.ensureCredentials = {
2024-07-26 22:12:48 +02:00
"vaultwarden@${config.secrets.secrets.global.domains.mail_public}".passwordFile =
nodes.maddy.config.age.secrets.vaultwardenPasswd.path;
};
};
system.activationScripts.systemd_env_smtp_passwd = {
text = ''
echo "SMTP_PASSWORD=$(< ${lib.escapeShellArg config.age.secrets.maddyPasswd.path})" > /run/vaultwarden_smtp_passwd
'';
2024-07-26 22:12:48 +02:00
deps = [ "agenix" ];
};
2024-07-26 22:12:48 +02:00
systemd.services.vaultwarden.serviceConfig.EnvironmentFile = [ "/run/vaultwarden_smtp_passwd" ];
2024-01-15 02:13:46 +01:00
2024-01-12 17:16:37 +01:00
services.vaultwarden = {
enable = true;
dbBackend = "sqlite";
2024-01-15 20:46:53 +01:00
backupDir = "/var/cache/backups/vaultwarden";
2024-01-12 17:16:37 +01:00
config = {
dataFolder = lib.mkForce "/var/lib/vaultwarden";
extendedLogging = true;
useSyslog = true;
webVaultEnabled = true;
rocketAddress = "0.0.0.0";
rocketPort = 3000;
signupsAllowed = false;
passwordIterations = 1000000;
invitationsAllowed = true;
invitationOrgName = "Vaultwarden";
domain = "https://${vaultwardenDomain}";
smtpHost = "smtp.${config.secrets.secrets.global.domains.mail_public}";
smtpFrom = "vaultwarden@${config.secrets.secrets.global.domains.mail_public}";
2024-01-12 17:16:37 +01:00
smtpPort = 465;
smtpSecurity = "force_tls";
smtpUsername = "vaultwarden@${config.secrets.secrets.global.domains.mail_public}";
smtpEmbedImages = true;
2024-01-12 17:16:37 +01:00
};
environmentFile = config.age.secrets.vaultwarden-env.path;
};
2024-03-14 23:08:42 +01:00
wireguard.elisabeth = {
client.via = "elisabeth";
2024-07-26 22:12:48 +02:00
firewallRuleForNode.elisabeth.allowedTCPPorts = [ config.services.vaultwarden.config.rocketPort ];
2024-03-14 23:08:42 +01:00
};
2024-01-13 19:23:51 +01:00
2024-01-12 17:16:37 +01:00
# 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 = "600"; # Retry every 10 minutes
};
2024-01-20 21:07:00 +01:00
environment.persistence."/state".directories = [
{
directory = config.services.vaultwarden.backupDir;
user = "vaultwarden";
group = "vaultwarden";
mode = "0770";
}
];
2024-01-12 17:16:37 +01:00
}