Summary, see original post below
Proposal: move /nix
to:
-
/opt/nix
: store directory -
/var/lib/nix/{profiles/, gc.lock, ...}
: everything that now lives under/nix/var/nix
-
/var/log/nix
: Nix log files
Benefit | |
---|---|
works with macOS | Unlocks large user base |
matches FHS | Allows easier installation on existing systems |
Easier to get buy-in from administrators | |
Shorter store path | 6 less characters per referenced path probably adds up to a savings of a few KB in the store |
Problem | Solutions |
---|---|
Extra work, no benefit on current installs | Making installation easier on other systems grows the ecosystem, which benefits Nix |
Requires rebuilding all | This regularly happens anyway |
Historical packages only available via /nix
|
They can be recompiled or patched, and /nix still works for a parallel or shared install |
Hardcoded /nix in places | Fix the broken code |
Needs 2 Hydra builds | Bind-mount the store, register both groups of packages. Since the prefix is part of the input hash, there should be no clashes, and invariant packages will be shared, invariant files hardlinked |
How to migrate | Write tool to do the migration, everything else remains the same |
clang resolves symlinks, causing impurity
|
Make sure the store is on a non-symlinked path |
/var is a symlink on macOS |
Use /opt instead |
/opt on Fedora Silverblue is immutable, and /usr/local is a symlink |
The userbase is currently much smaller and there are likely a number of mitigations possible |
/nix is used all over the documentation |
Letās update the documentation, use e.g. $NIX_ROOT , or, since this proposal removes the single root, $NIX_STORE
|
Original post
Up till now, having the Nix store and metadata live at /nix
was a mild inconvenience, and maybe a cute quirk.
However, macOS has been clamping down on writing to /, and I have to wonder if all the trouble is worth it. Why not move /nix
to a Filesystem Hierarchy Standard location, that will be more likely to be available?
I can think of these locations:
-
/var/nix
: /var is for Variable data, and the Nix store is surely variable, any user with access to nix-shell can cause additions in there. -
/var/lib/nix
: /var/lib is for database storage, and the Nix store is database if you squint -
/opt/nix
: /opt is for Optional installs, and except on NixOS, thatās the case -
/usr/local/nix
: /usr/local is for Local User installs, pretty apt for single-user nix installs
My favorite among these is /var/nix
, about all systems have a /var
, and itās totally ok to have an extra directory in there. Itās nicely out of the way and doesnāt disturb anyone. /var/lib/nix
is truly conformant to FHS but a little more hidden.
/opt and /usr/local are not as likely to be existing on all systems.
While weāre at it, it would be nice to flatten the /nix/var/nix
tree. Just have its children directly under nix/
, wherever it is, and preferably symlink the log to /var/log/nix
if possible.
To migrate to the new location, we can treat it as a new Nix installation, and either install the same packages, or rewrite store references in the existing ones (cutting some characters from their store path) so they run from the new location. Where possible, you can even bind-mount a single dir on both locations during a transition period, so unchanged files can be hardlinked together.