Skip to content

Commit

Permalink
Make the location of the build directory in the sandbox configurable
Browse files Browse the repository at this point in the history
This is mostly for use in the sandbox tests, since if the Nix store is
under /build, then we can't use /build as the build directory.
  • Loading branch information
edolstra committed May 5, 2017
1 parent 465cb68 commit bb50c89
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
7 changes: 2 additions & 5 deletions src/libstore/build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1661,9 +1661,6 @@ int childEntry(void * arg)
}


const std::string buildDir = "/build";


void DerivationGoal::startBuilder()
{
auto f = format(
Expand Down Expand Up @@ -1725,7 +1722,7 @@ void DerivationGoal::startBuilder()
/* In a sandbox, for determinism, always use the same temporary
directory. */
#if __linux__
tmpDirInSandbox = useChroot ? buildDir : tmpDir;
tmpDirInSandbox = useChroot ? settings.sandboxBuildDir : tmpDir;
#elif __APPLE__
// On Darwin, we canonize /tmp because its probably a symlink to /private/tmp.
tmpDirInSandbox = useChroot ? canonPath("/tmp", true) + "/nix-build-" + drvName + "-0" : tmpDir;
Expand Down Expand Up @@ -1843,7 +1840,7 @@ void DerivationGoal::startBuilder()
"root:x:0:0:Nix build user:%3%:/noshell\n"
"nixbld:x:%1%:%2%:Nix build user:%3%:/noshell\n"
"nobody:x:65534:65534:Nobody:/:/noshell\n",
sandboxUid, sandboxGid, buildDir));
sandboxUid, sandboxGid, settings.sandboxBuildDir));

/* Declare the build user's group so that programs get a consistent
view of the system (e.g., "id -gn"). */
Expand Down
3 changes: 3 additions & 0 deletions src/libstore/globals.hh
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ public:
#if __linux__
Setting<std::string> sandboxShmSize{this, "50%", "sandbox-dev-shm-size",
"The size of /dev/shm in the build sandbox."};

Setting<Path> sandboxBuildDir{this, "/build", "sandbox-build-dir",
"The build directory inside the sandbox."};
#endif

Setting<PathSet> allowedImpureHostPrefixes{this, {}, "allowed-impure-host-deps",
Expand Down
2 changes: 1 addition & 1 deletion src/libstore/machines.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void parseMachines(const std::string & s, Machines & machines)
if (sz < 1)
throw FormatError("bad machine specification ‘%s’", line);

auto isSet = [&](int n) {
auto isSet = [&](size_t n) {
return tokens.size() > n && tokens[n] != "" && tokens[n] != "-";
};

Expand Down
8 changes: 6 additions & 2 deletions tests/build-remote.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ rm -rf $TEST_ROOT/store0 $TEST_ROOT/store1
# FIXME: --option is not passed to build-remote, so have to create a config file.
export NIX_CONF_DIR=$TEST_ROOT/etc2
mkdir -p $NIX_CONF_DIR
echo "build-sandbox-paths = /nix/store" > $NIX_CONF_DIR/nix.conf
echo "
build-sandbox-paths = /nix/store
sandbox-build-dir = /build-tmp
" > $NIX_CONF_DIR/nix.conf

outPath=$(nix-build build-hook.nix --no-out-link -j0 --option builders "local?root=$TEST_ROOT/store0; local?root=$TEST_ROOT/store1 - - 1 1 foo" --option build-sandbox-paths /nix/store)
outPath=$(nix-build build-hook.nix --no-out-link -j0 \
--option builders "local?root=$TEST_ROOT/store0; local?root=$TEST_ROOT/store1 - - 1 1 foo")

cat $outPath/foobar | grep FOOBAR

Expand Down

0 comments on commit bb50c89

Please sign in to comment.