initial commit

This commit is contained in:
Amy de Buitléir 2023-06-11 20:42:18 +01:00
parent 9f673a1419
commit 3f33f10061
2 changed files with 152 additions and 0 deletions

View file

@ -0,0 +1,40 @@
== 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 dont 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:
....
$# shebangs/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:
....
$# shebangs/python-with-nixpkg.sh
....

View file

@ -0,0 +1,112 @@
== Nix shell recipes
=== Shell with access to a package from the Nixpkgs/NixOS repo
This shell provides access to two packages from nixpkgs: hello and
cowsay.
[source,nix,linenums]
....
include::0100-shell-with-nixpkgs.nix[]
....
Heres a demonstration using the shell.
....
$ nix-shell
$ hello
Hello, world!
$ cowsay "moo"
_____
< moo >
-----
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
....
The command-line equivalent would be `nix-shell -p hello cowsay`
=== Shell with access to a package defined in a remote git repo
[source,nix,linenums]
....
include::0150-shell-with-git-nix-pkg.nix[]
....
Heres a demonstration using the shell.
....
$ nix-shell
$ hello-nix
Hello from your nix package!
....
=== Shell with access to a flake
[source,nix,linenums]
....
include::0200-shell-with-flake.nix[]
....
Heres a demonstration using the shell.
....
$ nix-shell
$ hello-flake
Hello from your flake!
....
=== Shell with access to a specific revision of a flake
[source,nix,linenums]
....
include::0250-shell-with-flake-rev.nix[]
....
Heres a demonstration using the shell.
....
$ nix-shell
$ hello-flake
Hello from your flake!
....
=== Shell with access to a Haskell package on your local computer
This shell provides access to three Haskell packages that are on my hard
drive.
[source,nix,linenums]
....
include::0300-shell-haskell-local.nix[]
....
=== Shell with access to a Haskell package on your local computer, with interdependencies
This shell provides access to four Haskell packages that are on my hard
drive. The fourth package depends on the first three to build.
[source,nix,linenums]
....
include::0350-shell-haskell-local-deps.nix[]
....
=== Shell with an environment variable set
This shell has the environment variable FOO set to ``bar''
[source,nix,linenums]
....
include::0400-shell-with-env-var.nix[]
....
Heres a demonstration using the shell.
....
$ nix-shell
$ echo $FOO
bar
....