features icon indicating copy to clipboard operation
features copied to clipboard

Nix store volume not updating during rebuilds

Open dani0854 opened this issue 3 months ago • 4 comments

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-* volume is empty, and files are copied into it when an empty volume is mounted. 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)?

dani0854 avatar Oct 20 '25 02:10 dani0854