nx-rs provides nx, a CLI for managing Nix configuration repositories and host maintenance tasks.
nx is a workflow-oriented tool for maintaining a Nix config repo from the command line.
It helps you find package definitions, inspect what is installed, make deterministic
manifest edits for package add/remove flows, and manage host-level Nix generations.
The tool is intended for repositories that manage system and home configuration in Nix,
and it uses NX_REPO_ROOT as an override when you want to target a repo other than the
current flake.nix tree.
Host maintenance commands under nx generations are intentionally host-scoped and do not
require a repository root.
For a one-off install, use nix run or nix profile install.
If you want persistent session defaults like NX_REPO_ROOT, prefer the Home Manager path below.
Run without installing:
nix run github:flowerornament/nx-rs -- --helpInstall into your profile:
nix profile install github:flowerornament/nx-rsAdd nx-rs to your Nix configuration repository:
# flake.nix inputs
nx-rs = {
url = "github:flowerornament/nx-rs";
inputs.nixpkgs.follows = "nixpkgs";
};
# package list/module
inputs.nx-rs.packages.${pkgs.system}.defaultThen rebuild:
nix flake lock --update-input nx-rs
sudo /run/current-system/sw/bin/darwin-rebuild switch --flake .This is the recommended install path for declarative Nix users.
For a declarative user-level install, nx-rs now exports a Home Manager
module. It installs nx into home.packages and can optionally export the
same environment variables that drive nx at runtime.
Add the flake input:
nx-rs = {
url = "github:flowerornament/nx-rs";
inputs.nixpkgs.follows = "nixpkgs";
};Then include the module in your Home Manager configuration:
{
imports = [
inputs.nx-rs.homeManagerModules.default
];
programs.nx = {
enable = true;
repoRoot = "/Users/alice/code/nix-config";
autoRefresh = false;
};
}Available module options:
programs.nx.enableprograms.nx.packageprograms.nx.repoRootprograms.nx.autoRefreshprograms.nx.sops.packageprograms.nx.sops.bin
The module only manages binary installation and environment variables. Repo structure, manifests, and command behavior still live in the target Nix config repository itself.
That boundary is intentional:
- the managed repo owns
nxbehavior over your Nix configuration programs.nxowns machine/session defaults only- CLI flags still own one-off overrides
If you use nx secret add, you can wire sops declaratively too:
{
imports = [
inputs.nx-rs.homeManagerModules.default
];
programs.nx = {
enable = true;
sops.package = pkgs.sops;
sops.bin = "${pkgs.sops}/bin/sops";
};
}nx auto-detects the managed repo by walking up from the current working directory until
it finds flake.nix. Set NX_REPO_ROOT only when you want to override that detection:
export NX_REPO_ROOT=/path/to/your/config-repoSome flows can call local AI CLIs when helpful:
install:--engine codex|claudeselects the engine (codexdefault).--model <name>selects the model for the chosen engine.--explainprints extra decision details during install resolution.
remove:--model <name>sets the Claude model used for AI fallback edits.
upgrade:- Prints optional AI-generated change summaries for flake/homebrew updates.
--no-aidisables AI summaries entirely.
Requirements:
codexand/orclaudemust be installed and available onPATHfor the corresponding features.- Authentication and provider-specific environment variables are managed by those CLIs.
nx reads the following environment variables:
| Variable | Required | Default | Purpose |
|---|---|---|---|
NX_REPO_ROOT |
No | auto-detect from cwd / flake.nix |
Absolute/relative path override for the target Nix configuration repository. |
NX_RS_SOPS_BIN |
No | sops |
Override the sops executable used by nx secret add. |
NX_RS_AUTO_REFRESH |
No | enabled | Controls auto-refresh of a local cargo-installed nx binary before rebuild/upgrade. Set to 0, false, or no to disable. |
NO_COLOR |
No | unset | Disables colored output when set. |
TERM |
No | shell/default | If set to dumb, color output is disabled. |
Repository setup and discovery:
# Scan the current repo and write .nx/manifest.toml
nx init
# Show the config location for a package
nx where ripgrep
# Show package distribution across nix/homebrew/mas sources
nx statusPackage changes:
# Bare package names are treated as "install"
nx ripgrep
# Explicit install flows
nx install ripgrep fd
nx install --cask firefox
nx install --mas Tailscale
nx install --dry-run --bleeding-edge neovim
# Remove installed packages
nx remove ripgrep
nx remove --dry-run firefoxRead-only inspection:
nx search ripgrep
nx info ripgrep
nx list --plain
nx installed ripgrep fdSystem and host maintenance:
nx lint
nx rebuild --preflight
nx rebuild
nx upgrade
nx generations status
nx generations plan
nx generations prune --dry-runSecrets:
nx secret add github_token --value-stdin
printf '%s' "$TOKEN" | nx secret add github_token --value-stdinUse command help for the full flag surface:
nx --help
nx help <topic>
nx <command> --helpShows hierarchical help for commands and flags. Use nx help install, nx help secret add, or nx help -- --dry-run when you want the command tree rather than raw clap help.
Scans the current repo and writes .nx/manifest.toml. Use --refresh to rescan and merge with an existing manifest.
Installs one or more packages into the managed repo. If you run nx ripgrep, nx treats the bare token as nx install ripgrep.
- Use
--dry-runto preview edits without writing files. - Use
--yesto skip interactive prompts and accept defaults. - Use
--caskor--masto force macOS package targets. - Use
--bleeding-edge,--nur, or--sourceto bias source selection. - Use
--serviceto offer service scaffolding after install. - Use
--rebuildto rebuild after successful changes. - Use
--engine,--model, and--explainfor AI-assisted routing/edit flows.
Removes installed packages from the managed repo.
- Supports
--dry-runand--yes. - Supports
--modelfor the AI fallback removal path. rmanduninstallare aliases ofremove.
Adds or updates an encrypted secret via sops.
- Accepts a positional key or
--name. - Accepts
--valueor--value-stdin. - Prefer
--value-stdinto avoid leaving secrets in shell history. - Top-level command aliases:
secret,secrets.
Searches package sources without editing the repo.
- Good first step when you are not sure which backend will provide a package.
- Supports
--bleeding-edge,--nur, and--json.
Shows where a package is declared in the managed repo. This is the fastest way to jump to the owning file before a manual edit or review.
Lists installed packages by source bucket.
- Optional source filter:
nix,homebrew, ormas. - Supports
--verbose,--json, and--plain.
Shows package metadata plus candidate source information.
- Useful when deciding between nixpkgs, NUR, flake input, Homebrew, or MAS routes.
- Supports
--json,--bleeding-edge, and--verbose.
Shows a package distribution summary for the managed repo. This is a read-only overview of how packages are split across supported source families.
Checks whether one or more packages are currently installed.
- Supports
--json. - Supports
--show-locationto include file and line matches. - Returns success only when all requested packages are installed.
Checks # nx: routing annotations and keyword overlap across routable .nix files. Use this before reorganizing manifests or adding new routable files.
Reverts modified tracked files via git checkout. Use --yes to skip the confirmation prompt.
Runs nix flake update. Additional args after -- are passed through to the underlying flake update invocation.
Runs repo quality checks. This is the CLI entry point for validating the managed Nix config repository itself.
Runs darwin-rebuild switch for the managed repo.
- Use
--preflightto stop after lint, git, and flake checks without switching. - Additional args after
--pass through to the underlyingdarwin-rebuildcommand.
Runs the full upgrade flow: flake update, Homebrew update/upgrade, rebuild, and git commit.
- Use
--dry-runto preview without mutating files. - Use
--skip-brew,--skip-rebuild, or--skip-committo trim the flow. - Use
--no-aito disable AI-generated summaries and recovery prompts. - Additional args after
--pass through todarwin-rebuild switch.
Host-scoped retention and garbage-collection commands. These work from any directory and do not require a managed repo.
nx generations statusshows discovered nix-darwin and Home Manager generations plus the active retention policy.nx generations planrenders the exact prune and garbage-collection plan without mutating the host.nx generations pruneexecutes that plan, prompting by default.- Important flags:
--keep,--kind,--no-gc,--yes,--dry-run. nx generations prune --dry-runrenders the same plan asnx generations plan.
help,where,list,info,status,installed,search,generations status, andgenerations planare read-only.installandremovesupport--dry-runto preview changes before writing files.generationscommands are host-scoped and work from any directory.- Most commands operate on the current repo root; set
NX_REPO_ROOTonly when you want to override auto-discovery.
Rust is pinned in rust-toolchain.toml (1.93.1).
just help
just doctor
just hooks-install
just compile
just ciLocal install for ad hoc testing:
cargo install --path .Standard gate:
just ciAdditional strict checks:
cargo clippy --workspace --all-targets --all-features -- -D warnings -W clippy::pedantic
just test-systemWork is tracked in bd (./.beads):
bd ready
bd create --title="<task>" --type=task --priority=2
bd close <id>
bd dolt pushMIT.