Nix DevContainer Extension
A VS Code extension that provides Nix flake management for development containers. This extension automatically creates shell scripts from the output of nix print-dev-env
for each devshell, making Nix development environments seamlessly available in your devcontainer.
Features
- Automatically find Nix flakes in workspace folders
- Create shell scripts from
nix print-dev-env
output for each devshell
- Generate environment scripts in
/etc/profile.d/
for automatic loading
- Update Nix development shell profiles
- Reload window after profile updates
- Support for multiple flakes in a workspace
Commands
Nix DevContainer: Find Flakes
- Discovers all flake.nix files in workspace folders
Nix DevContainer: Update Single Flake
- Update a specific flake by name
Nix DevContainer: Update All Flakes
- Update all discovered flakes
Nix DevContainer: Find and Update All Flakes
- Find and update all flakes in one command
How it Works
The extension scans workspace folders for flake.nix
files and creates shell scripts from the output of nix print-dev-env
for each devshell. These scripts are saved in /etc/profile.d/nix-devcontainer-{flake-name}.sh
to provide the development environment automatically when opening a terminal. When a flake is updated, you'll be prompted to reload the window to apply the changes.
Installation
This extension is designed to be used with the Nix DevContainer feature. Add this to your devcontainer.json
:
{
"features": {
"ghcr.io/akospapp/devcontainer-features/nix-devcontainer:latest": {}
}
}
Requirements
- Nix package manager installed (automatically provided by the devcontainer feature)
- Running in a container or environment with sudo access to
/etc/profile.d/
- VS Code with workspace folders containing
flake.nix
files with devShells.
Usage
Automatic Usage (Recommended)
- Add the devcontainer feature to your
devcontainer.json
- Open your workspace in a devcontainer
- The extension will automatically activate and process all flakes
- Reload the window when prompted to apply environment changes
Manual Usage
- Open a workspace containing Nix flakes
- Use
Ctrl+Shift+P
to open the command palette
- Run
Nix DevContainer: Find and Update All Flakes
to get started
- Reload the window when prompted to apply environment changes
Development
Building the Extension
# Install dependencies
npm install
# Compile TypeScript
npm run compile
# Watch for changes during development
npm run watch
# Lint the code
npm run lint
# Package the extension
npm run package
Testing the Extension
- Open this folder in VS Code
- Press
F5
to run the extension in a new Extension Development Host window
- Open the Command Palette (
Ctrl+Shift+P
) and try the Nix DevContainer commands
Installing the Extension
After packaging, you can install the extension using:
npm run install-extension
Or manually install the generated .vsix
file through VS Code.