News for hackers. Stuff that matters.
Re:Nix and Containers: Why Not Both? by civo on Thursday February 27, 2025 @12:07PM (#43196246)
Why not both indeed!

- Kunal

Re:Nix and Containers: Why Not Both? by ronef on Thursday February 27, 2025 @11:40AM (#43195971)
Awesome to see this on here! We've seen a lot of comments talk about Nix versus other tools recently and wanted to share some of our thoughts on it. We like seeing Nix meet developers where they are, integrating into our existing workflows, including containerized ones.
Re:Nix and Containers: Why Not Both? by phaseto on Thursday February 27, 2025 @11:09AM (#43195672)
How does Nix improve layer caching efficiency in containerized environments?
Re:Nix and Containers: Why Not Both? by rokgarbas on Thursday February 27, 2025 @11:38AM (#43195950)
- Method 1: doesn't really improve layer caching, but it provides a familiar way (via Dockerfile) to use Nix packages. As with any Dockerfile, the creator is in charge of creating layers and making sure those layers are as small (cleaning cache, ...).

- Method 2: Nix language is used to describe (in a declarative way) what the end image should look like. Layers are then calculated based on the dependency tree (or as Nix calls it, dependency closure). The algorithm that creates layers[1] makes sure that there is higher likelihood of cache hits without the user needing to worry about layers, but you can even roll-up your own algorithm that fits your project better.

- Method 3: Using Flox you would get sort of both. An easy way to configure the final docker image via toml configuration and using Method 2 under the hood.

There are other ways how to improve caching efficiency, but those are very use case specific (eg. big "builder" images) and would probably require a completely separate blog post.

[1] https://github.com/NixOS/nixpkgs/blob/63f0da03a3b2c323ea924b...