nix icon indicating copy to clipboard operation
nix copied to clipboard

Build of Nix fails with error: home directory '/homeless-shelter' exists

Open noamraph opened this issue 1 year ago • 2 comments

Describe the bug

When building Nix from a single-user installation, the build fails with the error: home directory '/homeless-shelter' exists; please remove it to assure purity of builds without sandboxing

This is probably related to https://github.com/NixOS/nix/issues/8313

Steps To Reproduce

  1. Use WSL2. I used both 22.04 and 24.04 and got this behavior.
  2. Install nix as a single user:
wget https://releases.nixos.org/nix/nix-2.24.2/nix-2.24.2-x86_64-linux.tar.xz
tar -xf nix-2.24.2-x86_64-linux.tar.xz
nix-2.24.2-x86_64-linux/install
. ~/.nix-profile/etc/profile.d/nix.sh
mkdir -p ~/.config/nix
echo 'experimental-features = nix-command flakes' >> ~/.config/nix/nix.conf
  1. Build nix itself:
nix build github:noamraph/nix/no-gc-auto-test

(noamraph/nix/no-gc-auto-test disables the gc-auto test, to overcome https://github.com/NixOS/nix/issues/11284.)

Expected behavior

Build succeeds.

Actual behavior

Build fails with this error:

error: builder for '/nix/store/sir91p2xxiqfjmsxz6a4mgb4ab7nlqi7-nix-2.25.0pre20240812_005d00f.drv' failed with exit code 2;
       last 25 log lines:
       >     ++(/build/source/tests/functional/common/vars-and-functions.sh:342) for arg in "$@"
       >     ++(/build/source/tests/functional/common/vars-and-functions.sh:343) [[ silly != \s\i\l\l\y ]]
       >     ++(/build/source/tests/functional/common/vars-and-functions.sh:379) command grep silly
       >     ++(./user-envs-test-case.sh:34) nix-env -qa '*' --system
       >     ++(./user-envs-test-case.sh:34) grepQuiet x86_64-linux
       >     ++(/build/source/tests/functional/common/vars-and-functions.sh:378) checkGrepArgs x86_64-linux
       >     ++(/build/source/tests/functional/common/vars-and-functions.sh:341) local arg
       >     ++(/build/source/tests/functional/common/vars-and-functions.sh:342) for arg in "$@"
       >     ++(/build/source/tests/functional/common/vars-and-functions.sh:343) [[ x86_64-linux != \x\8\6\_\6\4\-\l\i\n\u\x ]]
       >     ++(/build/source/tests/functional/common/vars-and-functions.sh:379) command grep x86_64-linux
       >     ++(./user-envs-test-case.sh:37) nix-env -i foo-1.0
       >     installing 'foo-1.0'
       >     this derivation will be built:
       >       /build/nix-test/user-envs/store/0askgxjd42ypg9wp2xn7w10g9hv4piw9-foo-1.0.drv
       >     error: home directory '/homeless-shelter' exists; please remove it to assure purity of builds without sandboxing
       >     +++(./user-envs-test-case.sh:37) onError
       >     +++(/build/source/tests/functional/common/vars-and-functions.sh:292) set +x
       >     user-envs.sh: test failed at:
       >       source in ./user-envs-test-case.sh:37
       >       main in user-envs.sh:5
       > make: *** [mk/lib.mk:90: tests/functional/remote-store.sh.test] Error 1
       > make: *** [mk/lib.mk:90: tests/functional/user-envs.sh.test] Error 1
       > ran test tests/functional/experimental-features.sh... [PASS]
       > ran test tests/functional/lang.sh... [PASS]
       > ran test tests/functional/fetchMercurial.sh... [PASS]
       For full logs, run 'nix log /nix/store/sir91p2xxiqfjmsxz6a4mgb4ab7nlqi7-nix-2.25.0pre20240812_005d00f.drv'.

nix-env --version output

nix-env (Nix) 2.24.2

Additional context

When disabling sandbox the build succeeds:

nix --option sandbox false build github:noamraph/nix/no-gc-auto-test

When applying a branch which uses /sys/homeless-shelter instead of /homeless-shelter the build succeeds:

nix --option sandbox false build github:noamraph/nix/homeless-shelter-to-sys
/nix/store/zya5clc153x2ainifgs3gqrz9w3rvqrl-nix-2.25.0pre20240812_afcd0ff/bin/nix build github:noamraph/nix/no-gc-auto-test

Priorities

Add :+1: to issues you find important.

noamraph avatar Aug 14 '24 06:08 noamraph

Why is it that the test fails? Even when disabling the sandbox, you still shouldn't be able to create $HOME, unless you're root, in which case, ...why are you running builds as root?

puckipedia avatar Aug 24 '24 18:08 puckipedia

Hi, I'm not running the build as root. I described the exact steps to reproduce in the issue.

Interestingly, it wasn't reproduced on an Ubuntu 24.04 running on VirtualBox, but I did reproduce it by running the exact steps on a GitHub Actions worker.

noamraph avatar Aug 26 '24 15:08 noamraph

I added another way to reproduce the problem: This PR adds another GitHub Actions builder, which installs Nix with a single-user installation. It fails with this error: https://github.com/NixOS/nix/pull/11397

noamraph avatar Sep 02 '24 08:09 noamraph