diff --git a/src/nix/NOTES.md b/src/nix/NOTES.md index b3b53476a..05fe329e1 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 + +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 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..ea97ad65b 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 + +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 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..25312c04c --- /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 \ 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" + } + } } }