Skip to content

Commit 3a3b2fd

Browse files
Mic92edolstra
authored andcommitted
don't include derivation name in temporary build directories
With the migration to /nix/var/nix/builds we now have failing builds when the derivation name is too long. This change removes the derivation name from the temporary build to have a predictable prefix length: Also see: NixOS/infra#764 for context. (cherry picked from commit 725a2f3) (cherry picked from commit 7c3fd50)
1 parent 9f8a904 commit 3a3b2fd

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
synopsis: "Temporary build directories no longer include derivation names"
3+
prs: [13839]
4+
---
5+
6+
Temporary build directories created during derivation builds no longer include the derivation name in their path to avoid build failures when the derivation name is too long. This change ensures predictable prefix lengths for build directories under `/nix/var/nix/builds`.

src/libstore/unix/build/derivation-builder.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ void DerivationBuilderImpl::startBuilder()
717717

718718
/* Create a temporary directory where the build will take
719719
place. */
720-
topTmpDir = createTempDir(buildDir, "nix-build-" + std::string(drvPath.name()), 0700);
720+
topTmpDir = createTempDir(buildDir, "nix", 0700);
721721
setBuildTmpDir();
722722
assert(!tmpDir.empty());
723723

tests/functional/check.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ test_custom_build_dir() {
5252
nix-build check.nix -A failed --argstr checkBuildId "$checkBuildId" \
5353
--no-out-link --keep-failed --option build-dir "$TEST_ROOT/custom-build-dir" 2> "$TEST_ROOT/log" || status=$?
5454
[ "$status" = "100" ]
55-
[[ 1 == "$(count "$customBuildDir/nix-build-"*)" ]]
56-
local buildDir=("$customBuildDir/nix-build-"*)
55+
[[ 1 == "$(count "$customBuildDir/nix-"*)" ]]
56+
local buildDir=("$customBuildDir/nix-"*)
5757
if [[ "${#buildDir[@]}" -ne 1 ]]; then
58-
echo "expected one nix-build-* directory, got: ${buildDir[*]}" >&2
58+
echo "expected one nix-* directory, got: ${buildDir[*]}" >&2
5959
exit 1
6060
fi
6161
if [[ -e ${buildDir[*]}/build ]]; then

tests/nixos/user-sandboxing/default.nix

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ in
104104
105105
# Wait for the build to be ready
106106
# This is OK because it runs as root, so we can access everything
107-
machine.wait_until_succeeds("stat /nix/var/nix/builds/nix-build-open-build-dir.drv-*/build/syncPoint")
108-
dir = machine.succeed("ls -d /nix/var/nix/builds/nix-build-open-build-dir.drv-*").strip()
107+
machine.wait_until_succeeds("stat /nix/var/nix/builds/nix-*/build/syncPoint")
108+
dir = machine.succeed("ls -d /nix/var/nix/builds/nix-*").strip()
109109
110110
# But Alice shouldn't be able to access the build directory
111111
machine.fail(f"su alice -c 'ls {dir}/build'")
@@ -125,8 +125,8 @@ in
125125
args = [ (builtins.storePath "${create-hello-world}") ];
126126
}' >&2 &
127127
""".strip())
128-
machine.wait_until_succeeds("stat /nix/var/nix/builds/nix-build-innocent.drv-*/build/syncPoint")
129-
dir = machine.succeed("ls -d /nix/var/nix/builds/nix-build-innocent.drv-*").strip()
128+
machine.wait_until_succeeds("stat /nix/var/nix/builds/nix-*/build/syncPoint")
129+
dir = machine.succeed("ls -d /nix/var/nix/builds/nix-*").strip()
130130
131131
# The build ran as `nixbld1` (which is the only build user on the
132132
# machine), but a process running as `nixbld1` outside the sandbox

0 commit comments

Comments
 (0)