Check out FlakeHub — the best place to discover and publish Nix flakes, from Determinate Systems.

Sign up for the Determinate Systems mailing list

* indicates required

2. Run a program with Nix

Quick start / Run a program with Nix
Guide 2 of 8
In this guide

Use the nix run command to run a program from Nixpkgs

Learn about Nix flakes and packages

Download and run a program from Nixpkgs

In the last section, we installed Nix using the Determinate Nix Installer. Now we can dive in and use Nix to run an actual program. Let’s try running the delightful ponysay:

Pass a string to Ponysay
echo "Hello Nix" | nix run "https://flakehub.com/f/NixOS/nixpkgs/*#ponysay"

:rocket: Success! You should see a charming equine greeting in your console.

This could take a while

The first time you run a program using nix run it’s likely to be a slow operation. That’s because Nix needs to build the program’s package from scratch—or download it from a known cache—and store it in the Nix store. This is in contrast to most package managers, which install things more quickly because they download pre-built archives like tarballs. Future nix run invocations should be instantaneous, as Nix doesn’t need to build the package again.

Explanation

What happened here? The Nix CLI did a few things:

In Nix, every program is part of a package. Packages are built using the Nix language. The ponysay package has a single program (also called ponysay) but packages can contain multiple programs as well as man pages, configuration files, and more. The ffmpeg package, for example, provides both ffmpeg and ffprobe.

Install and run in one command

You may have noticed that nix run doesn’t require anything like a nix install command. This makes it handy for use cases like shell scripting or experimenting with in-progress tools.

For more on nix run, see Using Nix to run software with no installation steps on the Determinate Systems blog.

Congrats! You’ve just run a program using the Nix CLI and learned a little bit about some core Nix concepts. You’re now ready to explore Nix development environments.