Custom installation of nix unset NIX_BUILD_TOP?

Hi all,

I have a custom installation of nix in a non standard directory, long story short I configured the installation as so:

./configure \
        --enable-gc \
        --with-store-dir="/cvmfs/" \

After that I compiled and installed nix with make, and everything went fine.

Them, I added the stable channel using nix-channel --add $THE_URL and then I tried to install something.

nix-env -i gcc

It get stuck with an error like: /build/$somethign is not a directory.

The solution to the problem was to create the directory /build the next problem was indeed not enough permission on /build (correct, I created the directory as root, while I am building as user ubuntu). I change the ownership of the directory to ubuntu and now it is happily compiling.

I believe the problem is that the environment variable NIX_BUILD_TOP is empty during the build process. I tried to lookup into the code, but that variable seems to be set in a quite straightforward way.

How can I fix the problem? I would like nix to build somewhere else than the directory /build I create for it.

NIX_BUILD_TOP is set by Nix before it forks off the builder. Nix derives this directory sandbox-build-dir in nix.conf, which defaults to /build. Dunno if the default can be set at build time, but you can set it in /etc/nix/nix.conf or ~/.config/nix/nix.conf.

Note that by using a custom store dir, you will not be able to get binaries from the binary cache, and will build everything from source. You can get around this by setting store = /path/to/store in nix.conf instead of doing what you’re doing, which instead uses chroot to emulate /nix/store in a user owned directory. But this requires user namespaces to do it without root, which I’m guessing your distro doesn’t enable (otherwise I think it’d be able to set up /build via the chroot it would make for the build sandbox, even without store).

1 Like

I am already doing something a little too fancy, so chroot is out of the question for now. I am fine with building everything from scratch :slight_smile:

I believe that the installation from source of nix does not install any of the shell scripts and configurations file needed to actually use the package manager.

Should I report it somewhere? How do I install all the necessary configuration scripts?

No it does. It installs it at /usr/local/etc/profile.d/, at least.

Hummmm, I changed the prefix, but yes, eventually I found the file.

However, trying to source that file gives problems like:

$ source /cvmfs/ 
bash: stat: command not found
bash: id: command not found
bash: stat: command not found
bash: id: command not found

I installed nix using this script:

This is when I’d pull out strace :stuck_out_tongue:

Looks like replaces PATH with PATH=/bin within its setup, for some reason, and Ubuntu only puts those binaries in /usr/bin for some reason.

1 Like

Looks like it just guesses where all coreutils will be by checking where cat first appears on PATH:

So maybe --with-coreutils-bin=/usr/bin might fix it…

EDIT: Nope. Some of coreutils is only in /bin, and some is only in /usr/bin… EDIT2: Could install busybox somewhere to use instead.


1 Like

Thank you very much!