![Forrest logo](/images/logo.png)
nix3-run:tldr:b82ee
The nix run
command is used in the Nix package manager to execute a program or script within a specified environment. It ensures that the required dependencies for the program are properly installed and available before running it.
When you run nix run
, you provide it with the name or path of the program or script you want to execute, along with any necessary options or arguments. Nix will then create a temporary environment by fetching and building the required dependencies, and finally running the program within that environment.
For example, if you wanted to run a Python script called my_script.py
using the Nix package manager, you would execute:
nix run nixpkgs.python3 --command "python my_script.py"
This command tells Nix to fetch and install the python3
package from the nixpkgs
collection (which provides a large set of pre-built packages). Once the package is installed, the python
command is executed with the my_script.py
file as an argument, running the script within the Nix-managed environment.
Using nix run
ensures that the program is executed in an isolated environment with all necessary dependencies, helping to prevent issues related to missing or incompatible libraries.