nix-home/modules/cloud/bitwarden/default.nix

73 lines
1.7 KiB
Nix
Raw Normal View History

2021-11-01 01:41:29 +00:00
{ pkgs, lib, config, ... }:
with lib;
let
cfg = config.cloud.bitwarden;
databaseUser = "bitwarden";
databaseUrl = "postgres:///${user}?user=${user}";
user = "bitwarden";
port = 8001;
2021-11-01 18:41:55 +00:00
notificationsPort = 8002;
host = "bw.nkagami.me";
2021-11-01 01:41:29 +00:00
in
{
options.cloud.bitwarden = { };
config = {
# users
users.users."${user}" = {
group = "${user}";
isSystemUser = true;
};
users.groups."${user}" = { };
# database
cloud.postgresql.databases = [ databaseUser ];
# traefik
2021-11-01 18:41:55 +00:00
cloud.traefik.hosts.bitwarden = {
inherit port host;
2021-11-01 18:41:55 +00:00
};
cloud.traefik.hosts.bitwarden-notifications = {
inherit host;
2021-11-01 18:41:55 +00:00
port = notificationsPort;
path = "/notifications/hub";
2021-11-01 01:41:29 +00:00
};
# systemd unit
systemd.services.bitwarden-server = {
after = [ "network.target" ];
path = with pkgs; [ openssl ];
environment = {
DISABLE_ADMIN_TOKEN = "true";
SIGNUPS_ALLOWED = "false";
DATABASE_URL = databaseUrl;
DATA_FOLDER = "/var/lib/bitwarden-server";
WEB_VAULT_FOLDER = "${pkgs.unstable.vaultwarden-vault}/share/vaultwarden/vault";
ROCKET_PORT = toString port;
2021-11-01 19:03:23 +00:00
WEBSOCKET_ENABLED = "true";
2021-11-01 18:41:55 +00:00
WEBSOCKET_PORT = toString notificationsPort;
DOMAIN = "https://${host}";
2021-11-01 01:41:29 +00:00
};
serviceConfig = {
User = user;
Group = user;
ExecStart = "${pkgs.unstable.vaultwarden-postgresql}/bin/vaultwarden";
LimitNOFILE = "1048576";
PrivateTmp = "true";
PrivateDevices = "true";
ProtectHome = "true";
ProtectSystem = "strict";
AmbientCapabilities = "CAP_NET_BIND_SERVICE";
StateDirectory = "bitwarden-server";
};
wantedBy = [ "multi-user.target" ];
};
};
}