| name | nix |
| description | Run packages temporarily, create isolated shell environments, and evaluate Nix expressions. Use when executing tools without installing, debugging derivations, or searching nixpkgs. |
Nix Skill
Nix is a powerful package manager and functional programming language. This skill covers common operations like running apps on-the-fly and managing environments.
Running Applications
You can run any application from nixpkgs without installing it permanently.
nix run nixpkgs#hello
nix run nixpkgs#cowsay -- "Hello from Nix!"
nix shell nixpkgs#git nixpkgs#vim --command git --version
Formatting
Format Nix files in your project:
nix fmt
nix fmt -- --check
Evaluating Expressions (Debugging)
Since the environment is headless and non-interactive, use nix eval instead of the REPL for debugging.
nix eval --expr '1 + 2'
nix eval nixpkgs#hello.name
nix eval --file ./default.nix
nix eval --expr 'builtins.attrNames (import <nixpkgs> {})'
Searching for Packages
nix search nixpkgs python3
Common Nix Language Patterns
Variables and Functions
# Let binding
let
name = "Nix";
in
"Hello ${name}"
# Function definition
let
multiply = x: y: x * y;
in
multiply 2 3
Attribute Sets
{
a = 1;
b = "foo";
}
Shebang Scripts
Use Nix as a script interpreter:
#!/usr/bin/env nix
curl -s https://example.com
Or with flakes:
#!/usr/bin/env nix
print("Hello from Nix!")
Troubleshooting
- Broken Builds: Use
nix log to see the build output of a derivation.
- Dependency Issues: Use
nix-store -q --references $(which program) to see what a program depends on.
- Cache issues: Add
--no-substitute to force a local build if you suspect a bad binary cache.
- Why depends: Use
nix why-depends nixpkgs#hello nixpkgs#glibc to see dependency chain.
Related Skills
- nix-flakes: Use Nix Flakes for reproducible builds and dependency management in Nix projects.
- nh: Manage NixOS and Home Manager operations with improved output using nh.
Related Tools
- search-nix-packages: Search for packages available in the NixOS package repository.
- search-nix-options: Find configuration options available in NixOS.
- search-home-manager-options: Find configuration options for Home Manager.