# Super Colliding Nix Stores

**URL:** https://discourse.nixos.org/t/super-colliding-nix-stores/28462
**Category:** Announcements
**Created:** [May 25, 2023, 6:17pm UTC](https://discourse.nixos.org/t/super-colliding-nix-stores/28462 "2023-05-25T18:17:26Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![ryantm](https://discourse.nixos.org/user_avatar/discourse.nixos.org/ryantm/32/900_2.png) [@ryantm](https://discourse.nixos.org/u/ryantm)
#### Post date: [May 25, 2023, 6:17pm UTC](https://discourse.nixos.org/t/super-colliding-nix-stores/28462/1 "2023-05-25T18:17:26Z")

</div>

[Replit](https://replit.com/) has teamed up with [Obsidian Systems](https://obsidian.systems/) (@Ericson2314) and [Tweag](https://www.tweag.io/) (@thufschmitt, @ben) to add a Local Overlay Store to Nix that allows merging of multiple (possibly remote) stores.

You can read more about the motivation and details for this project on our blog:

> **[Replit — Super Colliding Nix Stores: Nix Flakes for Millions of Developers](https://blog.replit.com/super-colliding-nix-stores)**
>
> We’ve teamed up with Obsidian Systems and Tweag to enable Nix to merge multiple (possibly-remote) Nix stores, bringing Nix Flakes and development environment portability to millions of Replit users.
> 
> Nix is an open-source cross-platform package...

In the coming weeks, we will be developing these new features, releasing a Nix RFC, and working to upstream it into Nix.

Reply here if you have ideas for how this kind of Store could help you out. We’re interested to learn about more use cases to make it as general as possible.

Ultimately, we’re trying to make all the features of Nix work inside Replit Repls and this will go a long way.

Replit is also hiring for a lot of roles. If you live in North America and want to help bring Nix to millions of developers please reach out to me (@ryantm) and [apply](https://replit.com/site/careers).

---

<div class="post-metadata">

### Author: ![bbigras](https://discourse.nixos.org/user_avatar/discourse.nixos.org/bbigras/32/56_2.png) [@bbigras](https://discourse.nixos.org/u/bbigras)
#### Post date: [May 25, 2023, 6:33pm UTC](https://discourse.nixos.org/t/super-colliding-nix-stores/28462/2 "2023-05-25T18:33:18Z")

</div>

I think this could help in CI when you build using docker images. The overlay could be used as a cache for everything that isn’t in the docker image’s nix store.

---

<div class="post-metadata">

### Author: ![flurie](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/f/f07891/32.png) [@flurie](https://discourse.nixos.org/u/flurie)
#### Post date: [May 26, 2023, 3:35am UTC](https://discourse.nixos.org/t/super-colliding-nix-stores/28462/3 "2023-05-26T03:35:47Z")

</div>

This could help solve remote building in Bazel with Nix-derived tools and toolchains.

---

<div class="post-metadata">

### Author: ![FRidh](https://discourse.nixos.org/user_avatar/discourse.nixos.org/fridh/32/7643_2.png) [@FRidh](https://discourse.nixos.org/u/FRidh)
#### Post date: [May 27, 2023, 9:17am UTC](https://discourse.nixos.org/t/super-colliding-nix-stores/28462/4 "2023-05-27T09:17:29Z")

</div>

I was thinking of having one store as a “datalake”, and then exposing stores on top that workers use. The workers have the shared datalake mounted via say nfs. Similar to what has been discussed in the article.

---

<div class="post-metadata">

### Author: ![rickynils](https://discourse.nixos.org/user_avatar/discourse.nixos.org/rickynils/32/498_2.png) [@rickynils](https://discourse.nixos.org/u/rickynils)
#### Post date: [May 27, 2023, 12:35pm UTC](https://discourse.nixos.org/t/super-colliding-nix-stores/28462/5 "2023-05-27T12:35:57Z")

</div>

The “datalake” approach is what [nixbuild.net](http://nixbuild.net) takes, and it works really nicely. We have all nar files available in a central storage location, and then use a fuse-based filesystem to mount specific nar files for each build. We are also thinking about making a fuse-based client for our users that would let them mount their part (or a subset of it) of our “datalake” locally.

---

<div class="post-metadata">

### Author: ![Solene](https://discourse.nixos.org/user_avatar/discourse.nixos.org/solene/32/5738_2.png) [@Solene](https://discourse.nixos.org/u/Solene)
#### Post date: [May 30, 2023, 9:05am UTC](https://discourse.nixos.org/t/super-colliding-nix-stores/28462/6 "2023-05-30T09:05:25Z")

</div>

This could be useful to use Nix in a Qubes OS template where the template provides /nix, and allow a Qube (template derived system where only /home is persistent or specific directories) to have a persistent overlay on top of the /nix template

> **[Templates](https://www.qubes-os.org/doc/templates/)**
>
> In Getting Started, we covered the distinction in Qubes OS between where you install your software and where you run your software. Your software is installed in templates. Each template shares its root filesystem (i.e., all of its programs and...

---

<div class="post-metadata">

### Author: ![arianvp](https://discourse.nixos.org/user_avatar/discourse.nixos.org/arianvp/32/602_2.png) [@arianvp](https://discourse.nixos.org/u/arianvp)
#### Post date: [May 30, 2023, 10:03am UTC](https://discourse.nixos.org/t/super-colliding-nix-stores/28462/7 "2023-05-30T10:03:10Z")

</div>

hmm. Do we really need to change Nix to detect overlays and do a read-through on the nix store database? OverlayFS works fine with `nix-store --load-db` and is a pattern that is used all over the place.

What’s wrong with just doing `nix-store --load-db < /nix/.resgistration-paths` at startup to register all the paths that are in the base layer as we do today with our ISOs?

Anyhow. Interested in the RFC to understand more.

---

<div class="post-metadata">

### Author: ![qyliss](https://discourse.nixos.org/user_avatar/discourse.nixos.org/qyliss/32/34285_2.png) [@qyliss](https://discourse.nixos.org/u/qyliss)
#### Post date: [May 30, 2023, 11:00am UTC](https://discourse.nixos.org/t/super-colliding-nix-stores/28462/8 "2023-05-30T11:00:26Z")

</div>

> [@arianvp](#):
>
> OverlayFS works fine with `nix-store --load-db` and is a pattern that is used all over the place.

In my experience, you get lots of build failures if you try to actually build packages on overlayfs. I’ve heard recently overlayfs has some mode that’s supposed to make it behave more like a normal filesystem, though — I don’t know whether I was using that or not when I tried out Nix-on-overlayfs.

---

<div class="post-metadata">

### Author: ![olebedev](https://discourse.nixos.org/user_avatar/discourse.nixos.org/olebedev/32/4805_2.png) [@olebedev](https://discourse.nixos.org/u/olebedev)
#### Post date: [June 1, 2023, 11:55pm UTC](https://discourse.nixos.org/t/super-colliding-nix-stores/28462/9 "2023-06-01T23:55:51Z")

</div>

> But that was just the beginning, we want to give you more power to configure Repls how you would like and to increase Repl portability with other platforms. We want to give you access to an even larger collection of Nix packages: ones that were published years ago, and the latest ones published today. We also want you to be able to use [Nix Flakes](https://zero-to-nix.com/concepts/flakes) on Replit: it shouldn’t require extra work to configure development environments on every platform. Write a Nix Flake once and have the same reproducible environment everywhere.
> 
> To achieve this, we’re going to need a way to merge Nix stores!

I am pretty sure I miss something here, sorry if it’s obvious! What is the main difference in the use cases between the overlay fs and Nix binary cache here, is this because of they don’t invoke Nix for setting up dev environments at all?

---

<div class="post-metadata">

### Author: ![ryantm](https://discourse.nixos.org/user_avatar/discourse.nixos.org/ryantm/32/900_2.png) [@ryantm](https://discourse.nixos.org/u/ryantm)
#### Post date: [June 2, 2023, 11:40am UTC](https://discourse.nixos.org/t/super-colliding-nix-stores/28462/10 "2023-06-02T11:40:17Z")

</div>

> [@olebedev](#):
>
> What is the main difference in the use cases between the overlay fs and Nix binary cache here

When you use a binary cache, the build products have to be moved to your filesystem which can take time to move and use up disk space.

---

<div class="post-metadata">

### Author: ![veprbl](https://discourse.nixos.org/user_avatar/discourse.nixos.org/veprbl/32/5023_2.png) [@veprbl](https://discourse.nixos.org/u/veprbl)
#### Post date: [June 5, 2023, 5:46pm UTC](https://discourse.nixos.org/t/super-colliding-nix-stores/28462/11 "2023-06-05T17:46:22Z")

</div>

It may be that overlay stores can help with a use case described in [storePath as a settable property of derivation · Issue #5067 · NixOS/nix · GitHub](https://github.com/NixOS/nix/issues/5067)

---

<div class="post-metadata">

### Author: ![rhendric](https://discourse.nixos.org/user_avatar/discourse.nixos.org/rhendric/32/5699_2.png) [@rhendric](https://discourse.nixos.org/u/rhendric)
#### Post date: [June 5, 2023, 6:31pm UTC](https://discourse.nixos.org/t/super-colliding-nix-stores/28462/12 "2023-06-05T18:31:47Z")

</div>

I’ve wanted to be able to segregate a Nix store into a ‘system’ part and a ‘personal’ part, with the idea that the system store contains off-the-shelf software that wouldn’t need to be particularly protected if my computer were stolen, and the personal store contains software that is a privacy risk, IP that I’m obligated to secure, etc.; but where any paths already in the system store could be used by the personal store as needed. If I could do that by making a personal local overlay store over the system store, that would be pretty great, particularly if the stores could be handled differently in the following ways:

| | System | Personal |
| --- | --- | --- |
| Readability | world-readable | user-readable |
| Filesystem | boring and fast | encrypted (with the rest of /home?) |
| Garbage collection | system-defined schedule | different user-defined schedule |
| `keep-outputs` | no | yes |

---

<div class="post-metadata">

### Author: ![zhaofengli](https://discourse.nixos.org/user_avatar/discourse.nixos.org/zhaofengli/32/3481_2.png) [@zhaofengli](https://discourse.nixos.org/u/zhaofengli)
#### Post date: [June 6, 2023, 8:36pm UTC](https://discourse.nixos.org/t/super-colliding-nix-stores/28462/13 "2023-06-06T20:36:22Z")

</div>

That looks amazing! I have one question: Will your Layered Store support be tied to specific semantics (“upper Nix” having access to entire lower store DB and can instantly substitute) or will it be pluggable? I’m thinking of the following problems:

- It may not be feasible to expose the entire lower store as a Nix-compatible SQLIte database. The lower store may be large, dynamic, and even have multi-tenant awareness (e.g., [Attic](https://discourse.nixos.org/t/introducing-attic-a-self-hostable-nix-binary-cache-server/24343) and nixbuild’s datalake [mentioned earlier](https://discourse.nixos.org/t/super-colliding-nix-stores/28462/5)).
- Future isolation mechanisms (VMs) and complex setups the may necessitate other zero-copy substitution mechanisms (e.g., virtiofs, NFS, host-initiated bind mount, etc.) that are specific to each provider.

I thought about the general problem earlier, and came up with a different idea that minimizes the awareness of the “upper Nix” regarding the substitution mechanism: [Substitution Agents · GitHub](https://gist.github.com/zhaofengli/258d0bfef873af92d7587ad87b58b3b1)

All Nix knows is that the substitution agent will somehow make the store path appear. It might run as a service inside the VM and perform virtiofs mounts, or it can be in a sidecar container and can mount new paths into the CI container’s store.

---

<div class="post-metadata">

### Author: ![olebedev](https://discourse.nixos.org/user_avatar/discourse.nixos.org/olebedev/32/4805_2.png) [@olebedev](https://discourse.nixos.org/u/olebedev)
#### Post date: [June 7, 2023, 12:50am UTC](https://discourse.nixos.org/t/super-colliding-nix-stores/28462/14 "2023-06-07T00:50:13Z")

</div>

Yeah, I get it. But isn’t the overlay fs still copy artifacts onto the build host machine anyway?

---

<div class="post-metadata">

### Author: ![shimun](https://discourse.nixos.org/user_avatar/discourse.nixos.org/shimun/32/3576_2.png) [@shimun](https://discourse.nixos.org/u/shimun)
#### Post date: [June 8, 2023, 3:56pm UTC](https://discourse.nixos.org/t/super-colliding-nix-stores/28462/15 "2023-06-08T15:56:24Z")

</div>

Wouldn’t the upper store break if the lower store gets garbage collected?

---

<div class="post-metadata">

### Author: ![ryantm](https://discourse.nixos.org/user_avatar/discourse.nixos.org/ryantm/32/900_2.png) [@ryantm](https://discourse.nixos.org/u/ryantm)
#### Post date: [June 12, 2023, 12:54am UTC](https://discourse.nixos.org/t/super-colliding-nix-stores/28462/16 "2023-06-12T00:54:25Z")

</div>

Yes, it would. We’re exploring the idea of a store checker that would detect this issue.

---

<div class="post-metadata">

### Author: ![ryantm](https://discourse.nixos.org/user_avatar/discourse.nixos.org/ryantm/32/900_2.png) [@ryantm](https://discourse.nixos.org/u/ryantm)
#### Post date: [June 17, 2023, 2:06pm UTC](https://discourse.nixos.org/t/super-colliding-nix-stores/28462/17 "2023-06-17T14:06:18Z")

</div>

[https://github.com/NixOS/rfcs/pull/152](https://github.com/NixOS/rfcs/pull/152)

---

<div class="post-metadata">

### Author: ![Ericson2314](https://discourse.nixos.org/user_avatar/discourse.nixos.org/ericson2314/32/316_2.png) [@Ericson2314](https://discourse.nixos.org/u/Ericson2314)
#### Post date: [July 31, 2023, 7:40pm UTC](https://discourse.nixos.org/t/super-colliding-nix-stores/28462/18 "2023-07-31T19:40:41Z")

</div>

The RFC has been open for a bit, and we need more shepherds! Shepherding doesn’t take very much time for most RFCs, so we encourage anyone who would like to use this feature to sign up!

---

<div class="post-metadata">

### Author: ![Ericson2314](https://discourse.nixos.org/user_avatar/discourse.nixos.org/ericson2314/32/316_2.png) [@Ericson2314](https://discourse.nixos.org/u/Ericson2314)
#### Post date: [April 11, 2024, 11:48pm UTC](https://discourse.nixos.org/t/super-colliding-nix-stores/28462/19 "2024-04-11T23:48:13Z")

</div>

Happy to say that the implementation ([[RFC 0152] `local-overlay` store by Ericson2314 · Pull Request #152 · NixOS/rfcs · GitHub](https://github.com/NixOS/rfcs/pull/152)) is now merged in upstream Nix as an experimental feature!

---

<div class="post-metadata">

### Author: ![colemickens](https://discourse.nixos.org/user_avatar/discourse.nixos.org/colemickens/32/624_2.png) [@colemickens](https://discourse.nixos.org/u/colemickens)
#### Post date: [April 12, 2024, 1:40am UTC](https://discourse.nixos.org/t/super-colliding-nix-stores/28462/20 "2024-04-12T01:40:29Z")

</div>

First, congrats! I’ve been excited for this since it was announced, given my own weird poor hacky attempts at doing some sort of sqlite syncing with a shared /nix/store, etc. Thanks to you and replit and reviewers, etc.

What’s the best way to get my head around this, strictly from an end-user perspective? Skimming through the RFC is a bit of a doozy, and I’m hoping I can get some working knowledge without needing to consume the whole RFC/impl details.

[Next page](https://discourse.nixos.org/t/super-colliding-nix-stores/28462.md?page=2)
