Linux command
nix-shell.3 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Development shell
nix-shell [shell.nix]
Pure shell
nix-shell --pure
Ad-hoc shell
nix-shell -p [python3] [git]
Run a command
nix-shell --run "[make check]"
Select attribute
nix-shell -A [dev]
Keep environment variable
nix-shell --pure --keep [HOME]
说明
nix-shell starts an interactive shell in which the environment is set up based on a Nix expression. It provides all build dependencies of the specified derivation without actually building it, making it ideal for development environments. When used with --packages/-p, it creates ad-hoc environments with specific packages available. When used with --pure, the host environment is cleared to closely match a real Nix build environment. nix-shell can also be used as a script interpreter via shebang lines (`#!/usr/bin/env nix-shell`) to create reproducible scripts with declared dependencies.
参数
- -p, --packages _packages..._
- Set up an environment with the specified packages from Nixpkgs.
- --pure
- Clear the environment before starting the shell, retaining only HOME, USER, and DISPLAY.
- --run _cmd_
- Run a command in a non-interactive shell, then exit.
- --command _cmd_
- Run a command in an interactive shell, then exit.
- -A, --attr _attrPath_
- Select an attribute from the Nix expression.
- --keep _name_
- Keep an environment variable when using --pure.
- --exclude _regexp_
- Do not build dependencies whose store path matches the regexp.
- -i _interpreter_
- Specify the interpreter for nix-shell shebang scripts.
- -I _path_
- Add a path to the Nix expression search path.
- -v
- Verbose output.
FAQ
What is the nix-shell.3 command used for?
nix-shell starts an interactive shell in which the environment is set up based on a Nix expression. It provides all build dependencies of the specified derivation without actually building it, making it ideal for development environments. When used with --packages/-p, it creates ad-hoc environments with specific packages available. When used with --pure, the host environment is cleared to closely match a real Nix build environment. nix-shell can also be used as a script interpreter via shebang lines (`#!/usr/bin/env nix-shell`) to create reproducible scripts with declared dependencies.
How do I run a basic nix-shell.3 example?
Run `nix-shell [shell.nix]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -p, --packages _packages..._ do in nix-shell.3?
Set up an environment with the specified packages from Nixpkgs.