Idea for very minimally changing Nix & cache.nixos.org to allow custom store paths without rebuilding the world

/nix/store requires root to create on many Linux systems, requiring Nix users to contact their sysadmin in order to locally use Nix. /nix/store’s location also makes installation very difficult on macOS Catalina.

I propose, in the global nixpkgs cache, building packages with a path like /nix/store/././././././././. Systems using a custom Nix store path, if short enough, could simply replace that longer aforementioned path in downloaded binaries, allowing users to take advantage of the global Nix cache while using a custom location for the local nix store. Credits for inspiration.

This is definitely hacky, and it would place restrictions on local nix store locations before caching stops working. Maybe symlinks could help here (e.g. symlink some hidden filder with a special path length to the user’s custom store location).

I thought I’d post the idea here in case it’s worth something.

Cheers!

2 Likes

It’s not really needed - the hash is long enough that you can cut some letters off. So for example, if your Nix store should be under /home/aaronj/.n/, you can just snip the first 4 characters off the hash and rewrite all store references for downloaded packages. The likelyhood of a name collision in your store is basically 0.

1 Like

Ooooooohhh. That’s really cool! Do you think Nix would add a utility to do this?

More here: Rootless Nix: Path Rewriting (would like to contribute) · Issue #1971 · NixOS/nix · GitHub

1 Like