File tree Expand file tree Collapse file tree 5 files changed +70
-1
lines changed Expand file tree Collapse file tree 5 files changed +70
-1
lines changed Original file line number Diff line number Diff line change @@ -594,6 +594,10 @@ void LocalDerivationGoal::startBuilder()
594
594
else
595
595
dirsInChroot[i.substr (0 , p)] = {i.substr (p + 1 ), optional};
596
596
}
597
+ if (hasPrefix (worker.store .storeDir , tmpDirInSandbox))
598
+ {
599
+ throw Error (" `sandbox-build-dir` must not contain the storeDir" );
600
+ }
597
601
dirsInChroot[tmpDirInSandbox] = tmpDir;
598
602
599
603
/* Add the closure of store paths to the chroot. */
Original file line number Diff line number Diff line change @@ -138,7 +138,8 @@ nix_tests = \
138
138
path-from-hash-part.sh \
139
139
test-libstoreconsumer.sh \
140
140
toString-path.sh \
141
- read-only-store.sh
141
+ read-only-store.sh \
142
+ nested-sandboxing.sh
142
143
143
144
ifeq ($(HAVE_LIBCPUID ) , 1)
144
145
nix_tests += compute-levels.sh
Original file line number Diff line number Diff line change
1
+ source common.sh
2
+ # This test is run by `tests/nested-sandboxing/runner.nix` in an extra layer of sandboxing.
3
+ [[ -d /nix/store ]] || skipTest " running this test without Nix's deps being drawn from /nix/store is not yet supported"
4
+
5
+ requireSandboxSupport
6
+
7
+ source ./nested-sandboxing/command.sh
8
+
9
+ expectStderr 100 runNixBuild badStoreUrl 2 | grepQuiet ' `sandbox-build-dir` must not contain'
10
+
11
+ runNixBuild goodStoreUrl 5
Original file line number Diff line number Diff line change
1
+ export NIX_BIN_DIR=$( dirname $( type -p nix) )
2
+ # TODO Get Nix and its closure more flexibly
3
+ export EXTRA_SANDBOX=" /nix/store $( dirname $NIX_BIN_DIR ) "
4
+
5
+ badStoreUrl () {
6
+ local altitude=$1
7
+ echo $TEST_ROOT /store-$altitude
8
+ }
9
+
10
+ goodStoreUrl () {
11
+ local altitude=$1
12
+ echo $( " badStoreUrl" " $altitude " ) ? store=/foo-$altitude
13
+ }
14
+
15
+ # The non-standard sandbox-build-dir helps ensure that we get the same behavior
16
+ # whether this test is being run in a derivation as part of the nix build or
17
+ # being manually run by a developer outside a derivation
18
+ runNixBuild () {
19
+ local storeFun=$1
20
+ local altitude=$2
21
+ nix-build \
22
+ --no-substitute --no-out-link \
23
+ --store " $( " $storeFun " " $altitude " ) " \
24
+ --extra-sandbox-paths " $EXTRA_SANDBOX " \
25
+ ./nested-sandboxing/runner.nix \
26
+ --arg altitude " $(( altitude - 1 )) " \
27
+ --argstr storeFun " $storeFun " \
28
+ --sandbox-build-dir /build-non-standard
29
+ }
Original file line number Diff line number Diff line change
1
+ { altitude , storeFun } :
2
+
3
+ with import ../config.nix ;
4
+
5
+ mkDerivation {
6
+ name = "nested-sandboxing" ;
7
+ busybox = builtins . getEnv "busybox" ;
8
+ EXTRA_SANDBOX = builtins . getEnv "EXTRA_SANDBOX" ;
9
+ buildCommand = if altitude == 0 then ''
10
+ echo Deep enough! > $out
11
+ '' else ''
12
+ cp -r ${ ../common } ./common
13
+ cp ${ ../common.sh } ./common.sh
14
+ cp ${ ../config.nix } ./config.nix
15
+ cp -r ${ ./. } ./nested-sandboxing
16
+
17
+ export PATH=${ builtins . getEnv "NIX_BIN_DIR" } :$PATH
18
+
19
+ source common.sh
20
+ source ./nested-sandboxing/command.sh
21
+
22
+ runNixBuild ${ storeFun } ${ toString altitude } >> $out
23
+ '' ;
24
+ }
You can’t perform that action at this time.
0 commit comments