1.4 Your first Nix commands: nix run and nix shell
Lesson 4 of 68 · 5:27
Video chapters
-
0:00 Running Packages with nix run
-
1:51 Using nix shell and PATH Changes
Transcript
Running Packages with nix run
0:00 Let's have a look at our first few nix commands. After we installed nix and checked that it actually works, we are now going to play around with it. Let's start with nix shell first. So when we start a new shell, we can basically say nix run nix packages hashtag hello. And what that does is, from the nix packages repository, it selects the package hello and runs it.
0:31 So there it is. And it's kind of not installed, nothing. It was just run and then basically thrown away. Let's have a quick look at the syntax again. Here what does it actually mean when we say nix packages? Nix packages is a reference to the nix packages registry or to the flakes registry, where nix packages is one entry that points to the latest and greatest checkout of the nix packages GitHub repository. The registry itself is also in a GitHub repository.
1:03 And there it's a JSON file that shows different entries that we can reference. However, this one, basically, you always have to add it. And this hashtag is slightly strange, because typically in shells, the hashtag is a comment. And at this point, this is not a comment. We are basically just using nix packages hashtag hello as a separator at this point.
The full transcript comes with the lesson.
About this lesson
You just installed Nix, now what? This lesson shows the two commands that make Nix useful within minutes: nix run to launch any program from nixpkgs without installing it, and nix shell to open a temporary shell where the tool simply exists. Along the way you learn what nixpkgs#hello actually means, and how to run an older version of a package on purpose.
In this video
- Running a program straight from nixpkgs with
nix run: nothing installed, nothing left behind - What the
#innixpkgs#helloreally is, and where the namenixpkgscomes from (hint: there is a registry) - The small
--detail that decides whether an argument goes to Nix or to the program, a classic beginner trap - Getting an old package version by pointing at a different nixpkgs branch:
ripgrep13 and 15 on the same machine, no conflict - Temporary shells with
nix shell: what happens to yourPATH, how shells nest, a bash trick for several packages at once, and the shorter classicnix-shell -pthe instructor uses daily
After this lesson
You can try out any program from nixpkgs on demand, in the version you want, without installing anything or cleaning up afterwards.