Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support overlay/union-mounted stores #2764

Open
catern opened this issue Apr 13, 2019 · 13 comments
Open

Support overlay/union-mounted stores #2764

catern opened this issue Apr 13, 2019 · 13 comments
Labels
feature Feature request or proposal store Issues and pull requests concerning the Nix store

Comments

@catern
Copy link
Contributor

catern commented Apr 13, 2019

There are three motivating ideas:

  • Private stores in a home directory would be much more efficient if they could share artifacts by being union-mounted on top of the system-wide store. If private stores became much more efficient, they could be truly viable as a way to solve the secrets problem: with a union mount, a private store created for secrets would need only hold the actual secrets and top-level composition, making them vastly smaller than the current situation.

  • Likewise, more efficient private stores would allow individual users more flexibility when prototyping. Many of my users want to build things impurely while they are prototyping. This is impractical at the moment since they would need to copy all their dependencies into a private store, but if they could efficiently create private stores, that would open up new kinds of experimentation. Similarly, it would allow users to more flexibly trust new binary caches that aren't trusted system wide, copy unsigned artifacts around without being trusted users, etc.

  • Sharing a single store between hosts by mounting it with NFS and managing it with the daemon could improve performance in some scenarios, but has unclear correctness and could worsen performance in other scenarios. If a host-local daemon-managed store was union-mounted on top of a shared NFS store, that would resolve many of the issues, and return the desirable ability to install packages on only one host instead of everywhere.

Concretely, a "union store" would be a new LocalFSStore class, which maintains the store invariants only if the following three conditions hold:

  1. It is in contact with a "backend store", which is another LocalFSStore.
  2. The union store's store directory is union-mounted on top of the backend store's store directory.
  3. The backend store maintains the store invariants.

The implementation would likely share much with that of LocalStore, and it would always be able to fall back on doing exactly what LocalStore does.

But a union store would have an additional capability over LocalStore: Whenever it needs some store path, it could call out to the backend store to see if the store path is already present. It could even forward builds to the backend store based on some criteria, though we'd need to take care that secrets aren't uploaded. It might be simple enough to say that a union store will never call addToStore or similar calls on the backend store, though that might be undesirable for some use cases.

In any case, if a needed store path is present in the backend store, the union store would:

  1. Create a new GC root in the backend store for that path, so that the backend store does not delete store paths relied upon by the union store.
  2. Record the path as valid and provided by the backend store.

Store paths in the union store would then have dependencies on store paths provided by the backend store.

If the union store later, during garbage collection, wants to delete a path provided by the backend store, then it simply removes the GC root it created in the backend store for the path.

This is a very skeletal sketch, although I've been thinking about this for a while. The key realization that I had recently is that the same new concept would allow all three of the motivating ideas I mentioned above, which makes me more convinced that this would be a powerful and useful feature. Thoughts?

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/multi-user-secure-nix-store-user-quotas/7803/2

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/how-to-build-a-nixos-vm-with-nix-in-which-nixos-rebuild-is-a-no-op/7937/3

@anka-213
Copy link

Would this cause problems with the store not residing in /nix anymore, so much of binary caching would be broken? Or is there some good workaround for that?

@lheckemann
Copy link
Member

Mounting an overlay filesystem to /nix/store should do the trick.

@stale
Copy link

stale bot commented Mar 19, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the stale label Mar 19, 2021
@queezle42
Copy link

Not stale, right now it's not possible to share builders securely, this would really help.

@stale stale bot removed the stale label Apr 6, 2021
@stale
Copy link

stale bot commented Oct 11, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the stale label Oct 11, 2021
@queezle42
Copy link

Not stale (for the same reason)

@stale stale bot removed the stale label Oct 25, 2021
@bew
Copy link
Contributor

bew commented Oct 26, 2021

I love this and was wondering about something similar recently as well! 🙃
When you say "talk to the backend store", are you implying "the the system nix-daemon that manages the system store" ?
Or something else?

@stale
Copy link

stale bot commented Apr 27, 2022

I marked this as stale due to inactivity. → More info

@stale stale bot added the stale label Apr 27, 2022
@rhendric
Copy link
Member

Not stale. I'm very interested in something along these lines.

@pogobanane
Copy link
Member

pogobanane commented Apr 26, 2023

Mounting an overlay filesystem to /nix/store should do the trick.

This is only partially true.

For me the following workaround approximates this proposal: Mount host1 store readonly on host2 and set up an overlayFS to make the host1 store writeable on host2. This makes files available, but the database of host2 still needs updating to work well with flakes/nix-command:

# --dump-db or --export
@host1> nix-store --dump-db > host-db
# make host-db available on host2: --load-db (faster) or --import (slower). This command can take several minutes :(
@host2> nix-store --load-db < host-db

The NixOS options virtualisation.writableStore and virtualisation.pathsInNixDB do basically that. However it is quite slow in my case when sharing the entire (somewhat big) nix store from host1.

@stale stale bot removed the stale label Apr 26, 2023
@lheckemann
Copy link
Member

Right, I got that wrong: I think as long as the host store doesn't change, you can overlay-mount the whole of /nix, including the database. That would avoid a lengthy import step.

@roberth roberth added feature Feature request or proposal store Issues and pull requests concerning the Nix store labels Jun 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature request or proposal store Issues and pull requests concerning the Nix store
Projects
None yet
Development

No branches or pull requests

9 participants