mirror of
https://codeberg.org/mhwombat/nix-book.git
synced 2025-12-28 01:05:02 +08:00
40 lines
820 B
Text
40 lines
820 B
Text
== Nix-shell shebangs
|
||
|
||
You can use `nix-shell` to run scripts in arbitrary languages, providing
|
||
the necessary dependencies. This is particularly convenient for
|
||
standalone scripts because you don’t need to create a repo and write a
|
||
separate `flake.nix`.
|
||
|
||
The script should start with two ``shebang'' (`#!`) commands. The first
|
||
should invoke `nix-shell`. The second should declares the scrpt
|
||
interpreter and any dependencies. Here are some examples.
|
||
|
||
=== A Bash script depending on a package in the nixpkgs repo.
|
||
|
||
Script:
|
||
|
||
[source,bash,linenums]
|
||
....
|
||
include::bash-with-nixpkg.sh[]
|
||
....
|
||
|
||
Output:
|
||
|
||
....
|
||
$# ./bash-with-nixpkg.sh
|
||
....
|
||
|
||
=== A Python script depending on a package in the nixpkgs repo.
|
||
|
||
Script:
|
||
|
||
[source,bash,linenums]
|
||
....
|
||
include::python-with-nixpkg.sh[]
|
||
....
|
||
|
||
Output:
|
||
|
||
....
|
||
$# ./python-with-nixpkg.sh
|
||
....
|