nh

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

nh (Nix Helper)

nh(Nix 辅助工具)

CLI tool that simplifies Nix operations with cleaner interface for builds, switches, and garbage collection.
一款CLI工具,通过更简洁的界面简化Nix操作,涵盖构建、切换和垃圾回收等功能。

Core Commands

核心命令

System Updates (NixOS)

系统更新(NixOS)

Use
nh os
for managing NixOS configurations. Prefix local paths with
path:
.
bash
undefined
使用
nh os
管理NixOS配置。本地路径需添加
path:
前缀。
bash
undefined

Build and switch to a configuration (equivalent to nixos-rebuild switch)

Build and switch to a configuration (equivalent to nixos-rebuild switch)

nh os switch path:.
nh os switch path:.

Build and test a configuration (equivalent to nixos-rebuild test)

Build and test a configuration (equivalent to nixos-rebuild test)

nh os test path:.
nh os test path:.

Build a configuration without switching (equivalent to nixos-rebuild build)

Build a configuration without switching (equivalent to nixos-rebuild build)

nh os build path:.
nh os build path:.

Make configuration the boot default without activating

Make configuration the boot default without activating

nh os boot path:.
nh os boot path:.

Rollback to a previous generation

Rollback to a previous generation

nh os rollback
nh os rollback

List available generations

List available generations

nh os info
nh os info

Build a NixOS VM image

Build a NixOS VM image

nh os build-vm path:.
nh os build-vm path:.

Load system configuration in a REPL (use tmux for interactive)

Load system configuration in a REPL (use tmux for interactive)

tmux new -d -s nh-repl 'nh os repl path:.'
undefined
tmux new -d -s nh-repl 'nh os repl path:.'
undefined

Home Manager Updates

Home Manager 更新

Use
nh home
for managing Home Manager configurations.
bash
undefined
使用
nh home
管理Home Manager配置。
bash
undefined

Build and switch Home Manager configuration

Build and switch Home Manager configuration

nh home switch path:.
nh home switch path:.

Build Home Manager configuration without switching

Build Home Manager configuration without switching

nh home build path:.
nh home build path:.

Load Home Manager configuration in a REPL (use tmux for interactive)

Load Home Manager configuration in a REPL (use tmux for interactive)

tmux new -d -s hm-repl 'nh home repl path:.'
undefined
tmux new -d -s hm-repl 'nh home repl path:.'
undefined

Nix-Darwin (macOS)

Nix-Darwin(macOS)

Use
nh darwin
for managing nix-darwin configurations on macOS.
bash
undefined
使用
nh darwin
管理macOS上的nix-darwin配置。
bash
undefined

Build and switch darwin configuration

Build and switch darwin configuration

nh darwin switch path:.
nh darwin switch path:.

Build darwin configuration without switching

Build darwin configuration without switching

nh darwin build path:.
undefined
nh darwin build path:.
undefined

Package Search

包搜索

Search for packages using search.nixos.org:
bash
undefined
通过search.nixos.org搜索包:
bash
undefined

Search for packages

Search for packages

nh search ripgrep
undefined
nh search ripgrep
undefined

Maintenance and Cleanup

维护与清理

nh clean
provides a more intuitive way to manage the Nix store and generations.
bash
undefined
nh clean
提供了更直观的方式来管理Nix存储和世代。
bash
undefined

Clean all profiles (system + user)

Clean all profiles (system + user)

nh clean all --keep-since 7d
nh clean all --keep-since 7d

Clean only current user's profiles

Clean only current user's profiles

nh clean user --keep 5
nh clean user --keep 5

Clean a specific profile

Clean a specific profile

nh clean profile /nix/var/nix/profiles/system --keep 3
nh clean profile /nix/var/nix/profiles/system --keep 3

Run garbage collection on the Nix store

Run garbage collection on the Nix store

nh clean all
undefined
nh clean all
undefined

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.
  • --ask
    :执行操作前请求确认(在无界面/自动化脚本中避免使用)。
  • --dry
    :显示将要执行的操作但不实际修改。
  • --update
    :构建前更新flake输入。

Best Practices

最佳实践

  • Headless Usage: Avoid using the
    --ask
    flag in scripts or automated environments as it requires user interaction.
  • Path Inference:
    nh
    automatically looks for a
    flake.nix
    in the current directory if no path is provided.
  • Visuals:
    nh
    provides a more readable "Nom-like" output by default, which is helpful for monitoring build progress in a terminal.
  • 无界面使用:在脚本或自动化环境中避免使用
    --ask
    标志,因为它需要用户交互。
  • 路径推断:如果未提供路径,
    nh
    会自动在当前目录查找
    flake.nix
    文件。
  • 可视化输出
    nh
    默认提供更易读的“Nom-like”输出,有助于在终端中监控构建进度。

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.
  • nix:使用Nix无需安装即可运行应用程序,并评估Nix表达式。
  • nix-flakes:结合nh使用Nix Flakes实现可复现构建和项目隔离。