From c937d2025b896e47706694a41aa5f04bce07265c Mon Sep 17 00:00:00 2001 From: Venkumahanti Subhankar Date: Wed, 9 Sep 2026 08:41:19 +0000 Subject: [PATCH 1/3] fix(nix): remove the nix store cache causing rebuild inconsistencies --- src/nix/NOTES.md | 4 ++++ src/nix/README.md | 4 ++++ src/nix/devcontainer-feature.json | 9 +-------- test/nix/extra-config-packages.sh | 11 +++++++++++ test/nix/scenarios.json | 10 ++++++++++ 5 files changed, 30 insertions(+), 8 deletions(-) create mode 100755 test/nix/extra-config-packages.sh diff --git a/src/nix/NOTES.md b/src/nix/NOTES.md index b3b53476a..7559bb9c7 100644 --- a/src/nix/NOTES.md +++ b/src/nix/NOTES.md @@ -2,6 +2,10 @@ This Feature should work on recent versions of Debian/Ubuntu, RedHat Enterprise Linux, Fedora, RockyLinux, and Alpine Linux. +## Nix store persistence + +In versions before 1.4.0, a rebuild could keep the Nix store from the first build, so option changes might not fully take effect. You can patch this at runtime from `postCreateCommand`, which runs after the store is attached, using `nix-env` to install missing packages or appending to `/etc/nix/nix.conf` for config, but it has to be repeated after every rebuild. Use 1.4.0 or later to avoid it; leftover `nix-store-*` volumes are unused and safe to delete. + ## Location of Flakes Currently `flakeUri` works best with a remote URI (e.g., `github:nixos/nixpkgs/nixpkgs-unstable#hello`) as local files need to be in the image. diff --git a/src/nix/README.md b/src/nix/README.md index 4fd9700f3..8d44fa185 100644 --- a/src/nix/README.md +++ b/src/nix/README.md @@ -26,6 +26,10 @@ Installs the Nix package manager and optionally a set of packages. This Feature should work on recent versions of Debian/Ubuntu, RedHat Enterprise Linux, Fedora, RockyLinux, and Alpine Linux. +## Nix store persistence + +In versions before 1.4.0, a rebuild could keep the Nix store from the first build, so option changes might not fully take effect. You can patch this at runtime from `postCreateCommand`, which runs after the store is attached, using `nix-env` to install missing packages or appending to `/etc/nix/nix.conf` for config, but it has to be repeated after every rebuild. Use 1.4.0 or later to avoid it; leftover `nix-store-*` volumes are unused and safe to delete. + ## Location of Flakes Currently `flakeUri` works best with a remote URI (e.g., `github:nixos/nixpkgs/nixpkgs-unstable#hello`) as local files need to be in the image. diff --git a/src/nix/devcontainer-feature.json b/src/nix/devcontainer-feature.json index 63723e591..f2e956d8a 100644 --- a/src/nix/devcontainer-feature.json +++ b/src/nix/devcontainer-feature.json @@ -1,6 +1,6 @@ { "id": "nix", - "version": "1.3.1", + "version": "1.4.0", "name": "Nix Package Manager", "documentationURL": "https://github.com/devcontainers/features/tree/main/src/nix", "description": "Installs the Nix package manager and optionally a set of packages.", @@ -57,12 +57,5 @@ "containerEnv": { "PATH": "/nix/var/nix/profiles/default/bin:/nix/var/nix/profiles/default/sbin:${PATH}" }, - "mounts": [ - { - "source": "nix-store-${devcontainerId}", - "target": "/nix", - "type": "volume" - } - ], "entrypoint": "/usr/local/share/nix-entrypoint.sh" } diff --git a/test/nix/extra-config-packages.sh b/test/nix/extra-config-packages.sh new file mode 100755 index 000000000..2b8ee0a47 --- /dev/null +++ b/test/nix/extra-config-packages.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -e + +source dev-container-features-test-lib + +check "Nix installation is not masked by a volume" bash -c "! mountpoint -q /nix" +check "Experimental features config" grep -E '^experimental-features = nix-command flakes$' /etc/nix/nix.conf +check "hello_installed" type hello +check "hello_in_default_profile" bash -lc "nix-env -p /nix/var/nix/profiles/default -q | grep -q '^hello'" + +reportResults &2>1 \ No newline at end of file diff --git a/test/nix/scenarios.json b/test/nix/scenarios.json index 3fb839629..47340c073 100644 --- a/test/nix/scenarios.json +++ b/test/nix/scenarios.json @@ -108,5 +108,15 @@ "extraNixConfig": "extra-substituters = https://foo.cachix.org,extra-trusted-public-keys = foo.cachix.org-1:bar=" } } + }, + "extra-config-packages": { + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "remoteUser": "vscode", + "features": { + "nix": { + "extraNixConfig": "experimental-features = nix-command flakes", + "packages": "hello" + } + } } } From 9bd17d9b3d5f5c4b0799db34df805f2d437f90c4 Mon Sep 17 00:00:00 2001 From: Venkumahanti Subhankar Date: Thu, 10 Sep 2026 05:01:07 +0000 Subject: [PATCH 2/3] update docs to warn users about the failure in 1.3.x --- src/nix/NOTES.md | 2 +- src/nix/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nix/NOTES.md b/src/nix/NOTES.md index 7559bb9c7..05fe329e1 100644 --- a/src/nix/NOTES.md +++ b/src/nix/NOTES.md @@ -4,7 +4,7 @@ This Feature should work on recent versions of Debian/Ubuntu, RedHat Enterprise ## Nix store persistence -In versions before 1.4.0, a rebuild could keep the Nix store from the first build, so option changes might not fully take effect. You can patch this at runtime from `postCreateCommand`, which runs after the store is attached, using `nix-env` to install missing packages or appending to `/etc/nix/nix.conf` for config, but it has to be repeated after every rebuild. Use 1.4.0 or later to avoid it; leftover `nix-store-*` volumes are unused and safe to delete. +On 1.3.x, option changes may not be reflected after a rebuild, because `/nix` is mounted from a Docker volume that keeps the store built the first time. Either install packages from `postCreateCommand` with `nix-env` so they land in that volume, or upgrade to 1.4.0 or later, which drops the mount. ## Location of Flakes diff --git a/src/nix/README.md b/src/nix/README.md index 8d44fa185..ea97ad65b 100644 --- a/src/nix/README.md +++ b/src/nix/README.md @@ -28,7 +28,7 @@ This Feature should work on recent versions of Debian/Ubuntu, RedHat Enterprise ## Nix store persistence -In versions before 1.4.0, a rebuild could keep the Nix store from the first build, so option changes might not fully take effect. You can patch this at runtime from `postCreateCommand`, which runs after the store is attached, using `nix-env` to install missing packages or appending to `/etc/nix/nix.conf` for config, but it has to be repeated after every rebuild. Use 1.4.0 or later to avoid it; leftover `nix-store-*` volumes are unused and safe to delete. +On 1.3.x, option changes may not be reflected after a rebuild, because `/nix` is mounted from a Docker volume that keeps the store built the first time. Either install packages from `postCreateCommand` with `nix-env` so they land in that volume, or upgrade to 1.4.0 or later, which drops the mount. ## Location of Flakes From eec4a8afc338e349a348e838b4b25b6057bec177 Mon Sep 17 00:00:00 2001 From: Venkumahanti Subhankar Date: Thu, 10 Sep 2026 05:38:00 +0000 Subject: [PATCH 3/3] update docs to warn users about the failure in 1.3.x --- test/nix/extra-config-packages.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/nix/extra-config-packages.sh b/test/nix/extra-config-packages.sh index 2b8ee0a47..25312c04c 100755 --- a/test/nix/extra-config-packages.sh +++ b/test/nix/extra-config-packages.sh @@ -8,4 +8,4 @@ check "Experimental features config" grep -E '^experimental-features = nix-comma check "hello_installed" type hello check "hello_in_default_profile" bash -lc "nix-env -p /nix/var/nix/profiles/default -q | grep -q '^hello'" -reportResults &2>1 \ No newline at end of file +reportResults \ No newline at end of file