dotfiles/modules/nixos/homelab/guests/vaultwarden/config/default.nix

169 lines
4.9 KiB
Nix
Raw Normal View History

2025-12-07 01:38:13 -06:00
{
flake,
...
}:
let
inherit (flake.config.people) user0;
2025-12-08 03:32:04 -06:00
inherit (flake.config.services) instances;
serviceCfg = instances.vaultwarden;
smtpCfg = instances.smtp;
2025-12-07 01:38:13 -06:00
in
{
2025-12-08 03:32:04 -06:00
vaultwardenVM =
2025-12-07 01:38:13 -06:00
{
user,
ip,
mac,
userMac,
ssh,
2025-12-08 03:32:04 -06:00
host,
mnt,
2025-12-10 18:17:32 -06:00
inter,
2025-12-07 01:38:13 -06:00
}:
{
microvm.vms = {
"${serviceCfg.name}-${user}" = {
autostart = true;
restartIfChanged = true;
config = {
system.stateVersion = "24.05";
time.timeZone = "America/Winnipeg";
users.users.root.openssh.authorizedKeys.keys = flake.config.people.users.${user0}.sshKeys;
services = {
2025-12-08 03:32:04 -06:00
vaultwarden = {
2025-12-07 01:38:13 -06:00
enable = true;
2025-12-08 03:32:04 -06:00
dbBackend = "sqlite";
config = {
# Domain Configuration
DOMAIN = "https://${host}";
# Email Configuration
SMTP_AUTH_MECHANISM = "Plain";
SMTP_EMBED_IMAGES = true;
2025-12-08 22:25:13 -06:00
SMTP_FROM = smtpCfg.interfaces.interface0.email;
2025-12-08 03:32:04 -06:00
SMTP_FROM_NAME = serviceCfg.label;
2025-12-08 22:25:13 -06:00
SMTP_HOST = smtpCfg.interfaces.interface0.domain;
2025-12-08 03:32:04 -06:00
SMTP_PORT = smtpCfg.ports.port0;
2025-12-08 22:25:13 -06:00
SMTP_USERNAME = smtpCfg.interfaces.interface0.email;
2025-12-08 03:32:04 -06:00
SMTP_SECURITY = "starttls";
# Security Configuration
DISABLE_ADMIN_TOKEN = false;
# Event and Backup Management
EVENTS_DAYS_RETAIN = 90;
# User Features
SENDS_ALLOWED = true;
SIGNUPS_VERIFY = true;
WEB_VAULT_ENABLED = true;
# Rocket (Web Server) Settings
ROCKET_ADDRESS = "0.0.0.0";
2025-12-10 18:31:24 -06:00
ROCKET_PORT = serviceCfg.ports.port0;
ENABLE_WEBSOCKET = true;
2025-12-07 01:38:13 -06:00
};
2025-12-08 03:32:04 -06:00
# Environment file with secrets (mounted from host)
environmentFile = "/run/secrets/${user}-env";
2025-12-07 01:38:13 -06:00
};
2025-12-08 03:32:04 -06:00
2025-12-07 01:38:13 -06:00
openssh = {
enable = true;
settings = {
PasswordAuthentication = false;
PermitRootLogin = "prohibit-password";
};
};
};
networking.firewall.allowedTCPPorts = [
22
2025-12-08 03:32:04 -06:00
587
serviceCfg.ports.port0
2025-12-07 01:38:13 -06:00
];
systemd = {
services = {
2025-12-08 03:32:04 -06:00
systemd-networkd.wantedBy = [ "multi-user.target" ];
2025-12-07 01:38:13 -06:00
};
network = {
enable = true;
networks."20-lan" = {
2025-12-10 18:17:32 -06:00
matchConfig.Name = inter;
2025-12-07 01:38:13 -06:00
addresses = [
{ Address = "${ip}/24"; }
];
routes = [
{
Destination = "0.0.0.0/0";
Gateway = "192.168.50.1";
}
];
dns = [
"1.1.1.1"
"8.8.8.8"
];
};
};
2025-12-08 03:32:04 -06:00
tmpfiles.rules = [
"d /var/lib/${serviceCfg.name} 0755 ${serviceCfg.name} ${serviceCfg.name} -"
];
2025-12-07 01:38:13 -06:00
};
microvm = {
vcpu = 1;
2025-12-08 03:32:04 -06:00
mem = 1024;
2025-12-07 01:38:13 -06:00
hypervisor = "qemu";
interfaces = [
{
type = "tap";
2025-12-08 03:32:04 -06:00
id = "vm-vw-${user}";
2025-12-07 01:38:13 -06:00
mac = mac;
}
{
type = "user";
2025-12-08 03:32:04 -06:00
id = "vmuser-vault";
2025-12-07 01:38:13 -06:00
mac = userMac;
}
];
forwardPorts = [
{
from = "host";
host.port = ssh;
guest.port = 22;
}
];
shares = [
{
mountPoint = "/nix/.ro-store";
proto = "virtiofs";
source = "/nix/store";
tag = "read_only_nix_store";
}
{
2025-12-08 03:32:04 -06:00
mountPoint = "/var/lib/bitwarden_rs";
2025-12-07 01:38:13 -06:00
proto = "virtiofs";
2025-12-08 03:32:04 -06:00
source = "${mnt}/${serviceCfg.name}";
2025-12-07 01:38:13 -06:00
tag = "${serviceCfg.name}_${user}_data";
}
{
mountPoint = "/run/secrets";
proto = "virtiofs";
source = "/run/secrets/${serviceCfg.name}";
tag = "host_secrets";
}
];
};
};
};
};
systemd.tmpfiles.rules = [
2025-12-08 03:32:04 -06:00
"d ${mnt}/${serviceCfg.name} 0751 microvm wheel - -"
2025-12-07 01:38:13 -06:00
];
sops.secrets = {
2025-12-08 03:32:04 -06:00
"${serviceCfg.name}/${user}-env" = {
2025-12-07 01:38:13 -06:00
owner = "root";
mode = "0600";
};
};
};
}