forked from nix-community/nix-bundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nix-bundle.sh
executable file
·63 lines (46 loc) · 1.26 KB
/
nix-bundle.sh
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
#!/usr/bin/env sh
if [ "$#" -lt 2 ]; then
cat <<EOF
Usage: $0 TARGET EXECUTABLE
Create a single-file bundle from the nixpkgs attribute "TARGET".
EXECUTABLE should be relative to the TARGET's output path.
The TARGET is either an attribute in nixpkgs, or an absolute path to the
store.
For example:
$ $0 hello /bin/hello
$ ./hello
Hello, world!
EOF
exit 1
fi
nix_file=$(dirname "$0")/default.nix
target="$1"
shift
extraTargets=
if [ "$#" -gt 1 ]; then
while [ "$#" -gt 1 ]; do
extraTargets="$extraTargets $1"
shift
done
fi
exec="$1"
shift
bootstrap=nix-bootstrap
if [ "$target" = "nix-bundle" ] || [ "$target" = "nixStable" ] || [ "$target" = "nixUnstable" ] || [ "$target" = "nix" ]; then
bootstrap=nix-bootstrap-nix
elif [ -n "$extraTargets" ]; then
bootstrap=nix-bootstrap-path
fi
expr="with import <nixpkgs> {}; with import $nix_file {}; $bootstrap { target = $target; extraTargets = [ $extraTargets ]; run = \"$exec\"; }"
drv=$(nix-instantiate --no-gc-warning -E "$expr")
out=$(nix-store --no-gc-warning --realize "$drv")
if [ -z "$out" ]; then
>&2 echo "$0 failed. Exiting."
exit 1
elif [ -t 1 ]; then
filename=$(basename "$exec")
echo "Nix bundle created at $filename."
cp -f "$out" "$filename"
else
echo "$out"
fi