nix
Run applications without installation, create development environments, and evaluate Nix expressions. Use when executing packages temporarily, creating isolated environments, debugging expressions, or searching for packages.
安装与使用
请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。
查看来源 ↗使用指南技能说明
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.
# Run a package once
nix run nixpkgs#hello
# Run a package with specific arguments
nix run nixpkgs#cowsay -- "Hello from Nix!"
# Run a command within a shell environment (non-interactive)
nix shell nixpkgs#git nixpkgs#vim --command git --version
# Run long-running applications (e.g., servers): `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
Evaluating Expressions (Debugging)
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
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
#! 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.
使用示例
查看来源仓库中的使用示例与配置说明。
查看来源 ↗来源历史
- 收录时间
- 2026-01-20
- 索引更新时间
- 2026-01-26
- Branch
- main
收录与同步日期属于本站记录。源码修改历史请查看来源仓库。
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!