Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can nix be installed in a different location other than /nix?

Tags:

nix

After some time, I am starting to run out of disk space in my development machine (only 128GB). For this reason, I have decided to move local cache stores (.npm, .m2, .ivy2, etc.) to an external drive.

I switched recently to Nix for Haskell development after experiencing the well known "cabal hell". I haven't found a proper way to change the Nix store location, though.

Is it possible?

like image 356
jarandaf Avatar asked Mar 24 '15 15:03

jarandaf


3 Answers

After a little bit of github archaeology, I found nixos commit f8cd904:

https://github.com/NixOS/nix/commit/f8cd904e05b95c5a3ca7cf570c0503a25a2095ca

This works around a behavior (bug?) in gcc 3.3.3. The same commit message recommends working around the issue with bind mounts:

On Linux, bind mounts can be used instead of symlink for this purpose (e.g., `mount -o bind /data/nix/store /nix/store').

like image 78
Nick Avatar answered Sep 24 '22 07:09

Nick


In case someone is still searching for this question: the Nix manual explains that you can use the symlink at your own risk (possible failure building from source) https://nixos.org/nix/manual/#sec-common-env It is enough to set the following environment variable

export NIX_IGNORE_SYMLINK_STORE=1

edit:

tl,dr;

setting this environment variable will let you use a symlink to /nix; this may be convenient if

  • you don't want to mount something on your root directory
  • you still want to use precompiled pakages

be warned: this is not portable

details:

from the documentation

Normally, the Nix store directory (typically /nix/store) is not allowed to contain any symlink components. This is to prevent “impure” builds. Builders sometimes “canonicalise” paths by resolving all symlink components. Thus, builds on different machines (with /nix/store resolving to different locations) could yield different results. This is generally not a problem, except when builds are deployed to machines where /nix/store resolves differently. If you are sure that you’re not going to do that, you can set NIX_IGNORE_SYMLINK_STORE to 1.

So it is mostly a decision related to how some makefile work. If you don't plan to port your configuration elsewhere, it just works.

like image 33
marco Avatar answered Sep 25 '22 07:09

marco


As of Nix 2.0 there are three options that allow a user to use an alternative nix store, all three of which I assume use user namespaces:

https://nixos.wiki/wiki/Nix_Installation_Guide#Installing_without_root_permissions

  • nix-user-chroot creates an environment with a relocated /nix.
  • proot creates a user-managed chroot-like.
  • If you have Nix installed, a user can choose to use an alternative store with nix run --store /path/to/store.
like image 20
clacke Avatar answered Sep 21 '22 07:09

clacke