Skip to content

Misunderstanding on page /tutorials/first-steps/reproducible-scripts.html #1096

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

Open
TNTima opened this issue Jan 17, 2025 · 3 comments
Open

Comments

@TNTima
Copy link

TNTima commented Jan 17, 2025

#!/usr/bin/env nix-shell
#! 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 .

I'm newcomer to nix and I don't understand why nix channel is changed after imports.
Is it okay to post misunderstandings here?

@fricklerhandwerk
Copy link
Collaborator

Hi @TNTima, thanks for asking!

Is it okay to post misunderstandings here?

Yes of course, anything that helps us improve tutorials is highly appreciated.

I don't understand why nix channel is changed after imports.

I'm not sure I got your question right. Do you mean the -I nixpkgs=... part? That one is explained in one of the following paragraphs:

The parameter of -I refers to a specific Git commit of the Nixpkgs repository. This ensures that the script will always run with the exact same packages versions, everywhere.

But maybe I just misunderstood your misunderstanding... :)

fricklerhandwerk added a commit that referenced this issue Jan 17, 2025
Prompted by #1096

It may not be immediately obvious that the paragraphs following the code sample explain the invocation parameters. Making them a list should let that part stand out enough to slow down reading a bit.
fricklerhandwerk added a commit that referenced this issue Jan 19, 2025
…1097)

Prompted by #1096

It may not be immediately obvious that the paragraphs following the code sample explain the invocation parameters. Making them a list should let that part stand out enough to slow down reading a bit.
@TNTima
Copy link
Author

TNTima commented Apr 11, 2025

Sorry for wait, ping is huge here. What I don't understand why -I line goes before -p line. In my head this means source would be changed after imports already happened.

@fricklerhandwerk
Copy link
Collaborator

fricklerhandwerk commented Apr 11, 2025

Ah, so these #! nix-shell lines are somewhat unusual syntax: it's not a series of commands but an accumulation of command-line arguments to the invocation of nix-shell -- their order doesn't matter. You could also write #! /usr/bin/env nix-shell -i bash -p ... -I ... (if your OS supported it) and that would mean the exact same thing.

The explanation is here: https://nix.dev/manual/nix/2.24/command-ref/nix-shell.html#use-as-a--interpreter

The lines starting with #! nix-shell specify nix-shell options (see above). Note that you cannot write #! /usr/bin/env nix-shell -i ... because many operating systems only allow one argument in #! lines.

But both places could use a brief note to clarify that further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants