mirror of
https://github.com/NixOS/nix
synced 2025-06-29 14:53:16 +02:00
Merge pull request #10312 from hercules-ci/add-build-dir
Add build-dir setting
This commit is contained in:
commit
6c10cc0eda
4 changed files with 47 additions and 7 deletions
|
@ -488,7 +488,7 @@ void LocalDerivationGoal::startBuilder()
|
||||||
|
|
||||||
/* Create a temporary directory where the build will take
|
/* Create a temporary directory where the build will take
|
||||||
place. */
|
place. */
|
||||||
tmpDir = createTempDir("", "nix-build-" + std::string(drvPath.name()), false, false, 0700);
|
tmpDir = createTempDir(settings.buildDir.get().value_or(""), "nix-build-" + std::string(drvPath.name()), false, false, 0700);
|
||||||
|
|
||||||
chownToBuilder(tmpDir);
|
chownToBuilder(tmpDir);
|
||||||
|
|
||||||
|
@ -2089,7 +2089,7 @@ void LocalDerivationGoal::runChild()
|
||||||
bool allowLocalNetworking = parsedDrv->getBoolAttr("__darwinAllowLocalNetworking");
|
bool allowLocalNetworking = parsedDrv->getBoolAttr("__darwinAllowLocalNetworking");
|
||||||
|
|
||||||
/* The tmpDir in scope points at the temporary build directory for our derivation. Some packages try different mechanisms
|
/* The tmpDir in scope points at the temporary build directory for our derivation. Some packages try different mechanisms
|
||||||
to find temporary directories, so we want to open up a broader place for them to dump their files, if needed. */
|
to find temporary directories, so we want to open up a broader place for them to put their files, if needed. */
|
||||||
Path globalTmpDir = canonPath(defaultTempDir(), true);
|
Path globalTmpDir = canonPath(defaultTempDir(), true);
|
||||||
|
|
||||||
/* They don't like trailing slashes on subpath directives */
|
/* They don't like trailing slashes on subpath directives */
|
||||||
|
|
|
@ -687,16 +687,36 @@ public:
|
||||||
Setting<std::string> sandboxShmSize{
|
Setting<std::string> sandboxShmSize{
|
||||||
this, "50%", "sandbox-dev-shm-size",
|
this, "50%", "sandbox-dev-shm-size",
|
||||||
R"(
|
R"(
|
||||||
This option determines the maximum size of the `tmpfs` filesystem
|
*Linux only*
|
||||||
mounted on `/dev/shm` in Linux sandboxes. For the format, see the
|
|
||||||
description of the `size` option of `tmpfs` in mount(8). The default
|
This option determines the maximum size of the `tmpfs` filesystem
|
||||||
is `50%`.
|
mounted on `/dev/shm` in Linux sandboxes. For the format, see the
|
||||||
|
description of the `size` option of `tmpfs` in mount(8). The default
|
||||||
|
is `50%`.
|
||||||
)"};
|
)"};
|
||||||
|
|
||||||
Setting<Path> sandboxBuildDir{this, "/build", "sandbox-build-dir",
|
Setting<Path> sandboxBuildDir{this, "/build", "sandbox-build-dir",
|
||||||
"The build directory inside the sandbox."};
|
R"(
|
||||||
|
*Linux only*
|
||||||
|
|
||||||
|
The build directory inside the sandbox.
|
||||||
|
|
||||||
|
This directory is backed by [`build-dir`](#conf-build-dir) on the host.
|
||||||
|
)"};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Setting<std::optional<Path>> buildDir{this, std::nullopt, "build-dir",
|
||||||
|
R"(
|
||||||
|
The directory on the host, in which derivations' temporary build directories are created.
|
||||||
|
|
||||||
|
If not set, Nix will use the system temporary directory indicated by the `TMPDIR` environment variable.
|
||||||
|
Note that builds are often performed by the Nix daemon, so its `TMPDIR` is used, and not that of the Nix command line interface.
|
||||||
|
|
||||||
|
This is also the location where [`--keep-failed`](@docroot@/command-ref/opt-common.md#opt-keep-failed) leaves its files.
|
||||||
|
|
||||||
|
If Nix runs without sandbox, or if the platform does not support sandboxing with bind mounts (e.g. macOS), then the [`builder`](@docroot@/language/derivations.md#attr-builder)'s environment will contain this directory, instead of the virtual location [`sandbox-build-dir`](#conf-sandbox-build-dir).
|
||||||
|
)"};
|
||||||
|
|
||||||
Setting<PathSet> allowedImpureHostPrefixes{this, {}, "allowed-impure-host-deps",
|
Setting<PathSet> allowedImpureHostPrefixes{this, {}, "allowed-impure-host-deps",
|
||||||
"Which prefixes to allow derivations to ask for access to (primarily for Darwin)."};
|
"Which prefixes to allow derivations to ask for access to (primarily for Darwin)."};
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,21 @@ nix-build check.nix -A failed --argstr checkBuildId $checkBuildId \
|
||||||
[ "$status" = "100" ]
|
[ "$status" = "100" ]
|
||||||
if checkBuildTempDirRemoved $TEST_ROOT/log; then false; fi
|
if checkBuildTempDirRemoved $TEST_ROOT/log; then false; fi
|
||||||
|
|
||||||
|
test_custom_build_dir() {
|
||||||
|
local customBuildDir="$TEST_ROOT/custom-build-dir"
|
||||||
|
|
||||||
|
# Nix does not create the parent directories, and perhaps it shouldn't try to
|
||||||
|
# decide the permissions of build-dir.
|
||||||
|
mkdir "$customBuildDir"
|
||||||
|
nix-build check.nix -A failed --argstr checkBuildId $checkBuildId \
|
||||||
|
--no-out-link --keep-failed --option build-dir "$TEST_ROOT/custom-build-dir" 2> $TEST_ROOT/log || status=$?
|
||||||
|
[ "$status" = "100" ]
|
||||||
|
[[ 1 == "$(count "$customBuildDir/nix-build-"*)" ]]
|
||||||
|
local buildDir="$customBuildDir/nix-build-"*
|
||||||
|
grep $checkBuildId $buildDir/checkBuildId
|
||||||
|
}
|
||||||
|
test_custom_build_dir
|
||||||
|
|
||||||
nix-build check.nix -A deterministic --argstr checkBuildId $checkBuildId \
|
nix-build check.nix -A deterministic --argstr checkBuildId $checkBuildId \
|
||||||
--no-out-link 2> $TEST_ROOT/log
|
--no-out-link 2> $TEST_ROOT/log
|
||||||
checkBuildTempDirRemoved $TEST_ROOT/log
|
checkBuildTempDirRemoved $TEST_ROOT/log
|
||||||
|
|
|
@ -283,6 +283,11 @@ grepQuietInverse() {
|
||||||
! grep "$@" > /dev/null
|
! grep "$@" > /dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Return the number of arguments
|
||||||
|
count() {
|
||||||
|
echo $#
|
||||||
|
}
|
||||||
|
|
||||||
trap onError ERR
|
trap onError ERR
|
||||||
|
|
||||||
fi # COMMON_VARS_AND_FUNCTIONS_SH_SOURCED
|
fi # COMMON_VARS_AND_FUNCTIONS_SH_SOURCED
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue