-
Notifications
You must be signed in to change notification settings - Fork 1
/
lib.nix
57 lines (53 loc) · 1.53 KB
/
lib.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> {}
, nix-bubblewrap ? import ./. { inherit pkgs; } }:
{
wrapProgram =
{ name # name of the program
, options ? [] # nix-bwrap cli options
, program # path to the binary to wrap
}:
# runCommand isn't enough because we need makeBinaryWrapper, which is a hook
pkgs.stdenvNoCC.mkDerivation {
name = "${name}-bwrapped";
dontUnpack = true;
dontPatch = true;
dontConfigure = true;
dontBuild = true;
nativeBuildInputs = [ pkgs.makeBinaryWrapper ];
installPhase = ''
runHook preInstall
mkdir -p $out/bin
makeBinaryWrapper \
${nix-bubblewrap}/bin/nix-bwrap \
$out/bin/$(basename ${program}) \
--add-flags "${toString options}" \
--add-flags ${program}
runHook postInstall
'';
};
wrapPackage =
{ options ? [] # nix-bwrap cli options
, package # package to wrap
, name ? package.name
}:
pkgs.stdenvNoCC.mkDerivation {
name = "${name}-bwrapped";
dontUnpack = true;
dontPatch = true;
dontConfigure = true;
dontBuild = true;
nativeBuildInputs = [ pkgs.makeBinaryWrapper ];
installPhase = ''
runHook preInstall
mkdir -p $out/bin
for bin in ${package}/bin/*; do
makeBinaryWrapper \
${nix-bubblewrap}/bin/nix-bwrap \
$out/bin/$(basename "$bin") \
--add-flags "${toString options}" \
--add-flags "$bin"
done
runHook postInstall
'';
};
}