-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.nix
57 lines (56 loc) · 1.63 KB
/
default.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
{ pkgs ? import <nixpkgs> {} }:
let
inherit (pkgs)
runCommand
lib
;
in
{
lazyEnv =
{ name ? "lazy-env"
, exes
, assumeDrvCache ? false
}:
runCommand name {
passthru = { inherit exes; };
} ''
mkdir -p $out/bin
${
lib.concatMapStringsSep
"\n"
({ name, value }:
let
drvPath = refDrv value.drvPath;
bin = lib.getBin value;
binPath = builtins.unsafeDiscardStringContext bin.outPath;
exePath = "${binPath}/bin/${name}";
refDrv =
if assumeDrvCache
then builtins.unsafeDiscardStringContext
else builtins.unsafeDiscardOutputDependency;
in ''
cat >$out/bin/${name} <<"EOF"
#!/usr/bin/env bash
set -euo pipefail
if [[ -e ${lib.escapeShellArg binPath} ]]; then
exec ${lib.escapeShellArg exePath} "$@"
fi
nix-store -r ${drvPath}!${bin.outputName} >/dev/null
cat 1>&2 <<"EOM"
to prevent gc-ing the result, make sure to use
keep-outputs = true
which can be set in nix.conf or nix.extraOptions (NixOS, nix-darwin)
path ${binPath} now available; execing
EOM
exec ${lib.escapeShellArg exePath} "$@"
EOF
chmod a+x $out/bin/${name}
''
)
(lib.mapAttrsToList
lib.nameValuePair
exes
)
}
'';
}