# Run a program with Nix

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

```shell title="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.

<Admonition warning title="This could take a while" id="nix-run-loading">
  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][packages]
  from scratch&mdash;or download it from a known [cache]&mdash;and store it in
  the [Nix store][store]. This is in contrast to most [package managers][pkg],
  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.
</Admonition>

## Explanation

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

- It used the `nixpkgs` [flake reference][ref] to pull in some Nix code and targeted the `ponysay` [flake output][output] (more on this later).
- It built the [`ponysay` package][ponysay] and stored the result in the [Nix store][store].
- It ran the executable at `bin/ponysay` from the `ponysay` package.

In Nix, every program is part of a [package][packages].
Packages are built using the [Nix language][derivations].
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`][ffmpeg-pkg] package, for example, provides both [ffmpeg] and [ffprobe].

<Admonition success open title="Install and run in one command" id="nix-run-no-install">
You may have noticed that [`nix run`][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][nix-run-post] on the [Determinate Systems blog][blog].

</Admonition>

**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.

[blog]: https://determinate.systems/posts
[cache]: /concepts/caching
[derivations]: /concepts/nix-language#derivations
[ffmpeg]: https://ffmpeg.org
[ffmpeg-pkg]: https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/libraries/ffmpeg/generic.nix
[ffprobe]: https://ffmpeg.org/ffprobe.html
[nix]: /concepts/nix
[nix-installer]: /concepts/nix-installer
[nix-run]: https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-run
[nix-run-post]: https://determinate.systems/posts/nix-run
[output]: /concepts/flakes#outputs
[packages]: /concepts/packages
[ponysay]: https://github.com/erkin/ponysay
[pkg]: /concepts/package-management
[ref]: /concepts/flakes#references
[store]: /concepts/nix-store