nh
Manage NixOS and Home Manager operations with improved output and cleanup. Use when updating NixOS configurations, managing user environments, cleaning up generations, or performing system maintenance.
安装与使用
请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。
查看来源 ↗使用指南技能说明
nh (Nix Helper) Skill
nh is a CLI tool that simplifies Nix operations, providing a cleaner interface for builds, switches, and garbage collection.
Core Commands
System Updates (NixOS)
Use nh os for managing NixOS configurations. Prefix local paths with path:.
# Build and switch to a configuration (equivalent to nixos-rebuild switch)
nh os switch path:.
# Build and test a configuration (equivalent to nixos-rebuild test)
nh os test path:.
# Build a configuration without switching (equivalent to nixos-rebuild build)
nh os build path:.
# Make configuration the boot default without activating
nh os boot path:.
# Rollback to a previous generation
nh os rollback
# List available generations
nh os info
# Build a NixOS VM image
nh os build-vm path:.
# Load system configuration in a REPL (use tmux for interactive)
tmux new -d -s nh-repl 'nh os repl path:.'
Home Manager Updates
Use nh home for managing Home Manager configurations.
# Build and switch Home Manager configuration
nh home switch path:.
# Build Home Manager configuration without switching
nh home build path:.
# Load Home Manager configuration in a REPL (use tmux for interactive)
tmux new -d -s hm-repl 'nh home repl path:.'
Nix-Darwin (macOS)
Use nh darwin for managing nix-darwin configurations on macOS.
# Build and switch darwin configuration
nh darwin switch path:.
# Build darwin configuration without switching
nh darwin build path:.
Package Search
Search for packages using search.nixos.org:
# Search for packages
nh search ripgrep
Maintenance and Cleanup
nh clean provides a more intuitive way to manage the Nix store and generations.
# Clean all profiles (system + user)
nh clean all --keep-since 7d
# Clean only current user's profiles
nh clean user --keep 5
# Clean a specific profile
nh clean profile /nix/var/nix/profiles/system --keep 3
# Run garbage collection on the Nix store
nh clean all
Common Options
-
--ask: Ask for confirmation before performing actions (Avoid in headless/automated scripts). -
--dry: Show what would happen without making changes. -
--update: Update flake inputs before building.
Best Practices
-
Headless Usage: Avoid using the
--askflag in scripts or automated environments as it requires user interaction. -
Path Inference:
nhautomatically looks for aflake.nixin the current directory if no path is provided. -
Visuals:
nhprovides a more readable "Nom-like" output by default, which is helpful for monitoring build progress in a terminal.
Related Skills
- nix: Use Nix for running applications without installation and evaluating Nix expressions.
- nix-flakes: Leverage Nix Flakes for reproducible builds and project isolation with nh.
使用示例
查看来源仓库中的使用示例与配置说明。
查看来源 ↗来源历史
- 收录时间
- 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!