on master help sign in
appdir.nix+2−2
since splitsnapshots
unifiedsplit
@@ -1,4 +1,4 @@
1−{ stdenv, fetchurl, muslPkgs, perl, pathsFromGraph, fetchFromGitHub, coreutils, bash }:
1+{ stdenv, lib, fetchurl, muslPkgs, perl, pathsFromGraph, fetchFromGitHub, coreutils, bash }:
2
2
3let
3let
4 AppRun = targets: muslPkgs.stdenv.mkDerivation {
4 AppRun = targets: muslPkgs.stdenv.mkDerivation {
@@ -8,7 +8,7 @@ let
8
8
9 buildPhase = ''
9 buildPhase = ''
10 CC="$CC -O2 -Wall -Wno-deprecated-declarations -Wno-unused-result -static"
10 CC="$CC -O2 -Wall -Wno-deprecated-declarations -Wno-unused-result -static"
11− $CC ${./AppRun.c} -o AppRun -DENV_PATH='"${stdenv.lib.makeBinPath targets}"'
11+ $CC ${./AppRun.c} -o AppRun -DENV_PATH='"${lib.makeBinPath targets}"'
12 '';
12 '';
13
13
14 installPhase = ''
14 installPhase = ''
appimagetool.nix+2−2
@@ -1,4 +1,4 @@
1−{ stdenv, fetchurl, fuse, zlib, squashfsTools, glib }:
1+{ stdenv, lib, fetchurl, fuse, zlib, squashfsTools, glib }:
2
2
3# This is from some binaries.
3# This is from some binaries.
4
4
@@ -37,7 +37,7 @@ in stdenv.mkDerivation rec {
37 for x in $out/bin/*; do
37 for x in $out/bin/*; do
38 patchelf \
38 patchelf \
39 --set-interpreter ${dynamicLinker} \
39 --set-interpreter ${dynamicLinker} \
40− --set-rpath ${stdenv.lib.makeLibraryPath [ zlib stdenv.glibc.out fuse glib ]} \
40+ --set-rpath ${lib.makeLibraryPath [ zlib stdenv.glibc.out fuse glib ]} \
41 $x
41 $x
42 done
42 done
43 '';
43 '';
default.nix+23−8
@@ -10,6 +10,16 @@ let
10 '';
10 '';
11 });
11 });
12in rec {
12in rec {
13+ toStorePath = target:
14+ # If a store path has been given but is not a derivation, add the missing context
15+ # to it so it will be propagated properly as a build input.
16+ if !(lib.isDerivation target) && lib.isStorePath target then
17+ let path = toString target; in
18+ builtins.appendContext path { "${path}" = { path = true; }; }
19+ # Otherwise, add to the store. This takes care of appending the store path
20+ # in the context automatically.
21+ else "${target}";
22+
13 arx = { archive, startup}:
23 arx = { archive, startup}:
14 stdenv.mkDerivation {
24 stdenv.mkDerivation {
15 name = "arx";
25 name = "arx";
@@ -35,7 +45,7 @@ in rec {
35 };
45 };
36
46
37 # TODO: eventually should this go in nixpkgs?
47 # TODO: eventually should this go in nixpkgs?
38− nix-user-chroot = stdenv.lib.makeOverridable stdenv.mkDerivation {
48+ nix-user-chroot = lib.makeOverridable stdenv.mkDerivation {
39 name = "nix-user-chroot-2c52b5f";
49 name = "nix-user-chroot-2c52b5f";
40 src = ./nix-user-chroot;
50 src = ./nix-user-chroot;
41
51
@@ -70,15 +80,20 @@ in rec {
70 };
80 };
71 };
81 };
72
82
73− makeStartup = { target, nixUserChrootFlags, nix-user-chroot', run }:
83+ makeStartup = { target, nixUserChrootFlags, nix-user-chroot', run, initScript }:
84+ let
85+ # Avoid re-adding a store path into the store
86+ path = toStorePath target;
87+ in
74 writeScript "startup" ''
88 writeScript "startup" ''
75 #!/bin/sh
89 #!/bin/sh
90+ ${initScript}
76− .${nix-user-chroot'}/bin/nix-user-chroot -n ./nix ${nixUserChrootFlags} -- ${target}${run} $@
91+ .${nix-user-chroot'}/bin/nix-user-chroot -n ./nix ${nixUserChrootFlags} -- ${path}${run} "$@"
77 '';
92 '';
78
93
79− nix-bootstrap = { target, extraTargets ? [], run, nix-user-chroot' ? nix-user-chroot, nixUserChrootFlags ? "" }:
94+ nix-bootstrap = { target, extraTargets ? [], run, nix-user-chroot' ? nix-user-chroot, nixUserChrootFlags ? "", initScript ? "" }:
80 let
95 let
81− script = makeStartup { inherit target nixUserChrootFlags nix-user-chroot' run; };
96+ script = makeStartup { inherit target nixUserChrootFlags nix-user-chroot' run initScript; };
82 in makebootstrap {
97 in makebootstrap {
83 startup = ".${script} '\"$@\"'";
98 startup = ".${script} '\"$@\"'";
84 targets = [ "${script}" ] ++ extraTargets;
99 targets = [ "${script}" ] ++ extraTargets;
@@ -95,10 +110,10 @@ in rec {
95 nix-user-chroot'' = targets: nix-user-chroot.overrideDerivation (o: {
110 nix-user-chroot'' = targets: nix-user-chroot.overrideDerivation (o: {
96 buildInputs = o.buildInputs ++ targets;
111 buildInputs = o.buildInputs ++ targets;
97 makeFlags = o.makeFlags ++ [
112 makeFlags = o.makeFlags ++ [
98− ''ENV_PATH="${stdenv.lib.makeBinPath targets}"''
113+ ''ENV_PATH="${lib.makeBinPath targets}"''
99 ];
114 ];
100− }); in { target, extraTargets ? [], run }: nix-bootstrap {
115+ }); in { target, extraTargets ? [], run, initScript ? "" }: nix-bootstrap {
101− inherit target extraTargets run;
116+ inherit target extraTargets run initScript;
102 nix-user-chroot' = nix-user-chroot'' extraTargets;
117 nix-user-chroot' = nix-user-chroot'' extraTargets;
103 };
118 };
104}
119}
flake.nix+1−1
@@ -13,7 +13,7 @@
13 nix-bundle = import self { nixpkgs = nixpkgs'; };
13 nix-bundle = import self { nixpkgs = nixpkgs'; };
14 script = nixpkgs'.writeScript "startup" ''
14 script = nixpkgs'.writeScript "startup" ''
15 #!/bin/sh
15 #!/bin/sh
16− .${nix-bundle.nix-user-chroot}/bin/nix-user-chroot -n ./nix -- ${program} $@
16+ .${nix-bundle.nix-user-chroot}/bin/nix-user-chroot -n ./nix -- ${program} "$@"
17 '';
17 '';
18 in nix-bundle.makebootstrap {
18 in nix-bundle.makebootstrap {
19 targets = [ script ];
19 targets = [ script ];
nix-bootstrap.sh+13−13
@@ -1,35 +1,35 @@
1#!/bin/sh
1#!/bin/sh
2
2
3−cmd=sh
4−if ! [ $# -eq 0 ]; then
3+if [ $# -gt 0 ]; then
5− cmd=$@
4+ set -- sh
6fi
5fi
7
6
8# should download this in the future
7# should download this in the future
9# but the mirror is down
8# but the mirror is down
10−proot=`dirname $0`/proot-`uname -p`
9+proot=$(dirname "$0")/proot-$(uname -p)
11export PROOT_NO_SECCOMP=1
10export PROOT_NO_SECCOMP=1
12
11
13nixdir=$HOME/.nix
12nixdir=$HOME/.nix
14
13
15OLD_NIX_PATH=$NIX_PATH
14OLD_NIX_PATH=$NIX_PATH
15+# shellcheck disable=SC1090
16−if [ -e $HOME/.nix-profile/etc/profile.d/nix.sh ]; then . $HOME/.nix-profile/etc/profile.d/nix.sh; fi
16+if [ -e "$HOME/.nix-profile/etc/profile.d/nix.sh" ]; then . "$HOME/.nix-profile/etc/profile.d/nix.sh"; fi
17−if ! [ -z "$OLD_NIX_PATH" ]; then NIX_PATH="$OLD_NIX_PATH"; fi
17+if [ -n "$OLD_NIX_PATH" ]; then NIX_PATH="$OLD_NIX_PATH"; fi
18
18
19if [ -z "$IN_PROOT" ]; then
19if [ -z "$IN_PROOT" ]; then
20 export IN_PROOT=1
20 export IN_PROOT=1
21
21
22− if ! [ -d $nixdir ]; then
22+ if ! [ -d "$nixdir" ]; then
23− mkdir -p $nixdir
23+ mkdir -p "$nixdir"
24 s=$(mktemp)
24 s=$(mktemp)
25− curl https://nixos.org/nix/install -o $s
25+ curl https://nixos.org/nix/install -o "$s"
26− $proot -b $nixdir:/nix $0 sh $s
26+ $proot -b "$nixdir:/nix" "$0" sh "$s"
27 fi
27 fi
28
28
29− $proot -b $nixdir:/nix $0 $cmd
29+ $proot -b "$nixdir:/nix" "$0" "$@"
30
30
31 export IN_PROOT=
31 export IN_PROOT=
32 exit
32 exit
33−elif ! [ $# -eq 0 ]; then
33+elif [ $# -gt 0 ]; then
34− exec $cmd
34+ exec "$@"
35fi
35fi
nix-bundle.sh+4−1
@@ -8,6 +8,9 @@ Usage: $0 TARGET EXECUTABLE
8Create a single-file bundle from the nixpkgs attribute "TARGET".
8Create a single-file bundle from the nixpkgs attribute "TARGET".
9EXECUTABLE should be relative to the TARGET's output path.
9EXECUTABLE should be relative to the TARGET's output path.
10
10
11+The TARGET is either an attribute in nixpkgs, or an absolute path to the
12+store.
13+
11For example:
14For example:
12
15
13$ $0 hello /bin/hello
16$ $0 hello /bin/hello
@@ -56,5 +59,5 @@ elif [ -t 1 ]; then
56 echo "Nix bundle created at $filename."
59 echo "Nix bundle created at $filename."
57 cp -f "$out" "$filename"
60 cp -f "$out" "$filename"
58else
61else
59− cat "$out"
62+ echo "$out"
60fi
63fi
nix-run.sh+10−10
@@ -22,7 +22,7 @@ pkg="$1"
22shift
22shift
23
23
24# A second argument will provide a hint to run
24# A second argument will provide a hint to run
25−if ! [ -z "$1" ]; then
25+if [ -n "$1" ]; then
26 name="$1"
26 name="$1"
27 shift
27 shift
28else
28else
@@ -53,11 +53,11 @@ run_linux_desktop_app () {
53 file="$1"
53 file="$1"
54 shift
54 shift
55
55
56− cmd=$(grep '^Exec' $file | tail -1 | \
56+ cmd=$(grep '^Exec' "$file" | tail -1 | \
57 sed 's/Exec=//;s/^"//;s/" *$//')
57 sed 's/Exec=//;s/^"//;s/" *$//')
58
58
59− if ! [ -z "$@" ]; then
59+ if [ "$#" -gt 0 ]; then
60− cmd=$(echo "$cmd" | sed "s/%[fu]/$1/;s/%[FU]/$@/")
60+ cmd=$(echo "$cmd" | sed "s/%[fu]/$1/;s/%[FU]/$*/")
61 fi
61 fi
62
62
63 cmd=$(echo "$cmd" | sed "s/%k/$desktop/;s/%.//")
63 cmd=$(echo "$cmd" | sed "s/%k/$desktop/;s/%.//")
@@ -79,20 +79,20 @@ elif [ -x "$out/bin/run" ]; then
79 run_bin "$out/bin/run" "$@"
79 run_bin "$out/bin/run" "$@"
80elif [ "$(uname)" = Darwin ] && [ -d "$out/Applications/$name.app" ]; then
80elif [ "$(uname)" = Darwin ] && [ -d "$out/Applications/$name.app" ]; then
81 run_darwin_app "$out/Applications/$name.app" "$@"
81 run_darwin_app "$out/Applications/$name.app" "$@"
82−elif [ "$(uname)" = Darwin ] && [ -d $out/Applications/*.app ]; then
82+elif [ "$(uname)" = Darwin ] && [ -d "$out"/Applications/*.app ]; then
83− for f in $out/Applications/*.app; do
83+ for f in "$out"/Applications/*.app; do
84 run_darwin_app "$f" "$@"
84 run_darwin_app "$f" "$@"
85 done
85 done
86elif [ -f "$out/share/applications/$name.desktop" ]; then
86elif [ -f "$out/share/applications/$name.desktop" ]; then
87− run_linux_desktop_app "$out/share/applications/$name.desktop" $@
87+ run_linux_desktop_app "$out/share/applications/$name.desktop" "$@"
88−elif [ -d $out/share/applications ]; then
88+elif [ -d "$out"/share/applications ]; then
89− for f in $out/share/applications/*.desktop; do
89+ for f in "$out"/share/applications/*.desktop; do
90 run_linux_desktop_app "$f"
90 run_linux_desktop_app "$f"
91 done
91 done
92elif [ -x "$out/bin/$name" ]; then
92elif [ -x "$out/bin/$name" ]; then
93 run_bin "$out/bin/$name" "$@"
93 run_bin "$out/bin/$name" "$@"
94elif [ -d "$out/bin" ]; then
94elif [ -d "$out/bin" ]; then
95− for bin in $out/bin/*; do
95+ for bin in "$out"/bin/*; do
96 run_bin "$bin" "$@"
96 run_bin "$bin" "$@"
97 done
97 done
98else
98else
test.shnew file+10
@@ -0,0 +1,10 @@
1+#!/usr/bin/env bash
2+set -euo pipefail
3+export NIX_PATH=channel:nixos-20.09
4+
5+echo "Test with attribute name"
6+./nix-bundle.sh hello /bin/hello
7+
8+echo "Test with store path"
9+out=$(nix-build --no-out-link --expr '(import <nixpkgs> {})' -A hello)
10+./nix-bundle.sh "$out" /bin/hello