Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

working on #PR 325 - nix shell and shellbang #427

Merged
merged 14 commits into from
Feb 16, 2023
Merged
9 changes: 5 additions & 4 deletions source/tutorials/reproducible-scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Reproducible interpreted scripts

In this tutorial, you will learn how to use Nix to create and run reproducible interpreted scripts.
In this tutorial, you will learn how to use Nix to create and run reproducible interpreted scripts with [shebang].
henrik-ch marked this conversation as resolved.
Show resolved Hide resolved

## Requirements

Expand Down Expand Up @@ -31,7 +31,7 @@ A [shebang] is the first line of a script starting with `#!`.
It determines which program to use for running the script.

[Bash]: https://www.gnu.org/software/bash/
[shebang]: https://en.m.wikipedia.org/wiki/Shebang_(Unix)
[shebang]: https://en.wikipedia.org/wiki/Shebang_(Unix)

We will use the shebang line `#! /usr/bin/env nix-shell`.

Expand All @@ -44,6 +44,7 @@ It takes the following parameters relevant for our use case:
- `-i` tells which program to use for interpreting the rest of the file
- `-p` lists packages that should be present in the interpreter's environment
- `-I` explicitly sets [the search path] for packages
- `--pure` clears the environment before start - more details in the [nix-shell man page]: https://nixos.org/manual/nix/stable/command-ref/nix-shell.html#options
henrik-ch marked this conversation as resolved.
Show resolved Hide resolved

henrik-ch marked this conversation as resolved.
Show resolved Hide resolved
[`nix-shell` as a shebang interpreter]: https://nixos.org/manual/nix/stable/command-ref/nix-shell.html#use-as-a--interpreter
[the search path]: https://nixos.org/manual/nix/unstable/command-ref/opt-common.html#opt-I
Expand All @@ -52,8 +53,8 @@ Create a file named `nixpkgs-releases.sh` with the following content:

```shell
#!/usr/bin/env nix-shell
#! nix-shell -i bash
#! nix-shell -p curl jq python3Packages.xmljson
#! nix-shell -i bash --pure
#! nix-shell -p bash cacert curl jq python3Packages.xmljson
#! nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/2a601aafdc5605a5133a2ca506a34a3a73377247.tar.gz

curl https://github.com/NixOS/nixpkgs/releases.atom | xml2json | jq .
Expand Down