on ebbcafa help sign in
13 files changed+61−278
since splitsnapshots
unifiedsplit
AppRun.c+1−9 README.md+1−14 appdir.nix+4−4 appimage-bundle.nix−61 appimagetool.nix+2−2 default.nix+8−26 flake.nix−26 nix-bootstrap.sh+13−13 nix-bundle.sh+6−11 nix-run.sh+21−23 nix-user-chroot/main.cpp+4−78 release.nix+1−1 test.sh−10
AppRun.c+1−9
@@ -207,11 +207,6 @@ int main(int argc, char *argv[]) {
207207 err_exit("mount(%s, %s)", usrdir, path_buf);
208208 }
209209
210− snprintf(path_buf, sizeof(path_buf), "%s/bin", rootdir);
211− if (symlink("/usr/bin", path_buf) < 0) {
212− err_exit("symlink(/usr/bin, %s)", path_buf);
213− }
214−
215210 // fixes issue #1 where writing to /proc/self/gid_map fails
216211 // see user_namespaces(7) for more documentation
217212 int fd_setgroups = open("/proc/self/setgroups", O_WRONLY);
@@ -231,10 +226,8 @@ int main(int argc, char *argv[]) {
231226 err_exit("chroot(%s)", rootdir);
232227 }
233228
234− char *pwddir = getenv("PWD");
235− chdir(pwddir);
229+ chdir("/");
236230
237− SAVE_ENV_VAR(PWD);
238231 SAVE_ENV_VAR(DBUS_SESSION_BUS_ADDRESS);
239232 SAVE_ENV_VAR(USER);
240233 SAVE_ENV_VAR(HOSTNAME);
@@ -250,7 +243,6 @@ int main(int argc, char *argv[]) {
250243
251244 clearenv();
252245
253− LOAD_ENV_VAR(PWD);
254246 LOAD_ENV_VAR(DBUS_SESSION_BUS_ADDRESS);
255247 LOAD_ENV_VAR(USER);
256248 LOAD_ENV_VAR(HOSTNAME);
README.md+1−14
@@ -35,27 +35,14 @@ Some others to try:
3535./nix-bundle.sh nano /bin/nano
3636```
3737
38−```sh
39−./nix-bundle.sh emacs /bin/emacs
40−```
41−
42−Or if you want to try graphical applications:
43−
44−```sh
45−# Simple X game. Very few dependencies. Quick to build and load. ~13MB
46−./nix-bundle.sh xskat /bin/xskat
47−```
48−
4938```sh
5039./nix-bundle.sh firefox /bin/firefox
5140```
5241
5342```sh
54−# SDL-based game. ~228MB
55−./nix-bundle.sh ivan /bin/ivan
43+./nix-bundle.sh emacs /bin/emacs
5644```
5745
58−
5946## Self-bundling (meta)
6047
6148Starting with v0.1.3, you can bundle nix-bundle! To do this, just use nix-bundle normally:
appdir.nix+4−4
@@ -1,4 +1,4 @@
1−{ stdenv, lib, fetchurl, muslPkgs, perl, pathsFromGraph, fetchFromGitHub, coreutils, bash }:
1+{ stdenv, fetchurl, muslPkgs, perl, pathsFromGraph, fetchFromGitHub, coreutils, bash }:
22
33let
44 AppRun = targets: muslPkgs.stdenv.mkDerivation {
@@ -8,7 +8,7 @@ let
88
99 buildPhase = ''
1010 CC="$CC -O2 -Wall -Wno-deprecated-declarations -Wno-unused-result -static"
11− $CC ${./AppRun.c} -o AppRun -DENV_PATH='"${lib.makeBinPath targets}"'
11+ $CC ${./AppRun.c} -o AppRun -DENV_PATH='"${stdenv.lib.makeBinPath targets}"'
1212 '';
1313
1414 installPhase = ''
@@ -63,12 +63,12 @@ in
6363
6464 # icons
6565 if [ -d ${target}/share/icons ]; then
66− icon=$(find ${target}/share/icons -name "${name}*.png" | head -n1)
66+ icon=$(find ${target}/share/icons -name "${name}.png" | head -n1)
6767 if ! [ -z "$icon" ]; then
6868 ln -s .$icon
6969 ln -s .$icon .DirIcon
7070 else
71− icon=$(find ${target}/share/icons -name "${name}*.svg" | head -n1)
71+ icon=$(find ${target}/share/icons -name "${name}.svg" | head -n1)
7272 if ! [ -z "$icon" ]; then
7373 ln -s .$icon
7474 ln -s .$icon .DirIcon
appimage-bundle.nixdeleted−61
@@ -1,61 +0,0 @@
1−# use like this:
2−# nix-build appimage-bundle.nix --argstr package hello --argstr exec hello
3−# nix-build appimage-bundle.nix --arg package 'with import <nixpkgs>{}; writers.writePython3Bin "helloThere.py" {} "print(1)\n"' --argstr exec helloThere.py
4−
5−
6−{nixpkgs ? import <nixpkgs>{},
7−package,
8−exec,
9−... }:
10−let
11− appimage_src = drv : exec : with nixpkgs;
12− self.stdenv.mkDerivation rec {
13− name = drv.name + "-appdir";
14− env = buildEnv {
15− inherit name;
16− paths = buildInputs;
17− };
18− src = env;
19− inherit exec;
20− buildInputs = [ drv ];
21− buildCommand = ''
22− mkdir -p $out/share/icons/hicolor/256x256/apps
23− mkdir -p $out/share/applications
24−
25− shopt -s extglob
26− ln -s ${env}/!(share) $out/
27− ln -s ${env}/share/* $out/share/
28−
29− touch $out/share/icons/hicolor/256x256/apps/${drv.name}.png
30− touch $out/share/icons/${drv.name}.png
31−
32− cat <<EOF > $out/share/applications/${drv.name}.desktop
33− [Desktop Entry]
34− Type=Application
35− Version=1.0
36− Name=${drv.name}
37− Path=${env}
38− Icon=${drv.name}
39− Exec=$exec
40− Terminal=true
41− EOF
42− '';
43− system = builtins.currentSystem;
44− };
45−
46−in
47− let results =
48− if (nixpkgs.lib.isDerivation package && !(nixpkgs.lib.isString package))
49− then {
50− name = package.name;
51− target = appimage_src package "${exec}";
52− extraTargets = [];
53− }
54− else {
55− name = nixpkgs."${package}".name;
56− target = appimage_src (nixpkgs."${package}") "${exec}";
57− extraTargets = [];
58− };
59− in
60− with (import (./appimage-top.nix){nixpkgs' = nixpkgs.path;});
61− (appimage (appdir results )).overrideAttrs (old: {name = results.name;})
appimagetool.nix+2−2
@@ -1,4 +1,4 @@
1−{ stdenv, lib, fetchurl, fuse, zlib, squashfsTools, glib }:
1+{ stdenv, fetchurl, fuse, zlib, squashfsTools, glib }:
22
33# This is from some binaries.
44
@@ -37,7 +37,7 @@ in stdenv.mkDerivation rec {
3737 for x in $out/bin/*; do
3838 patchelf \
3939 --set-interpreter ${dynamicLinker} \
40− --set-rpath ${lib.makeLibraryPath [ zlib stdenv.glibc.out fuse glib ]} \
40+ --set-rpath ${stdenv.lib.makeLibraryPath [ zlib stdenv.glibc.out fuse glib ]} \
4141 $x
4242 done
4343 '';
default.nix+8−26
@@ -10,16 +10,6 @@ let
1010 '';
1111 });
1212in 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−
2313 arx = { archive, startup}:
2414 stdenv.mkDerivation {
2515 name = "arx";
@@ -45,7 +35,7 @@ in rec {
4535 };
4636
4737 # TODO: eventually should this go in nixpkgs?
48− nix-user-chroot = lib.makeOverridable stdenv.mkDerivation {
38+ nix-user-chroot = stdenv.lib.makeOverridable stdenv.mkDerivation {
4939 name = "nix-user-chroot-2c52b5f";
5040 src = ./nix-user-chroot;
5141
@@ -68,8 +58,6 @@ in rec {
6858
6959 runHook postInstall
7060 '';
71−
72− meta.platforms = lib.platforms.linux;
7361 };
7462
7563 makebootstrap = { targets, startup }:
@@ -80,20 +68,14 @@ in rec {
8068 };
8169 };
8270
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
71+ makeStartup = { target, nixUserChrootFlags, nix-user-chroot', run }:
8872 writeScript "startup" ''
89− #!/bin/sh
90− ${initScript}
91− .${nix-user-chroot'}/bin/nix-user-chroot -n ./nix ${nixUserChrootFlags} -- ${path}${run} "$@"
73+.${nix-user-chroot'}/bin/nix-user-chroot -n ./nix ${nixUserChrootFlags} -- ${target}${run} $@
9274 '';
9375
94− nix-bootstrap = { target, extraTargets ? [], run, nix-user-chroot' ? nix-user-chroot, nixUserChrootFlags ? "", initScript ? "" }:
76+ nix-bootstrap = { target, extraTargets ? [], run, nix-user-chroot' ? nix-user-chroot, nixUserChrootFlags ? "" }:
9577 let
96− script = makeStartup { inherit target nixUserChrootFlags nix-user-chroot' run initScript; };
78+ script = makeStartup { inherit target nixUserChrootFlags nix-user-chroot' run; };
9779 in makebootstrap {
9880 startup = ".${script} '\"$@\"'";
9981 targets = [ "${script}" ] ++ extraTargets;
@@ -110,10 +92,10 @@ in rec {
11092 nix-user-chroot'' = targets: nix-user-chroot.overrideDerivation (o: {
11193 buildInputs = o.buildInputs ++ targets;
11294 makeFlags = o.makeFlags ++ [
113− ''ENV_PATH="${lib.makeBinPath targets}"''
95+ ''ENV_PATH="${stdenv.lib.makeBinPath targets}"''
11496 ];
115− }); in { target, extraTargets ? [], run, initScript ? "" }: nix-bootstrap {
116− inherit target extraTargets run initScript;
97+ }); in { target, extraTargets ? [], run }: nix-bootstrap {
98+ inherit target extraTargets run;
11799 nix-user-chroot' = nix-user-chroot'' extraTargets;
118100 };
119101}
flake.nixdeleted−26
@@ -1,26 +0,0 @@
1−{
2− description = "The purely functional package manager";
3−
4− inputs.nixpkgs.url = "nixpkgs/nixos-20.03-small";
5−
6− outputs = { self, nixpkgs }: let
7− systems = [ "x86_64-linux" "i686-linux" "aarch64-linux" ];
8− forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f system);
9− in {
10− bundlers = {
11− nix-bundle = { program, system }: let
12− nixpkgs' = nixpkgs.legacyPackages.${system};
13− nix-bundle = import self { nixpkgs = nixpkgs'; };
14− script = nixpkgs'.writeScript "startup" ''
15− #!/bin/sh
16− .${nix-bundle.nix-user-chroot}/bin/nix-user-chroot -n ./nix -- ${program} "$@"
17− '';
18− in nix-bundle.makebootstrap {
19− targets = [ script ];
20− startup = ".${builtins.unsafeDiscardStringContext script} '\"$@\"'";
21− };
22− };
23−
24− defaultBundler = self.bundlers.nix-bundle;
25− };
26−}
nix-bootstrap.sh+13−13
@@ -1,35 +1,35 @@
11#!/bin/sh
22
3−if [ $# -gt 0 ]; then
4− set -- sh
3+cmd=sh
4+if ! [ $# -eq 0 ]; then
5+ cmd=$@
56fi
67
78# should download this in the future
89# but the mirror is down
9−proot=$(dirname "$0")/proot-$(uname -p)
10+proot=`dirname $0`/proot-`uname -p`
1011export PROOT_NO_SECCOMP=1
1112
1213nixdir=$HOME/.nix
1314
1415OLD_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
17−if [ -n "$OLD_NIX_PATH" ]; then NIX_PATH="$OLD_NIX_PATH"; 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
1818
1919if [ -z "$IN_PROOT" ]; then
2020 export IN_PROOT=1
2121
22− if ! [ -d "$nixdir" ]; then
23− mkdir -p "$nixdir"
22+ if ! [ -d $nixdir ]; then
23+ mkdir -p $nixdir
2424 s=$(mktemp)
25− curl https://nixos.org/nix/install -o "$s"
26− $proot -b "$nixdir:/nix" "$0" sh "$s"
25+ curl https://nixos.org/nix/install -o $s
26+ $proot -b $nixdir:/nix $0 sh $s
2727 fi
2828
29− $proot -b "$nixdir:/nix" "$0" "$@"
29+ $proot -b $nixdir:/nix $0 $cmd
3030
3131 export IN_PROOT=
3232 exit
33−elif [ $# -gt 0 ]; then
34− exec "$@"
33+elif ! [ $# -eq 0 ]; then
34+ exec $cmd
3535fi
nix-bundle.sh+6−11
@@ -8,9 +8,6 @@ Usage: $0 TARGET EXECUTABLE
88Create a single-file bundle from the nixpkgs attribute "TARGET".
99EXECUTABLE should be relative to the TARGET's output path.
1010
11−The TARGET is either an attribute in nixpkgs, or an absolute path to the
12−store.
13−
1411For example:
1512
1613$ $0 hello /bin/hello
@@ -22,7 +19,7 @@ EOF
2219 exit 1
2320fi
2421
25−nix_file=$(dirname "$0")/default.nix
22+nix_file=`dirname $0`/default.nix
2623
2724target="$1"
2825shift
@@ -41,23 +38,21 @@ shift
4138bootstrap=nix-bootstrap
4239if [ "$target" = "nix-bundle" ] || [ "$target" = "nixStable" ] || [ "$target" = "nixUnstable" ] || [ "$target" = "nix" ]; then
4340 bootstrap=nix-bootstrap-nix
44−elif [ -n "$extraTargets" ]; then
41+elif ! [ -z "$extraTargets" ]; then
4542 bootstrap=nix-bootstrap-path
4643fi
4744
4845expr="with import <nixpkgs> {}; with import $nix_file {}; $bootstrap { target = $target; extraTargets = [ $extraTargets ]; run = \"$exec\"; }"
4946
50−drv=$(nix-instantiate --no-gc-warning -E "$expr")
51−
52−out=$(nix-store --no-gc-warning --realize "$drv")
47+out=$(nix-store --no-gc-warning -r $(nix-instantiate --no-gc-warning -E "$expr"))
5348
5449if [ -z "$out" ]; then
5550 >&2 echo "$0 failed. Exiting."
5651 exit 1
5752elif [ -t 1 ]; then
58− filename=$(basename "$exec")
53+ filename=$(basename $exec)
5954 echo "Nix bundle created at $filename."
60− cp -f "$out" "$filename"
55+ cp -f $out $filename
6156else
62− echo "$out"
57+ cat $out
6358fi
nix-run.sh+21−23
@@ -18,11 +18,11 @@ if [ -z "$1" ]; then
1818 exit 1
1919fi
2020
21−pkg="$1"
21+pkg=$1
2222shift
2323
2424# A second argument will provide a hint to run
25−if [ -n "$1" ]; then
25+if ! [ -z "$1" ]; then
2626 name="$1"
2727 shift
2828else
@@ -31,7 +31,7 @@ fi
3131
3232expr="with import <nixpkgs> {}; let x = ($pkg); in x"
3333path=$(nix-instantiate --no-gc-warning -E "$expr")
34−out=$(nix-store --no-gc-warning -r "$path")
34+out=$(nix-store --no-gc-warning -r $path)
3535
3636if [ -z "$out" ]; then
3737 >&2 echo "Could not evaluate $pkg to a Nix drv."
@@ -43,7 +43,7 @@ run_darwin_app () {
4343 dir="$1"
4444 shift
4545
46− open -a "$dir" --args "$@"
46+ open -a "$dir" --args $@
4747}
4848
4949# Run FILE as a Freedesktop application
@@ -53,16 +53,14 @@ run_linux_desktop_app () {
5353 file="$1"
5454 shift
5555
56− cmd=$(grep '^Exec' "$file" | tail -1 | \
57− sed 's/Exec=//;s/^"//;s/" *$//')
56+ cmd=$(grep '^Exec' $file | tail -1 | \
57+ sed 's/Exec=//;s/^"//;s/" *$/')
5858
59− if [ "$#" -gt 0 ]; then
60− cmd=$(echo "$cmd" | sed "s/%[fu]/$1/;s/%[FU]/$*/")
59+ if ! [ -z "$@" ]; then
60+ cmd=$(echo "$cmd" | sed "s/%[fu]/$1/;s/%[FU]/$@/")
6161 fi
6262
6363 cmd=$(echo "$cmd" | sed "s/%k/$desktop/;s/%.//")
64−
65− "$cmd" "$@"
6664}
6765
6866# Run FILE as an ordinary binary
@@ -70,30 +68,30 @@ run_bin () {
7068 file="$1"
7169 shift
7270
73− "$file" "$@"
71+ $file $@
7472}
7573
7674if [ -x "$out/nix-support/run" ]; then
77− run_bin "$out/nix-support/run" "$@"
75+ run_bin "$out/nix-support/run" $@
7876elif [ -x "$out/bin/run" ]; then
79− run_bin "$out/bin/run" "$@"
77+ run_bin "$out/bin/run" $@
8078elif [ "$(uname)" = Darwin ] && [ -d "$out/Applications/$name.app" ]; then
81− run_darwin_app "$out/Applications/$name.app" "$@"
82−elif [ "$(uname)" = Darwin ] && [ -d "$out"/Applications/*.app ]; then
83− for f in "$out"/Applications/*.app; do
84− run_darwin_app "$f" "$@"
79+ run_darwin_app "$out/Applications/$name.app" $@
80+elif [ "$(uname)" = Darwin ] && [ -d $out/Applications/*.app ]; then
81+ for f in $out/Applications/*.app; do
82+ run_darwin_app "$f" $@
8583 done
8684elif [ -f "$out/share/applications/$name.desktop" ]; then
87− run_linux_desktop_app "$out/share/applications/$name.desktop" "$@"
88−elif [ -d "$out"/share/applications ]; then
89− for f in "$out"/share/applications/*.desktop; do
85+ run_linux_desktop_app "$out/share/applications/$name.desktop" $@
86+elif [ -d $out/share/applications ]; then
87+ for f in $out/share/applications/*.desktop; do
9088 run_linux_desktop_app "$f"
9189 done
9290elif [ -x "$out/bin/$name" ]; then
93− run_bin "$out/bin/$name" "$@"
91+ run_bin "$out/bin/$name" $@
9492elif [ -d "$out/bin" ]; then
95− for bin in "$out"/bin/*; do
96− run_bin "$bin" "$@"
93+ for bin in $out/bin/*; do
94+ run_bin "$bin" $@
9795 done
9896else
9997 >&2 echo "Cannot find a way to run path $out."
nix-user-chroot/main.cpp+4−78
@@ -26,10 +26,6 @@
2626using namespace std;
2727
2828#define err_exit(format, ...) { fprintf(stderr, format ": %s\n", ##__VA_ARGS__, strerror(errno)); exit(EXIT_FAILURE); }
29−static int child_proc(const char *rootdir, const char *nixdir, uint8_t clear_env, list<struct DirMapping> dirMappings, list<struct SetEnv> envMappings, const char *executable, char * const new_argv[]);
30−
31−volatile uint8_t child_died = 0;
32−int child_pid = 0;
3329
3430static void usage(const char *pname) {
3531 fprintf(stderr, "Usage: %s -n <nixpath> -- <command>\n", pname);
@@ -37,7 +33,6 @@ static void usage(const char *pname) {
3733 fprintf(stderr, "\t-m <src>:<src>\tmap src on the host to dest in the sandbox\n");
3834 fprintf(stderr, "\t-d\tdelete all default dir mappings, may break things\n");
3935 fprintf(stderr, "\t-p <var>\tpreserve the value of a variable across the -c clear\n");
40− fprintf(stderr, "\t-e\tadd an /escape-hatch to the sandbox, and run (outside the sandbox) any strings written to it\n");
4136
4237 exit(EXIT_FAILURE);
4338}
@@ -96,15 +91,8 @@ struct DirMapping parseMapping(string input) {
9691 return (struct DirMapping){ src, dest };
9792}
9893
99−static void handle_child_death(int signo, siginfo_t *info, void *context) {
100− if ( (child_pid == 0) || (info->si_pid == child_pid) ) {
101− child_died = 1;
102− }
103−}
104−
10594int main(int argc, char *argv[]) {
10695 uint8_t clear_env = 0;
107− uint8_t enable_escape_hatch = 0;
10896 char *nixdir = NULL;
10997 list<struct DirMapping> dirMappings;
11098 list<struct SetEnv> envMappings;
@@ -119,19 +107,14 @@ int main(int argc, char *argv[]) {
119107 x("var");
120108 x("etc");
121109 x("usr");
122− x("home");
123− x("root");
124110#undef x
125111
126112 int opt;
127− while ((opt = getopt(argc, argv, "cen:m:dp:")) != -1) {
113+ while ((opt = getopt(argc, argv, "cn:m:dp:")) != -1) {
128114 switch (opt) {
129115 case 'c':
130116 clear_env = 1;
131117 break;
132− case 'e':
133− enable_escape_hatch = 1;
134− break;
135118 case 'n':
136119 // determine absolute directory for nix dir
137120 nixdir = realpath(optarg, NULL);
@@ -179,62 +162,6 @@ int main(int argc, char *argv[]) {
179162 err_exit("mkdtemp(%s)", template_);
180163 }
181164
182− int unrace[2];
183−
184− if (pipe(unrace)) {
185− err_exit("pipe()");
186− }
187−
188− struct sigaction handle_child;
189− handle_child.sa_sigaction = handle_child_death;
190− handle_child.sa_flags = SA_SIGINFO;
191−
192− struct sigaction old_handler;
193− if (sigaction(SIGCHLD, &handle_child, &old_handler)) {
194− err_exit("sigaction()");
195− }
196−
197− int child;
198− child = child_pid = fork();
199− if (child < 0) {
200− err_exit("fork()");
201− } else if (child == 0) {
202− sigaction(SIGCHLD, &old_handler, NULL);
203− close(unrace[1]);
204− char buf[10];
205− read(unrace[0], buf, 10);
206− close(unrace[0]);
207− return child_proc(rootdir, nixdir, clear_env, dirMappings, envMappings, argv[optind], argv + optind);
208− } else {
209− close(unrace[0]);
210− char fifopath[PATH_MAX];
211− if (enable_escape_hatch) {
212− snprintf(fifopath, PATH_MAX, "%s/escape-hatch", rootdir);
213− mkfifo(fifopath, 0600);
214− }
215− close(unrace[1]);
216− if (enable_escape_hatch) {
217− char buffer[1024];
218− while (!child_died) {
219− int fd = open(fifopath, O_RDONLY);
220− if (fd < 0) {
221− if (errno == EINTR) continue;
222− fprintf(stderr, "error opening escape-hatch: %s\n", strerror(errno));
223− continue;
224− }
225− int size = read(fd, buffer, 1024);
226− buffer[size] = 0;
227− system(buffer);
228− close(fd);
229− }
230− }
231− int status;
232− int ret = waitpid(child, &status, 0);
233− return WEXITSTATUS(status);
234− }
235−}
236−
237−static int child_proc(const char *rootdir, const char *nixdir, uint8_t clear_env, list<struct DirMapping> dirMappings, list<struct SetEnv> envMappings, const char *executable, char * const new_argv[]) {
238165 // get uid, gid before going to new namespace
239166 uid_t uid = getuid();
240167 gid_t gid = getgid();
@@ -242,7 +169,7 @@ static int child_proc(const char *rootdir, const char *nixdir, uint8_t clear_env
242169 // "unshare" into new namespace
243170 if (unshare(CLONE_NEWNS | CLONE_NEWUSER) < 0) {
244171 if (errno == EPERM) {
245− fputs("Run the following to enable unprivileged namespace use:\nsudo bash -c \"sysctl -w kernel.unprivileged_userns_clone=1 ; echo kernel.unprivileged_userns_clone=1 > /etc/sysctl.d/nix-user-chroot.conf\"\n\n", stderr);
172+ fputs("Run the following as root to enable unprivileged namespace use:\nsysctl -w kernel.unprivileged_userns_clone=1 ; echo kernel.unprivileged_userns_clone=1 > /etc/sysctl.d/nix-user-chroot.conf\n\n", stderr);
246173 exit(EXIT_FAILURE);
247174 } else {
248175 err_exit("unshare()");
@@ -275,7 +202,6 @@ static int child_proc(const char *rootdir, const char *nixdir, uint8_t clear_env
275202 int fd_setgroups = open("/proc/self/setgroups", O_WRONLY);
276203 if (fd_setgroups > 0) {
277204 write(fd_setgroups, "deny", 4);
278− close(fd_setgroups);
279205 }
280206
281207 // map the original uid/gid in the new ns
@@ -302,6 +228,6 @@ static int child_proc(const char *rootdir, const char *nixdir, uint8_t clear_env
302228 }
303229
304230 // execute the command
305− execvp(executable, new_argv);
306− err_exit("execvp(%s)", executable);
231+ execvp(argv[optind], argv + optind);
232+ err_exit("execvp(%s)", argv[optind]);
307233}
release.nix+1−1
@@ -4,7 +4,7 @@
44stdenv.mkDerivation rec {
55 pname = "nix-bundle";
66 name = "${pname}-${version}";
7− version = "0.4.0";
7+ version = "0.3.0";
88
99 src = ./.;
1010
test.shdeleted−10
@@ -1,10 +0,0 @@
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