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?
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').
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
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.
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
.nix run --store /path/to/store
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With