nixfiles/nixos/boxes/colony/vms/shill/containers/vaultwarden.nix

133 lines
3.7 KiB
Nix
Raw Normal View History

{ lib, ... }:
let
inherit (lib.my) net;
2023-11-02 13:41:50 +00:00
inherit (lib.my.c.colony) domain prefixes;
in
{
2022-03-26 14:20:30 +00:00
nixos.systems.vaultwarden = {
system = "x86_64-linux";
nixpkgs = "mine";
2022-03-26 14:20:30 +00:00
assignments = {
internal = {
name = "vaultwarden-ctr";
inherit domain;
ipv4.address = net.cidr.host 3 prefixes.ctrs.v4;
ipv6 = {
2022-05-31 21:25:51 +01:00
iid = "::3";
address = net.cidr.host 3 prefixes.ctrs.v6;
};
};
};
configuration = { lib, config, assignments, ... }:
2022-03-26 14:20:30 +00:00
let
inherit (lib) mkMerge mkIf mkForce;
inherit (lib.my) networkdAssignment;
2022-03-26 14:20:30 +00:00
vwData = "/var/lib/vaultwarden";
in
{
config = mkMerge [
{
my = {
deploy.enable = false;
2022-03-26 14:20:30 +00:00
server.enable = true;
secrets = {
key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFP2mF50ENpnJnr+VTnG9P+JFPjgwvoIxCLyJPzXRpVy";
2023-08-06 16:24:36 +01:00
files = {
"vaultwarden/config.env" = {};
"vaultwarden/backup-pass.txt" = {};
"vaultwarden/backup-ssh.key" = {};
};
2022-03-26 14:20:30 +00:00
};
firewall = {
tcp.allowed = with config.services.vaultwarden.config; [ ROCKET_PORT WEBSOCKET_PORT ];
2022-03-26 14:20:30 +00:00
};
tmproot.persistence.config.directories = [
{
directory = vwData;
user = config.users.users.vaultwarden.name;
group = config.users.groups.vaultwarden.name;
}
];
};
systemd = {
services.vaultwarden.serviceConfig.StateDirectory = mkForce "vaultwarden";
network.networks."80-container-host0" = networkdAssignment "host0" assignments.internal;
2022-03-26 14:20:30 +00:00
};
2023-08-06 16:24:36 +01:00
programs.ssh.knownHostsFiles = [
2023-11-02 13:41:50 +00:00
lib.my.c.sshKeyFiles.rsyncNet
2023-08-06 16:24:36 +01:00
];
2022-03-26 14:20:30 +00:00
services = {
vaultwarden = {
enable = true;
config = {
DATA_FOLDER = vwData;
2022-03-26 14:20:30 +00:00
WEB_VAULT_ENABLED = true;
WEBSOCKET_ENABLED = true;
WEBSOCKET_ADDRESS = "::";
WEBSOCKET_PORT = 3012;
SIGNUPS_ALLOWED = false;
2023-11-02 13:41:50 +00:00
DOMAIN = "https://pass.${lib.my.c.pubDomain}";
ROCKET_ADDRESS = "::";
ROCKET_PORT = 80;
SMTP_HOST = "mail.nul.ie";
SMTP_FROM = "pass@nul.ie";
SMTP_FROM_NAME = "Vaultwarden";
SMTP_SECURITY = "starttls";
SMTP_PORT = 587;
SMTP_USERNAME = "pass@nul.ie";
SMTP_TIMEOUT = 15;
2023-08-06 15:09:57 +01:00
PUSH_ENABLED = true;
2022-03-26 14:20:30 +00:00
};
2023-08-06 16:24:36 +01:00
environmentFile = config.age.secrets."vaultwarden/config.env".path;
};
borgbackup.jobs.vaultwarden = {
paths = [ vwData ];
repo = "zh2855@zh2855.rsync.net:borg/vaultwarden2";
doInit = true;
environment = {
BORG_REMOTE_PATH = "borg1";
BORG_RSH = ''ssh -i ${config.age.secrets."vaultwarden/backup-ssh.key".path}'';
};
compression = "zstd,10";
encryption = {
mode = "repokey";
passCommand = ''cat ${config.age.secrets."vaultwarden/backup-pass.txt".path}'';
};
prune.keep = {
within = "1d";
daily = 7;
weekly = 4;
monthly = -1;
};
2022-03-26 14:20:30 +00:00
};
};
}
(mkIf config.my.build.isDevVM {
virtualisation = {
forwardPorts = [
{ from = "host"; host.port = 8080; guest.port = 80; }
];
};
})
];
};
};
}