NixOS Command Not Found Handler
Automatically handles "command not found" errors in NixOS environments by searching for packages and retrying with nix shell.
When to Use
Activate this skill when:
- •Command fails with "command not found" or "No such file or directory"
- •User is in NixOS environment (detected by
/etc/nixosexistence orNIX_STOREenv var) - •Command appears to be a standard Unix tool or known package
Workflow
- •Detect NixOS environment: Check for
/etc/nixosorNIX_STOREenv var - •Extract command name: Get the missing command from error output
- •If error output already suggests a nix shell: Run that exact command
- •Else search locally: Use
nix search nixpkgs <cmd>and pick best match - •Run via nix shell:
nix shell nixpkgs#<package> -c <original-command> - •Delegate only if needed: If no match or ambiguous, delegate to nixos agent
Implementation Steps
1. Environment Detection
Check if we're in NixOS:
test -d /etc/nixos || test -n "$NIX_STORE"
2. Use Suggested nix shell (if present)
If the error output already includes a recommended nix shell nixpkgs#... -c ..., run it as-is.
3. Local Search + Run
Search locally and pick best match from plain text output:
nix search nixpkgs <cmd>
Selection order:
- •Exact attr path equals cmd
- •Attr path contains cmd
- •Description contains cmd
Then run:
nix shell nixpkgs#<package> -c <original-command>
4. Delegate When Needed
If no match or too many ambiguous results, delegate to nixos agent to resolve.
Examples
Missing tree command
- •User runs:
tree /some/path - •Error:
zsh: command not found: tree - •Detect NixOS environment ✓
- •Run
nix search nixpkgs tree - •Pick
treepackage, runnix shell nixpkgs#tree -c tree /some/path - •Return: actual directory tree output
Missing jq command
- •User runs:
cat data.json | jq '.name' - •Error:
command not found: jq - •Run
nix search nixpkgs jq - •Pick
jqpackage, run with stdin preserved - •Return: actual JSON parsing result
Missing cargo command
- •User runs:
cargo build - •Error:
command not found: cargo - •Run
nix search nixpkgs cargo - •Pick
cargopackage, runnix shell nixpkgs#cargo -c cargo build - •Return: actual build output or errors
Suggested nix shell already provided
- •Error output includes:
use nix shell nixpkgs#ripgrep -c rg ... - •Run that exact command
- •Return command output
Edge Cases
Multiple Package Options
Try local selection order first. If still ambiguous, delegate to nixos agent.
Complex Commands
Nixos agent handles command complexity:
- •Preserves pipes, redirects, and shell syntax
- •Uses appropriate shell escaping when needed
- •Maintains stdin/stdout/stderr as expected
Already in Nix Shell
Still proceed (might need different package). Inform user about current nix shell context.
Error Handling
Package Not Found
If local search fails, delegate to nixos agent for broader search/fallbacks.
Command Failures
Return actual command results. Distinguish between "package not found" vs "command failed".
Integration Notes
Detection Triggers
Monitor for these error patterns:
- •
command not found: <cmd> - •
<cmd>: No such file or directory - •
zsh: command not found: <cmd> - •
bash: <cmd>: command not found
Agent Responsibilities
Only delegate when local search fails or ambiguous. When delegated, nixos agent handles:
- •Maintains current working directory
- •Preserves environment variables
- •Keeps stdin/stdout/stderr intact
- •Shows what package was used
- •Provides appropriate feedback
Main Agent Role
- •Detects NixOS environment
- •Runs suggested nix shell if present
- •Else runs local
nix search - •Delegates only if needed
- •Returns command results to user
Configuration
Excluded Commands
Don't handle these (likely typos or not packages):
- •Single letters:
a,b,x - •Common typos:
sl,gerp - •Shell builtins that failed:
cd,export
Channel Preference
- •Default to
nixpkgs#(follows system channel) - •Could use
nixpkgs/unstable#for newest versions - •Respect user's flake configuration if detected