-
Notifications
You must be signed in to change notification settings - Fork 1
/
flake.nix
71 lines (64 loc) · 2.49 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Copyright 2024 Ross Light
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
{
description = "Helper for creating a Vault plugin directory";
outputs = { ... }: {
lib.mkPluginDirectory = { plugins, pkgs }:
let
inherit (builtins) map;
inherit (pkgs.lib.meta) getExe;
inherit (pkgs.lib.strings) concatLines escapeShellArg getName optionalString removePrefix;
registerScriptName = "register-vault-plugins";
commandPrefix = "vault-plugin-";
plugins' = map
({ binary
, type ? "secret"
, pname ? removePrefix commandPrefix (getName binary)
, version ? binary.version or ""
}:
let
command = commandPrefix + pname + (optionalString (version != "") "-${version}");
in
{
inherit type pname version command;
script = ''
makeWrapper ${escapeShellArg (getExe binary)} "$out/libexec/vault-plugins/${command}"
'';
}
) plugins;
scriptWriter = pkgs.buildGoModule {
name = "make_register_script";
src = ./make_register_script;
vendorHash = null;
meta.mainProgram = "make_register_script";
};
in
pkgs.runCommandLocal "vault-plugins" {
nativeBuildInputs = [ pkgs.makeBinaryWrapper ];
plugins = builtins.toJSON (map (p: builtins.removeAttrs p [ "script" ]) plugins');
passAsFile = [ "plugins" ];
inherit scriptWriter;
} (''
mkdir -p "$out/libexec/vault-plugins"
${concatLines (map (p: p.script) plugins')}
mkdir -p "$out/bin"
echo ${escapeShellArg ("#!" + pkgs.runtimeShell)} > "$out/bin/${registerScriptName}"
echo 'set -euo pipefail' >> "$out/bin/${registerScriptName}"
${getExe scriptWriter} >> "$out/bin/${registerScriptName}"
chmod +x "$out/bin/${registerScriptName}"
'');
};
}