Agent skill
nix
Runs packages temporarily, creates isolated shell environments, and evaluates Nix expressions. Use when executing tools without installing, debugging derivations, or working with nixpkgs.
Install this agent skill to your Project
npx add-skill https://github.com/knoopx/pi/tree/main/agent/skills/nix
SKILL.md
Nix
Package manager and functional language for reproducible environments.
Quick Start
# Run a package once
nix run nixpkgs#hello
# Create a shell with multiple packages
nix shell nixpkgs#git nixpkgs#vim --command git --version
Running Applications
Run any application from nixpkgs without installing it permanently.
# Run a package with specific arguments
nix run nixpkgs#cowsay -- "Hello from Nix!"
# Run long-running applications: `tmux new -d 'nix run nixpkgs#some-server'`
Formatting
Format Nix files in your project:
# Format current flake
nix fmt
# Check formatting
nix fmt -- --check
Hash Conversion
Convert hashes between formats (replaces deprecated nix hash to-sri/to-base16).
# Convert a nix32 hash to SRI (sha256)
nix hash convert --hash-algo sha256 --from nix32 --to sri 1b8m03r63zqhnjf7l5wnldhh7c134ap5vpj0850ymkq1iyzicy5s
# Convert to nix32 explicitly
nix hash convert --hash-algo sha256 --to nix32 sha256-ungWv48Bz+pBQUDeXa4iI7ADYaOWF3qctBD/YfIAFa0=
Prefetching Hashes
Use prefetch helpers to fetch sources and get the nix32 hash, then convert to SRI if needed.
# Fetch a tarball and print its nix32 hash
nix-prefetch-url --unpack https://example.com/source.tar.gz
# Convert the nix32 hash to SRI for fetchFromGitHub/fetchurl
nix hash convert --hash-algo sha256 --from nix32 --to sri <nix32-hash>
Evaluating Expressions
Since the environment is headless and non-interactive, use nix eval instead of the REPL for debugging.
# Evaluate a simple expression
nix eval --expr '1 + 2'
# Inspect an attribute from nixpkgs
nix eval nixpkgs#hello.name
# Evaluate a local nix file
nix eval --file ./default.nix
# List keys in a set (useful for exploration)
nix eval --expr 'builtins.attrNames (import <nixpkgs> {})'
Searching for Packages
# Search for a package by name or description
nix search nixpkgs python3
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
#! nix shell nixpkgs#bash nixpkgs#curl --command bash
curl -s https://example.com
Or with flakes:
#!/usr/bin/env nix
#! nix shell nixpkgs#python3 --command python3
print("Hello from Nix!")
Troubleshooting
- Broken Builds: Use
nix logto 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-substituteto force a local build if you suspect a bad binary cache. - Why Depends: Use
nix why-depends nixpkgs#hello nixpkgs#glibcto 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.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
conventional-commits
Writes and reviews Conventional Commits commit messages (v1.0.0) to support semantic versioning and automated changelogs. Use when drafting git commit messages, PR titles, release notes, or when enforcing a conventional commit format (type(scope): subject, BREAKING CHANGE, footers, revert).
nix-flakes
Creates reproducible builds, manages flake inputs, defines devShells, and builds packages with flake.nix. Use when initializing Nix projects, locking dependencies, or running nix build/develop commands.
skill-authoring
Writes effective pi skills with proper structure, concise content, and progressive disclosure. Use when creating new skills, improving existing skills, or reviewing skill quality.
gtkx
Build GTK4 desktop applications with GTKX React framework. Use when creating React components that render as native GTK widgets, working with GTK4/Libadwaita UI, handling signals, virtual lists, menus, or building Linux desktop UIs.
nu-shell
Processes structured data through pipelines, filters tables, transforms JSON/CSV/YAML, and defines custom commands. Use when scripting with typed parameters or working with tabular data.
jj-hunk
Programmatic hunk selection for jj (Jujutsu). Use when splitting commits, making partial commits, or selectively squashing changes without interactive UI.
Didn't find tool you were looking for?