.\" -*- mode: troff; coding: utf-8 -*- .TH "nix-shell" "1" "" .SH Name .LP \f(CRnix-shell\fR - start an interactive shell based on a Nix expression .SH Synopsis .LP \f(CRnix-shell\fR [\f(CR--arg\fR \fIname\fR \fIvalue\fR] [\f(CR--argstr\fR \fIname\fR \fIvalue\fR] [{\f(CR--attr\fR | \f(CR-A\fR} \fIattrPath\fR] [\f(CR--command\fR \fIcmd\fR] [\f(CR--run\fR \fIcmd\fR] [\f(CR--exclude\fR \fIregexp\fR] [\f(CR--pure\fR] [\f(CR--keep\fR \fIname\fR] {{\f(CR--packages\fR | \f(CR-p\fR} {\fIpackages\fR | \fIexpressions\fR} … | [\fIpath\fR]} .SH Disambiguation .LP This man page describes the command \f(CRnix-shell\fR, which is distinct from \f(CRnix shell\fR. For documentation on the latter, run \f(CRnix shell --help\fR or see \f(CRman nix3-shell\fR. .SH Description .LP The command \f(CRnix-shell\fR will build the dependencies of the specified derivation, but not the derivation itself. It will then start an interactive shell in which all environment variables defined by the derivation \fIpath\fR have been set to their corresponding values, and the script \f(CR$stdenv/setup\fR has been sourced. This is useful for reproducing the environment of a derivation for development. .PP If \fIpath\fR is not given, \f(CRnix-shell\fR defaults to \f(CRshell.nix\fR if it exists, and \f(CRdefault.nix\fR otherwise. .PP If \fIpath\fR starts with \f(CRhttp://\fR or \f(CRhttps://\fR, it is interpreted as the URL of a tarball that will be downloaded and unpacked to a temporary location. The tarball must include a single top-level directory containing at least a file named \f(CRdefault.nix\fR. .PP If the derivation defines the variable \f(CRshellHook\fR, it will be run after \f(CR$stdenv/setup\fR has been sourced. Since this hook is not executed by regular Nix builds, it allows you to perform initialisation specific to \f(CRnix-shell\fR. For example, the derivation attribute .LP .EX shellHook = '' echo \(dqHello shell\(dq export SOME_API_TOKEN=\(dq$(cat \(ti/.config/some-app/api-token)\(dq ''; .EE .PP will cause \f(CRnix-shell\fR to print \f(CRHello shell\fR and set the \f(CRSOME_API_TOKEN\fR environment variable to a user-configured value. .SH Options .LP All options not listed here are passed to \f(CRnix-store --realise\fR, except for \f(CR--arg\fR and \f(CR--attr\fR / \f(CR-A\fR which are passed to \f(CRnix-instantiate\fR. .IP "\(bu" 3 \f(CR--command\fR \fIcmd\fR .br In the environment of the derivation, run the shell command \fIcmd\fR. This command is executed in an interactive shell. (Use \f(CR--run\fR to use a non-interactive shell instead.) However, a call to \f(CRexit\fR is implicitly added to the command, so the shell will exit after running the command. To prevent this, add \f(CRreturn\fR at the end; e.g. \f(CR--command \(dqecho Hello; return\(dq\fR will print \f(CRHello\fR and then drop you into the interactive shell. This can be useful for doing any additional initialisation. .IP "\(bu" 3 \f(CR--run\fR \fIcmd\fR .br Like \f(CR--command\fR, but executes the command in a non-interactive shell. This means (among other things) that if you hit Ctrl-C while the command is running, the shell exits. .IP "\(bu" 3 \f(CR--exclude\fR \fIregexp\fR .br Do not build any dependencies whose store path matches the regular expression \fIregexp\fR. This option may be specified multiple times. .IP "\(bu" 3 \f(CR--pure\fR .br If this flag is specified, the environment is almost entirely cleared before the interactive shell is started, so you get an environment that more closely corresponds to the “real” Nix build. A few variables, in particular \f(CRHOME\fR, \f(CRUSER\fR and \f(CRDISPLAY\fR, are retained. .IP "\(bu" 3 \f(CR--packages\fR / \f(CR-p\fR \fIpackages\fR… .br Set up an environment in which the specified packages are present. The command line arguments are interpreted as attribute names inside the Nix Packages collection. Thus, \f(CRnix-shell --packages libjpeg openjdk\fR will start a shell in which the packages denoted by the attribute names \f(CRlibjpeg\fR and \f(CRopenjdk\fR are present. .IP "\(bu" 3 \f(CR-i\fR \fIinterpreter\fR .br The chained script interpreter to be invoked by \f(CRnix-shell\fR. Only applicable in \f(CR#!\fR-scripts (described below). .IP "\(bu" 3 \f(CR--keep\fR \fIname\fR .br When a \f(CR--pure\fR shell is started, keep the listed environment variables. .SH Common Options .LP Most Nix commands accept the following command-line options: .IP "\(bu" 3 \fB\f(CR--help\fR\fR .IP Prints out a summary of the command syntax and exits. .IP "\(bu" 3 \fB\f(CR--version\fR\fR .IP Prints out the Nix version number on standard output and exits. .IP "\(bu" 3 \fB\f(CR--verbose\fR\fR / \f(CR-v\fR .IP Increases the level of verbosity of diagnostic messages printed on standard error. For each Nix operation, the information printed on standard output is well-defined; any diagnostic information is printed on standard error, never on standard output. .IP This option may be specified repeatedly. Currently, the following verbosity levels exist: .RS .IP "\(bu" 3 \f(CR0\fR “Errors only” .RE .IP Only print messages explaining why the Nix invocation failed. .RS .IP "\(bu" 3 \f(CR1\fR “Informational” .RE .IP Print \fIuseful\fR messages about what Nix is doing. This is the default. .RS .IP "\(bu" 3 \f(CR2\fR “Talkative” .RE .IP Print more informational messages. .RS .IP "\(bu" 3 \f(CR3\fR “Chatty” .RE .IP Print even more informational messages. .RS .IP "\(bu" 3 \f(CR4\fR “Debug” .RE .IP Print debug information. .RS .IP "\(bu" 3 \f(CR5\fR “Vomit” .RE .IP Print vast amounts of debug information. .IP "\(bu" 3 \fB\f(CR--quiet\fR\fR .IP Decreases the level of verbosity of diagnostic messages printed on standard error. This is the inverse option to \f(CR-v\fR / \f(CR--verbose\fR. .IP This option may be specified repeatedly. See the previous verbosity levels list. .IP "\(bu" 3 \fB\f(CR--log-format\fR\fR \fIformat\fR .IP This option can be used to change the output of the log format, with \fIformat\fR being one of: .RS .IP "\(bu" 3 \f(CRraw\fR .RE .IP This is the raw format, as outputted by nix-build. .RS .IP "\(bu" 3 \f(CRinternal-json\fR .RE .IP Outputs the logs in a structured manner. .RS .IP \fBWarning\fR .IP While the schema itself is relatively stable, the format of the error-messages (namely of the \f(CRmsg\fR-field) can change between releases. .RE .RS .IP "\(bu" 3 \f(CRbar\fR .RE .IP Only display a progress bar during the builds. .RS .IP "\(bu" 3 \f(CRbar-with-logs\fR .RE .IP Display the raw logs, with the progress bar at the bottom. .IP "\(bu" 3 \fB\f(CR--no-build-output\fR\fR / \f(CR-Q\fR .IP By default, output written by builders to standard output and standard error is echoed to the Nix command\(cqs standard error. This option suppresses this behaviour. Note that the builder\(cqs standard output and error are always written to a log file in \f(CRprefix/nix/var/log/nix\fR. .IP "\(bu" 3 \fB\f(CR--max-jobs\fR\fR / \f(CR-j\fR \fInumber\fR .IP Sets the maximum number of build jobs that Nix will perform in parallel to the specified number. Specify \f(CRauto\fR to use the number of CPUs in the system. The default is specified by the \f(CRmax-jobs\fR configuration setting, which itself defaults to \f(CR1\fR. A higher value is useful on SMP systems or to exploit I/O latency. .IP Setting it to \f(CR0\fR disallows building on the local machine, which is useful when you want builds to happen only on remote builders. .IP "\(bu" 3 \fB\f(CR--cores\fR\fR .IP Sets the value of the \f(CRNIX_BUILD_CORES\fR environment variable in the invocation of builders. Builders can use this variable at their discretion to control the maximum amount of parallelism. For instance, in Nixpkgs, if the derivation attribute \f(CRenableParallelBuilding\fR is set to \f(CRtrue\fR, the builder passes the \f(CR-jN\fR flag to GNU Make. It defaults to the value of the \f(CRcores\fR configuration setting, if set, or \f(CR1\fR otherwise. The value \f(CR0\fR means that the builder should use all available CPU cores in the system. .IP "\(bu" 3 \fB\f(CR--max-silent-time\fR\fR .IP Sets the maximum number of seconds that a builder can go without producing any data on standard output or standard error. The default is specified by the \f(CRmax-silent-time\fR configuration setting. \f(CR0\fR means no time-out. .IP "\(bu" 3 \fB\f(CR--timeout\fR\fR .IP Sets the maximum number of seconds that a builder can run. The default is specified by the \f(CRtimeout\fR configuration setting. \f(CR0\fR means no timeout. .IP "\(bu" 3 \fB\f(CR--keep-going\fR\fR / \f(CR-k\fR .IP Keep going in case of failed builds, to the greatest extent possible. That is, if building an input of some derivation fails, Nix will still build the other inputs, but not the derivation itself. Without this option, Nix stops if any build fails (except for builds of substitutes), possibly killing builds in progress (in case of parallel or distributed builds). .IP "\(bu" 3 \fB\f(CR--keep-failed\fR\fR / \f(CR-K\fR .IP Specifies that in case of a build failure, the temporary directory (usually in \f(CR/tmp\fR) in which the build takes place should not be deleted. The path of the build directory is printed as an informational message. .IP "\(bu" 3 \fB\f(CR--fallback\fR\fR .IP Whenever Nix attempts to build a derivation for which substitutes are known for each output path, but realising the output paths through the substitutes fails, fall back on building the derivation. .IP The most common scenario in which this is useful is when we have registered substitutes in order to perform binary distribution from, say, a network repository. If the repository is down, the realisation of the derivation will fail. When this option is specified, Nix will build the derivation instead. Thus, installation from binaries falls back on installation from source. This option is not the default since it is generally not desirable for a transient failure in obtaining the substitutes to lead to a full build from source (with the related consumption of resources). .IP "\(bu" 3 \fB\f(CR--readonly-mode\fR\fR .IP When this option is used, no attempt is made to open the Nix database. Most Nix operations do need database access, so those operations will fail. .IP "\(bu" 3 \fB\f(CR--arg\fR\fR \fIname\fR \fIvalue\fR .IP This option is accepted by \f(CRnix-env\fR, \f(CRnix-instantiate\fR, \f(CRnix-shell\fR and \f(CRnix-build\fR. When evaluating Nix expressions, the expression evaluator will automatically try to call functions that it encounters. It can automatically call functions for which every argument has a \fBdefault value\fR (e.g., \f(CR{ argName ? defaultValue }: ...\fR). .IP With \f(CR--arg\fR, you can also call functions that have arguments without a default value (or override a default value). That is, if the evaluator encounters a function with an argument named \fIname\fR, it will call it with value \fIvalue\fR. .IP For instance, the top-level \f(CRdefault.nix\fR in Nixpkgs is actually a function: .LP .EX { # The system (e.g., \(gai686-linux') for which to build the packages. system ? builtins.currentSystem \&... }: ... .EE .IP So if you call this Nix expression (e.g., when you do \f(CRnix-env --install --attr pkgname\fR), the function will be called automatically using the value \fB\f(CRbuiltins.currentSystem\fR\fR for the \f(CRsystem\fR argument. You can override this using \f(CR--arg\fR, e.g., \f(CRnix-env --install --attr pkgname --arg system \e\(dqi686-freebsd\e\(dq\fR. (Note that since the argument is a Nix string literal, you have to escape the quotes.) .IP "\(bu" 3 \fB\f(CR--argstr\fR\fR \fIname\fR \fIvalue\fR .IP This option is like \f(CR--arg\fR, only the value is not a Nix expression but a string. So instead of \f(CR--arg system \e\(dqi686-linux\e\(dq\fR (the outer quotes are to keep the shell happy) you can say \f(CR--argstr system i686-linux\fR. .IP "\(bu" 3 \fB\f(CR--attr\fR\fR / \f(CR-A\fR \fIattrPath\fR .IP Select an attribute from the top-level Nix expression being evaluated. (\f(CRnix-env\fR, \f(CRnix-instantiate\fR, \f(CRnix-build\fR and \f(CRnix-shell\fR only.) The \fIattribute path\fR \fIattrPath\fR is a sequence of attribute names separated by dots. For instance, given a top-level Nix expression \fIe\fR, the attribute path \f(CRxorg.xorgserver\fR would cause the expression \f(CRe.xorg.xorgserver\fR to be used. See \fB\f(CRnix-env --install\fR\fR for some concrete examples. .IP In addition to attribute names, you can also specify array indices. For instance, the attribute path \f(CRfoo.3.bar\fR selects the \f(CRbar\fR attribute of the fourth element of the array in the \f(CRfoo\fR attribute of the top-level expression. .IP "\(bu" 3 \fB\f(CR--expr\fR\fR / \f(CR-E\fR .IP Interpret the command line arguments as a list of Nix expressions to be parsed and evaluated, rather than as a list of file names of Nix expressions. (\f(CRnix-instantiate\fR, \f(CRnix-build\fR and \f(CRnix-shell\fR only.) .IP For \f(CRnix-shell\fR, this option is commonly used to give you a shell in which you can build the packages returned by the expression. If you want to get a shell which contain the \fIbuilt\fR packages ready for use, give your expression to the \f(CRnix-shell --packages\fR convenience flag instead. .IP "\(bu" 3 \fB\f(CR-I\fR\fR \fIpath\fR .IP Add an entry to the \fBNix expression search path\fR. This option may be given multiple times. Paths added through \f(CR-I\fR take precedence over \fB\f(CRNIX_PATH\fR\fR. .IP "\(bu" 3 \fB\f(CR--option\fR\fR \fIname\fR \fIvalue\fR .IP Set the Nix configuration option \fIname\fR to \fIvalue\fR. This overrides settings in the Nix configuration file (see nix.conf5). .IP "\(bu" 3 \fB\f(CR--repair\fR\fR .IP Fix corrupted or missing store paths by redownloading or rebuilding them. Note that this is slow because it requires computing a cryptographic hash of the contents of every path in the closure of the build. Also note the warning under \f(CRnix-store --repair-path\fR. .SH Environment variables .IP "\(bu" 3 \f(CRNIX_BUILD_SHELL\fR .br Shell used to start the interactive environment. Defaults to the \f(CRbash\fR found in \f(CR\fR, falling back to the \f(CRbash\fR found in \f(CRPATH\fR if not found. .SH Common Environment Variables .LP Most Nix commands interpret the following environment variables: .IP "\(bu" 3 \fB\f(CRIN_NIX_SHELL\fR\fR .br Indicator that tells if the current environment was set up by \f(CRnix-shell\fR. It can have the values \f(CRpure\fR or \f(CRimpure\fR. .IP "\(bu" 3 \fB\f(CRNIX_PATH\fR\fR .br A colon-separated list of directories used to look up the location of Nix expressions using \fBpaths\fR enclosed in angle brackets (i.e., \f(CR\fR), e.g. \f(CR/home/eelco/Dev:/etc/nixos\fR. It can be extended using the \fB\f(CR-I\fR option\fR. .IP If \f(CRNIX_PATH\fR is not set at all, Nix will fall back to the following list in \fBimpure\fR and \fBunrestricted\fR evaluation mode: .RS .IP "1." 3 \f(CR$HOME/.nix-defexpr/channels\fR .if n \ .sp -1 .if t \ .sp -0.25v .IP "2." 3 \f(CRnixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixpkgs\fR .if n \ .sp -1 .if t \ .sp -0.25v .IP "3." 3 \f(CR/nix/var/nix/profiles/per-user/root/channels\fR .RE .IP If \f(CRNIX_PATH\fR is set to an empty string, resolving search paths will always fail. For example, attempting to use \f(CR\fR will produce: .LP .EX error: file 'nixpkgs' was not found in the Nix search path .EE .IP "\(bu" 3 \fB\f(CRNIX_IGNORE_SYMLINK_STORE\fR\fR .br Normally, the Nix store directory (typically \f(CR/nix/store\fR) is not allowed to contain any symlink components. This is to prevent “impure” builds. Builders sometimes “canonicalise” paths by resolving all symlink components. Thus, builds on different machines (with \f(CR/nix/store\fR resolving to different locations) could yield different results. This is generally not a problem, except when builds are deployed to machines where \f(CR/nix/store\fR resolves differently. If you are sure that you’re not going to do that, you can set \f(CRNIX_IGNORE_SYMLINK_STORE\fR to \f(CR1\fR. .IP Note that if you’re symlinking the Nix store so that you can put it on another file system than the root file system, on Linux you’re better off using \f(CRbind\fR mount points, e.g., .LP .EX $ mkdir /nix $ mount -o bind /mnt/otherdisk/nix /nix .EE .IP Consult the mount 8 manual page for details. .IP "\(bu" 3 \fB\f(CRNIX_STORE_DIR\fR\fR .br Overrides the location of the Nix store (default \f(CRprefix/store\fR). .IP "\(bu" 3 \fB\f(CRNIX_DATA_DIR\fR\fR .br Overrides the location of the Nix static data directory (default \f(CRprefix/share\fR). .IP "\(bu" 3 \fB\f(CRNIX_LOG_DIR\fR\fR .br Overrides the location of the Nix log directory (default \f(CRprefix/var/log/nix\fR). .IP "\(bu" 3 \fB\f(CRNIX_STATE_DIR\fR\fR .br Overrides the location of the Nix state directory (default \f(CRprefix/var/nix\fR). .IP "\(bu" 3 \fB\f(CRNIX_CONF_DIR\fR\fR .br Overrides the location of the system Nix configuration directory (default \f(CRprefix/etc/nix\fR). .IP "\(bu" 3 \fB\f(CRNIX_CONFIG\fR\fR .br Applies settings from Nix configuration from the environment. The content is treated as if it was read from a Nix configuration file. Settings are separated by the newline character. .IP "\(bu" 3 \fB\f(CRNIX_USER_CONF_FILES\fR\fR .br Overrides the location of the Nix user configuration files to load from. .IP The default are the locations according to the \fBXDG Base Directory Specification\fR. See the \fBXDG Base Directories\fR sub-section for details. .IP The variable is treated as a list separated by the \f(CR:\fR token. .IP "\(bu" 3 \fB\f(CRTMPDIR\fR\fR .br Use the specified directory to store temporary files. In particular, this includes temporary build directories; these can take up substantial amounts of disk space. The default is \f(CR/tmp\fR. .IP "\(bu" 3 \fB\f(CRNIX_REMOTE\fR\fR .br This variable should be set to \f(CRdaemon\fR if you want to use the Nix daemon to execute Nix operations. This is necessary in \fBmulti-user Nix installations\fR. If the Nix daemon\(cqs Unix socket is at some non-standard path, this variable should be set to \f(CRunix://path/to/socket\fR. Otherwise, it should be left unset. .IP "\(bu" 3 \fB\f(CRNIX_SHOW_STATS\fR\fR .br If set to \f(CR1\fR, Nix will print some evaluation statistics, such as the number of values allocated. .IP "\(bu" 3 \fB\f(CRNIX_COUNT_CALLS\fR\fR .br If set to \f(CR1\fR, Nix will print how often functions were called during Nix expression evaluation. This is useful for profiling your Nix expressions. .IP "\(bu" 3 \fB\f(CRGC_INITIAL_HEAP_SIZE\fR\fR .br If Nix has been configured to use the Boehm garbage collector, this variable sets the initial size of the heap in bytes. It defaults to 384 MiB. Setting it to a low value reduces memory consumption, but will increase runtime due to the overhead of garbage collection. .SS XDG Base Directories .LP Nix follows the \fBXDG Base Directory Specification\fR. .PP For backwards compatibility, Nix commands will follow the standard only when \fB\f(CRuse-xdg-base-directories\fR\fR is enabled. \fBNew Nix commands\fR (experimental) conform to the standard by default. .PP The following environment variables are used to determine locations of various state and configuration files: .IP "\(bu" 3 [\f(CRXDG_CONFIG_HOME\fR]{#env-XDG\fICONFIG\fRHOME} (default \f(CR\(ti/.config\fR) .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 [\f(CRXDG_STATE_HOME\fR]{#env-XDG\fISTATE\fRHOME} (default \f(CR\(ti/.local/state\fR) .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 [\f(CRXDG_CACHE_HOME\fR]{#env-XDG\fICACHE\fRHOME} (default \f(CR\(ti/.cache\fR) .SH Examples .LP To build the dependencies of the package Pan, and start an interactive shell in which to build it: .LP .EX $ nix-shell '' --attr pan [nix-shell]$ eval ${unpackPhase:-unpackPhase} [nix-shell]$ cd $sourceRoot [nix-shell]$ eval ${patchPhase:-patchPhase} [nix-shell]$ eval ${configurePhase:-configurePhase} [nix-shell]$ eval ${buildPhase:-buildPhase} [nix-shell]$ ./pan/gui/pan .EE .PP The reason we use form \f(CReval ${configurePhase:-configurePhase}\fR here is because those packages that override these phases do so by exporting the overridden values in the environment variable of the same name. Here bash is being told to either evaluate the contents of \(oqconfigurePhase\(cq, if it exists as a variable, otherwise evaluate the configurePhase function. .PP To clear the environment first, and do some additional automatic initialisation of the interactive shell: .LP .EX $ nix-shell '' --attr pan --pure \e --command 'export NIX_DEBUG=1; export NIX_CORES=8; return' .EE .PP Nix expressions can also be given on the command line using the \f(CR-E\fR and \f(CR-p\fR flags. For instance, the following starts a shell containing the packages \f(CRsqlite\fR and \f(CRlibX11\fR: .LP .EX $ nix-shell --expr 'with import { }; runCommand \(dqdummy\(dq { buildInputs = [ sqlite xorg.libX11 ]; } \(dq\(dq' .EE .PP A shorter way to do the same is: .LP .EX $ nix-shell --packages sqlite xorg.libX11 [nix-shell]$ echo $NIX_LDFLAGS … -L/nix/store/j1zg5v…-sqlite-3.8.0.2/lib -L/nix/store/0gmcz9…-libX11-1.6.1/lib … .EE .PP Note that \f(CR-p\fR accepts multiple full nix expressions that are valid in the \f(CRbuildInputs = [ ... ]\fR shown above, not only package names. So the following is also legal: .LP .EX $ nix-shell --packages sqlite 'git.override { withManual = false; }' .EE .PP The \f(CR-p\fR flag looks up Nixpkgs in the Nix search path. You can override it by passing \f(CR-I\fR or setting \f(CRNIX_PATH\fR. For example, the following gives you a shell containing the Pan package from a specific revision of Nixpkgs: .LP .EX $ nix-shell --packages pan -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/8a3eea054838b55aca962c3fbde9c83c102b8bf2.tar.gz [nix-shell:\(ti]$ pan --version Pan 0.139 .EE .SH Use as a \f(CR#!\fR-interpreter .LP You can use \f(CRnix-shell\fR as a script interpreter to allow scripts written in arbitrary languages to obtain their own dependencies via Nix. This is done by starting the script with the following lines: .LP .EX #! /usr/bin/env nix-shell #! nix-shell -i real-interpreter --packages packages .EE .PP where \fIreal-interpreter\fR is the “real” script interpreter that will be invoked by \f(CRnix-shell\fR after it has obtained the dependencies and initialised the environment, and \fIpackages\fR are the attribute names of the dependencies in Nixpkgs. .PP The lines starting with \f(CR#! nix-shell\fR specify \f(CRnix-shell\fR options (see above). Note that you cannot write \f(CR#! /usr/bin/env nix-shell -i ...\fR because many operating systems only allow one argument in \f(CR#!\fR lines. .PP For example, here is a Python script that depends on Python and the \f(CRprettytable\fR package: .LP .EX #! /usr/bin/env nix-shell #! nix-shell -i python --packages python pythonPackages.prettytable import prettytable # Print a simple table. t = prettytable.PrettyTable([\(dqN\(dq, \(dqN\(ha2\(dq]) for n in range(1, 10): t.add_row([n, n * n]) print t .EE .PP Similarly, the following is a Perl script that specifies that it requires Perl and the \f(CRHTML::TokeParser::Simple\fR and \f(CRLWP\fR packages: .LP .EX #! /usr/bin/env nix-shell #! nix-shell -i perl --packages perl perlPackages.HTMLTokeParserSimple perlPackages.LWP use HTML::TokeParser::Simple; # Fetch nixos.org and print all hrefs. my $p = HTML::TokeParser::Simple->new(url => 'http://nixos.org/'); while (my $token = $p->get_tag(\(dqa\(dq)) { my $href = $token->get_attr(\(dqhref\(dq); print \(dq$href\en\(dq if $href; } .EE .PP Sometimes you need to pass a simple Nix expression to customize a package like Terraform: .LP .EX #! /usr/bin/env nix-shell #! nix-shell -i bash --packages \(dqterraform.withPlugins (plugins: [ plugins.openstack ])\(dq terraform apply .EE .RS .PP \fBNote\fR .PP You must use double quotes (\f(CR\(dq\fR) when passing a simple Nix expression in a nix-shell shebang. .RE .PP Finally, using the merging of multiple nix-shell shebangs the following Haskell script uses a specific branch of Nixpkgs/NixOS (the 20.03 stable branch): .LP .EX #! /usr/bin/env nix-shell #! nix-shell -i runghc --packages \(dqhaskellPackages.ghcWithPackages (ps: [ps.download-curl ps.tagsoup])\(dq #! nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/nixos-20.03.tar.gz import Network.Curl.Download import Text.HTML.TagSoup import Data.Either import Data.ByteString.Char8 (unpack) -- Fetch nixos.org and print all hrefs. main = do resp <- openURI \(dqhttps://nixos.org/\(dq let tags = filter (isTagOpenName \(dqa\(dq) $ parseTags $ unpack $ fromRight undefined resp let tags' = map (fromAttrib \(dqhref\(dq) tags mapM_ putStrLn $ filter (/= \(dq\(dq) tags' .EE .PP If you want to be even more precise, you can specify a specific revision of Nixpkgs: .LP .EX #! nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/0672315759b3e15e2121365f067c1c8c56bb4722.tar.gz .EE .PP The examples above all used \f(CR-p\fR to get dependencies from Nixpkgs. You can also use a Nix expression to build your own dependencies. For example, the Python example could have been written as: .LP .EX #! /usr/bin/env nix-shell #! nix-shell deps.nix -i python .EE .PP where the file \f(CRdeps.nix\fR in the same directory as the \f(CR#!\fR-script contains: .LP .EX with import {}; runCommand \(dqdummy\(dq { buildInputs = [ python pythonPackages.prettytable ]; } \(dq\(dq .EE