Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/nix/NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@

This Feature should work on recent versions of Debian/Ubuntu, RedHat Enterprise Linux, Fedora, RockyLinux, and Alpine Linux.

## Nix store persistence

> [!WARNING]
> On 1.3.x, Due to a nix cache `version`/`packages` changes are silently ignored on rebuild. `/nix` is mounted from a Docker volume that is seeded only on the first build. That mount can't be modified afterwards, so it keeps masking the newer image and no option change ever takes effect.

**1.4.0+** removes the cache to avoid this; follow the workaround below to keep it.

### Optional: cache `/nix` to speed up rebuilds

Only if you use the default Feature (`"nix": {}`) and rebuild often: Add a local cache by pinning `/nix` to your own volume so runtime-installed packages survive recreation instead of being re-downloaded each time. Safe here because no options ever change.

Add this as a top-level property in your `.devcontainer/devcontainer.json`:

```json
"mounts": [
{ "source": "my-nix-store", "target": "/nix", "type": "volume" }
]
```

Rebuild once to seed it. If you later add options or bump `version`, run `docker volume rm my-nix-store` first so the new image takes effect.

## 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.
Expand Down
21 changes: 21 additions & 0 deletions src/nix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,27 @@ 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

> [!WARNING]
> On 1.3.x, Due to a nix cache `version`/`packages` changes are silently ignored on rebuild. `/nix` is mounted from a Docker volume that is seeded only on the first build. That mount can't be modified afterwards, so it keeps masking the newer image and no option change ever takes effect.

**1.4.0+** removes the cache to avoid this; follow the workaround below to keep it.

### Optional: cache `/nix` to speed up rebuilds

Only if you use the default Feature (`"nix": {}`) and rebuild often: Add a local cache by pinning `/nix` to your own volume so runtime-installed packages survive recreation instead of being re-downloaded each time. Safe here because no options ever change.

Add this as a top-level property in your `.devcontainer/devcontainer.json`:

```json
"mounts": [
{ "source": "my-nix-store", "target": "/nix", "type": "volume" }
]
```

Rebuild once to seed it. If you later add options or bump `version`, run `docker volume rm my-nix-store` first so the new image takes effect.

## 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.
Expand Down
9 changes: 1 addition & 8 deletions src/nix/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -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.",
Expand Down Expand Up @@ -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"
}
11 changes: 11 additions & 0 deletions test/nix/extra-config-packages.sh
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions test/nix/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
}
Loading