devcontainers / devcontainers/features
Nix store volume not updating during rebuilds
- Dominant language
- Shell
- Stars
- 1.5k
- Forks
- 621
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 4
Description
Running on linux (nixos), with docker.
**Steps to reproduce:**
1. Create and start a new environment
```
{
"name": "test",
"image": "mcr.microsoft.com/devcontainers/base:noble",
"features": {
"ghcr.io/devcontainers/features/nix:1": {
"packages": "hello"
}
}
}
```
2. Change `packages` and rebuild
```
{
"name": "test",
"image": "mcr.microsoft.com/devcontainers/base:noble",
"features": {
"ghcr.io/devcontainers/features/nix:1": {
"packages": "busybox"
}
}
}
```
3. After rebuild `busybox` won't be available (or any other package from `packages`).
After some debugging I think I found the cause. First time we build and run it, [`nix-store-*`](https://github.com/devcontainers/features/blob/main/src/nix/devcontainer-feature.json#L62) volume is empty, and [files are copied into it when an empty volume is mounted](https://docs.docker.com/engine/storage/volumes/#mounting-a-volume-over-existing-data). Second time however since volume already contains data, it mounts over existing `/nix/store` from second build. And so `/home/vscode/.nix-profile` symlink chain is broken, since the new profile is not in `/nix/store`.
Furthermore if we change anything that affects nix installation itself, it will likely also be overwritten by volume mount. And I somehow managed to also break nix install completely during debugging, but I wasn't able to reproduce it.
The workaround would be to delete the volume every time devcontainers gets rebuilt, or somehow make volume name unique to specific build of the image, not image name.
To make work with `/nix/store` in volume, it would have to be mounted during feature install, which I don't think is possible.
Is it possible to make mount point optional (or a separate feature with or without it)?
Contributor guide
Assessment
This issue has not been assessed yet.