nix-run
Run applications in isolated Nix environments
TLDR
Run the default application in the flake in the current directory
Run a command whose name matches the package name from nixpkgs (if you want a different command from that package, see tldr nix shell)
Run a command with provided arguments
Run from a remote repository
Run from a remote repository using a specific tag, revision or branch
Run from a remote repository specifying a subdirectory and a program
Run the flake of a GitHub pull request
SYNOPSIS
nix run [options] expression
PARAMETERS
--expr
Evaluate
A Nix expression to evaluate. It can be a string containing Nix code or a path to a Nix file.
-f, --file
Load a Nix expression from
--impure
Allow access to mutable paths such as /etc, /var, and /tmp.
--option
Set the Nix configuration setting
-v, --verbose
Increase verbosity level.
--help
Show help message.
DESCRIPTION
The nix-run command allows you to execute Nix expressions or pre-defined commands within a Nix environment. It's a powerful tool for quickly testing Nix code, running scripts, and managing dependencies without permanently modifying your system. The command facilitates isolated builds by creating a temporary Nix environment for each execution. This guarantees reproducibility and prevents interference with other parts of your system.
It supports running simple Nix expressions directly on the command line or executing commands defined in Nix files or packages. nix-run can also be used to execute commands from Git repositories, URLs, or local paths. The ability to specify input sources and environment variables makes it highly customizable. The command offers a convenient way to use software packages managed by Nix without explicitly installing them globally. It's particularly useful for development, testing, and continuous integration workflows, providing a consistent and isolated environment for running your code.
CAVEATS
The exact behavior of nix-run can vary slightly depending on the Nix version. Running impure code can compromise reproducibility. Security precautions should be considered while using --impure flag.
EXAMPLES
nix run 'pkgs.hello': Runs the 'hello' package.
nix run ./my-script.nix: Runs the script defined in 'my-script.nix'.
nix run 'with import
HISTORY
nix-run emerged as part of the Nix package manager, aiming to simplify the execution of Nix expressions and commands. It builds upon Nix's core principles of reproducibility and isolation, providing a convenient way to execute code in a consistent environment.