Reputation: 4427
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?
Upvotes: 11
Views: 11622
Reputation: 304
Building Nix from source while specifying --with-store-dir=path
Note that this would only define the store folder (/nix/store
) to another location but not the whole /nix
folder.
The documentation also says:
Warning: It is best not to change the Nix store from its default, since doing so makes it impossible to use pre-built binaries from the standard Nixpkgs channels — that is, all packages will need to be built from source.
ref: https://nix.dev/manual/nix/2.22/installation/building-source
Upvotes: 3
Reputation: 137
This is by now a very old discussion, but I think the question is still looking for a satisfactory answer.
I think what you want is nix-portable
.
See here for details: https://github.com/DavHau/nix-portable
My understanding is that nix is not really designed to be installed into a custom location. Someone over there on that link has done the nontrivial legwork to make it work, however. I tried and it worked out of the box.
The downside in general is that it does not work on macs, but it worked fine for me on Linux.
Upvotes: 0
Reputation: 8016
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
.Upvotes: 6
Reputation: 193
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.
Upvotes: 8
Reputation: 111
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').
Upvotes: 11
Reputation: 4276
Yes, but you won't be able to use the binary packages (everything will be compiled from scratch). To bootstrap, see https://nixos.org/wiki/How_to_install_nix_in_home_%28on_another_distribution%29
A better idea might be to make /nix be a symlink to a directory on your external drive. Have you considered this? As @jarandaf mentions below, /nix
cannot be a symlink.
Upvotes: 1