nix-shell
21-11-2026 door Bernard in
Geen categorie
nix-shell start een shell met tijdelijke programma's of een complete ontwikkelomgeving, zonder iets blijvend te installeren.
Basisgebruik
nix-shell -p python3 nodejs
nix-shell -p jq --run "jq . data.json"
Sluit je de shell (exit), dan zijn de programma's weer weg.
Ontwikkelomgeving per project: shell.nix
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
packages = with pkgs; [ go gopls postgresql ];
shellHook = ''
echo "Go-omgeving klaar"
'';
}
Daarna in die map:
nix-shell
Opties
| Optie | Betekenis |
|---|---|
-p pakket |
Pakketten uit Nixpkgs |
--run "cmd" |
Commando uitvoeren en stoppen |
--pure |
Lege omgeving: alleen wat je opgeeft |
Als shebang
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p curl jq
curl -s https://api.github.com | jq .
Het script haalt zelf de programma's op die het nodig heeft.
Tip
Met direnv en use nix start de omgeving automatisch als je de map binnengaat. De nieuwere vormen zijn nix shell en nix develop.
Zie ook
Reactie? Stuur ons een bericht via ons contactformulier.