← 返回命令列表

Linux command

nix-shell 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Enter shell with package

nix-shell -p [hello]

Enter shell from default.nix

nix-shell

Enter shell from file

nix-shell [shell.nix]

Run command in shell

nix-shell -p [jq] --run "[jq --version]"

Pure shell

nix-shell --pure -p [python3]

Multiple packages

nix-shell -p [python3] [nodejs] [git]

说明

nix-shell creates temporary development environments. Provides packages without installing. The tool sets up shell with dependencies. Exits cleanly without system changes.

参数

-p _PACKAGES_
Packages to include.
--run _CMD_
Command to execute.
--pure
Clear environment.
-A _ATTR_
Use specific attribute.
-I _PATH_
Add path to Nix expression search path (e.g., `-I nixpkgs=/path/to/nixpkgs`).
--command _CMD_
Run a command then stay in the shell (unlike `--run`, which exits after).
--keep _VAR_
Keep an environment variable when using `--pure`.
--packages
Long form of `-p`.
-i _INTERPRETER_
Use as a shebang interpreter (see `#!nix-shell` scripts).
--help
Display help information.

FAQ

What is the nix-shell command used for?

nix-shell creates temporary development environments. Provides packages without installing. The tool sets up shell with dependencies. Exits cleanly without system changes.

How do I run a basic nix-shell example?

Run `nix-shell -p [hello]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -p _PACKAGES_ do in nix-shell?

Packages to include.