vault: add unitConfig.RequiresMountsFor to systemd config

Volth 519f1703 7330e804

Changed files
+18 -14
nixos
modules
services
security
pkgs
tools
security
vault
+17 -13
nixos/modules/services/security/vault.nix
···
};
};
-
config = mkIf cfg.enable {
+
config = let
+
localDir = if (cfg.storageBackend == "file" || cfg.storageBackend == "file_transactional") then
+
let
+
matched = builtins.match ''.*path[ ]*=[ ]*"([^"]+)".*'' (toString cfg.storageConfig);
+
in
+
if matched == null then
+
throw ''`storageBackend` "${cfg.storageBackend}" requires path in `storageConfig`''
+
else
+
head matched
+
else
+
null;
+
in mkIf cfg.enable {
users.extraUsers.vault = {
name = "vault";
···
after = [ "network.target" ]
++ optional (config.services.consul.enable && cfg.storageBackend == "consul") "consul.service";
-
preStart =
-
optionalString (cfg.storageBackend == "file" || cfg.storageBackend == "file_transactional")
-
(let
-
matched = builtins.match ''.*path[ ]*=[ ]*"([^"]+)".*'' (toString cfg.storageConfig);
-
path = if matched == null then
-
throw ''`storageBackend` "${cfg.storageBackend}" requires path in `storageConfig`''
-
else
-
head matched;
-
in ''
-
[ -d "${path}"] || install -d -m0700 -o vault -g vault "${path}"
-
'') +
-
''
+
preStart = optionalString (localDir != null) ''
+
install -d -m0700 -o vault -g vault "${localDir}"
+
'' + ''
# generate a self-signed certificate, you will have to set environment variable "VAULT_SKIP_VERIFY=1" in the client
if [ ! -s ${cfg.tlsCertFile} -o ! -s ${cfg.tlsKeyFile} ]; then
mkdir -p $(dirname ${cfg.tlsCertFile}) || true
···
StartLimitInterval = "60s";
StartLimitBurst = 3;
};
+
+
unitConfig.RequiresMountsFor = optional (localDir != null) localDir;
};
};
+1 -1
pkgs/tools/security/vault/default.nix
···
-
{ stdenv, lib, buildGoPackage, fetchFromGitHub }:
+
{ stdenv, buildGoPackage, fetchFromGitHub }:
let
vaultBashCompletions = fetchFromGitHub {