4 ms·
I think he may be referring to installing Nix itself, which does require root even if the intention isn't to install anything system-wide. I did once think abou
by raunakchhatwal 3y ago
I think he may be referring to installing Nix itself, which does require root even if the intention isn't to install anything system-wide. I did once think about modifying the nix installer to let me set an arbitrary nix store because I wanted nix packages in a docker container I was debugging, but never really got around to it. Let me know if you know of somebody else who tried this.
- iFreilicht 3y agoSo this is possible, but there are a lot of caveats. First, the installer itself explicitly says: ``` # Please don't change this. We don't support it, because the # default shell profile that comes with Nix doesn't support it. readonly NIX_ROOT="/nix" ``` I haven't seen any configurations where the entire /nix is relocated, but nix _does_ support relocating the store with the environment variable `NIX_STORE_DIR`.[1] However, this means that you can no longer use the the binary cache and *everything* you install has to be compiled from scratch, including glibc. The reason is that nix usually patches paths like `/bin/myprogram` to `/nix/store/1238f...-myprogram-1.2.3/bin/myprogram` in everything that depends on `myprogram` during build time to isolate the build outputs from the system. If you change your store, all those paths will now be invalid, including the hash part. So using a nix store that isn't `/nix/store` is possible, but I don't think anyone is actually doing it except in a few select scenarios. You can also compile nix itself with a different root. That will work as expected, but you still have the issue that you need to compile everything you install yourself. [1]: https://nixos.org/manual/nix/stable/command-ref/env-common.html?highlight=NIX_STORE#env-NIX_STORE_DIR https://nixos.org/manual/nix/stable/command-ref/env-common.h... (you can also relocate most other directories. The `prefix` in the paths is `/nix`)
- bshacklett 3y agoNow that's interesting. I use Homebrew in a similar way. It does mean I have to compile a lot of things from scratch, but Homebrew has knowledge of which packages are relocatable and which aren't, so I get to use binary "bottles" for about 25% of the packages I install. I'll have to give this a try.