2024-01-23 05:29:57 +01:00
|
|
|
{ config, pkgs, lib, ... }: let
|
2023-10-06 13:42:11 +02:00
|
|
|
cfg = config.services.vaultwarden;
|
|
|
|
in {
|
2023-07-12 01:45:05 +02:00
|
|
|
services.vaultwarden = {
|
|
|
|
enable = true;
|
|
|
|
dbBackend = "postgresql";
|
|
|
|
# TODO: Set a database password
|
|
|
|
environmentFile = pkgs.writeText "vaultwarden.env" ''
|
|
|
|
DATABASE_URL=postgresql://vaultwarden:@%2Fvar%2Frun%2Fpostgresql/vaultwarden
|
|
|
|
'';
|
|
|
|
config = {
|
|
|
|
DOMAIN = "https://bw.nani.wtf";
|
|
|
|
SIGNUPS_ALLOWED = false;
|
2024-01-23 05:30:14 +01:00
|
|
|
INVITATIONS_ALLOWED = false;
|
2023-07-12 01:45:05 +02:00
|
|
|
ROCKET_ADDRESS = "127.0.0.1";
|
|
|
|
ROCKET_PORT = 8222;
|
|
|
|
ROCKET_LOG = "critical";
|
|
|
|
ROCKET_WORKERS = 1;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-01-23 05:29:57 +01:00
|
|
|
systemd.services.vaultwarden = lib.mkIf cfg.enable {
|
2023-07-12 01:45:05 +02:00
|
|
|
requires = [ "postgresql.service" ];
|
2023-07-28 21:52:51 +02:00
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
# Extra hardening
|
|
|
|
CapabilityBoundingSet = "";
|
|
|
|
LockPersonality = true;
|
|
|
|
NoNewPrivileges = true;
|
|
|
|
# MemoryDenyWriteExecute = true;
|
|
|
|
PrivateMounts = true;
|
|
|
|
PrivateUsers = true;
|
|
|
|
ProcSubset = "pid";
|
|
|
|
ProtectClock = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
ProtectHostname = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
ProtectProc = "invisible";
|
|
|
|
RestrictAddressFamilies = [
|
|
|
|
"AF_INET"
|
|
|
|
"AF_INET6"
|
|
|
|
"AF_UNIX"
|
|
|
|
];
|
|
|
|
RemoveIPC = true;
|
|
|
|
RestrictNamespaces = true;
|
|
|
|
RestrictRealtime = true;
|
|
|
|
RestrictSUIDSGID = true;
|
|
|
|
SystemCallArchitectures = "native";
|
|
|
|
SystemCallFilter = [
|
|
|
|
"@system-service"
|
|
|
|
"~@privileged"
|
|
|
|
];
|
|
|
|
UMask = "0007";
|
|
|
|
};
|
2023-07-12 01:45:05 +02:00
|
|
|
};
|
|
|
|
|
2024-01-23 05:29:57 +01:00
|
|
|
services.postgresql = lib.mkIf cfg.enable {
|
2023-07-12 01:45:05 +02:00
|
|
|
enable = true;
|
|
|
|
ensureDatabases = [ "vaultwarden" ];
|
|
|
|
ensureUsers = [
|
|
|
|
(rec {
|
|
|
|
name = "vaultwarden";
|
|
|
|
ensurePermissions = {
|
|
|
|
"DATABASE \"${name}\"" = "ALL PRIVILEGES";
|
|
|
|
};
|
|
|
|
})
|
|
|
|
];
|
|
|
|
};
|
2023-10-06 13:42:11 +02:00
|
|
|
|
|
|
|
local.socketActivation.vaultwarden = {
|
|
|
|
enable = cfg.enable;
|
|
|
|
originalSocketAddress = "${cfg.config.ROCKET_ADDRESS}:${toString cfg.config.ROCKET_PORT}";
|
|
|
|
newSocketAddress = "/run/vaultwarden.sock";
|
|
|
|
privateNamespace = false;
|
|
|
|
};
|
2023-07-12 01:45:05 +02:00
|
|
|
}
|