nixos-config/patches/vaultwarden.patch

80 lines
3.3 KiB
Diff
Raw Normal View History

2023-04-08 22:47:50 +03:00
diff --git a/nixos/modules/services/security/vaultwarden/default.nix b/nixos/modules/services/security/vaultwarden/default.nix
2024-04-23 21:37:10 +03:00
index b2920931f..443b8421b 100644
2023-04-08 22:47:50 +03:00
--- a/nixos/modules/services/security/vaultwarden/default.nix
+++ b/nixos/modules/services/security/vaultwarden/default.nix
2024-04-23 21:37:10 +03:00
@@ -23,7 +23,7 @@ let
configEnv = lib.concatMapAttrs (name: value: lib.optionalAttrs (value != null) {
${nameToEnvVar name} = if lib.isBool value then lib.boolToString value else toString value;
2023-04-08 22:47:50 +03:00
}) cfg.config;
2024-04-23 21:37:10 +03:00
- in { DATA_FOLDER = "/var/lib/bitwarden_rs"; } // lib.optionalAttrs (!(configEnv ? WEB_VAULT_ENABLED) || configEnv.WEB_VAULT_ENABLED == "true") {
+ in { DATA_FOLDER = cfg.dataDir; } // lib.optionalAttrs (!(configEnv ? WEB_VAULT_ENABLED) || configEnv.WEB_VAULT_ENABLED == "true") {
2023-04-08 22:47:50 +03:00
WEB_VAULT_FOLDER = "${cfg.webVaultPackage}/share/vaultwarden/vault";
} // configEnv;
2023-04-25 17:20:58 +03:00
2024-04-23 21:37:10 +03:00
@@ -163,6 +163,16 @@ in {
defaultText = lib.literalExpression "pkgs.vaultwarden.webvault";
description = "Web vault package to use.";
2023-04-08 22:47:50 +03:00
};
2024-04-23 21:37:10 +03:00
+
+ dataDir = lib.mkOption {
+ type = lib.types.str;
2023-04-08 22:47:50 +03:00
+ default = "/var/lib/bitwarden_rs";
+ description = ''
+ The directury in which vaultwarden will keep its state. If left as the default value
+ this directory will automatically be created before the vaultwarden server starts, otherwise
+ the sysadmin is responsible for ensuring the directory exists with appropriate ownership and permissions.
+ '';
+ };
2024-04-23 21:37:10 +03:00
};
config = lib.mkIf cfg.enable {
@@ -180,28 +190,32 @@ in {
systemd.services.vaultwarden = {
2023-04-08 22:47:50 +03:00
after = [ "network.target" ];
path = with pkgs; [ openssl ];
- serviceConfig = {
- User = user;
- Group = group;
2024-04-23 21:37:10 +03:00
- EnvironmentFile = [ configFile ] ++ lib.optional (cfg.environmentFile != null) cfg.environmentFile;
2023-04-08 22:47:50 +03:00
- ExecStart = "${vaultwarden}/bin/vaultwarden";
- LimitNOFILE = "1048576";
- PrivateTmp = "true";
- PrivateDevices = "true";
- ProtectHome = "true";
- ProtectSystem = "strict";
- AmbientCapabilities = "CAP_NET_BIND_SERVICE";
- StateDirectory = "bitwarden_rs";
- StateDirectoryMode = "0700";
- Restart = "always";
- };
2024-04-23 21:37:10 +03:00
+ serviceConfig = lib.mkMerge [
+ (lib.mkIf (cfg.dataDir == "/var/lib/bitwarden_rs") {
2023-04-08 22:47:50 +03:00
+ StateDirectory = "bitwarden_rs";
+ StateDirectoryMode = "0700";
+ })
+ {
+ User = user;
+ Group = group;
2024-04-23 21:37:10 +03:00
+ EnvironmentFile = [ configFile ] ++ lib.optional (cfg.environmentFile != null) cfg.environmentFile;
2023-04-08 22:47:50 +03:00
+ ExecStart = "${vaultwarden}/bin/vaultwarden";
+ LimitNOFILE = "1048576";
+ PrivateTmp = "true";
+ PrivateDevices = "true";
+ ProtectHome = "true";
+ ProtectSystem = "strict";
+ AmbientCapabilities = "CAP_NET_BIND_SERVICE";
+ Restart = "always";
+ }
+ ];
wantedBy = [ "multi-user.target" ];
};
2023-04-25 17:20:58 +03:00
2024-04-23 21:37:10 +03:00
systemd.services.backup-vaultwarden = lib.mkIf (cfg.backupDir != null) {
2023-04-08 22:47:50 +03:00
description = "Backup vaultwarden";
environment = {
- DATA_FOLDER = "/var/lib/bitwarden_rs";
2023-04-25 17:20:58 +03:00
+ DATA_FOLDER = cfg.dataDir;
2023-04-08 22:47:50 +03:00
BACKUP_FOLDER = cfg.backupDir;
};
path = with pkgs; [ sqlite ];