nixos-command-not-found
Auto-install missing commands in NixOS environments. Detects NixOS, searches for packages containing the missing command, and re-runs with nix shell. Use when commands fail with "command not found" errors.
$ 설치
git clone https://github.com/clempat/ai-tools-flake /tmp/ai-tools-flake && cp -r /tmp/ai-tools-flake/config/skills/nixos-command-not-found ~/.claude/skills/ai-tools-flake// tip: Run this command in your terminal to install the skill
name: nixos-command-not-found description: Auto-install missing commands in NixOS environments. Detects NixOS, searches for packages containing the missing command, and re-runs with nix shell. Use when commands fail with "command not found" errors.
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
- Delegate everything to nixos agent: Agent finds package AND runs command
- Return command output: Agent provides the actual command result
Implementation Steps
1. Environment Detection
Check if we're in NixOS:
test -d /etc/nixos || test -n "$NIX_STORE"
2. Delegate Complete Task
Use Task tool with nixos agent to handle everything:
Task(
description="Run missing command with nix shell",
prompt="The command '<original-command>' failed with 'command not found'. Please:
1. Search for the NixOS package that provides this command
2. Run the command using 'nix shell nixpkgs#<package> -c <original-command>'
3. Return the actual command output/result",
subagent_type="nixos"
)
3. Return Results
The nixos agent returns the actual command execution result, not just package info.
Examples
Missing tree command
- User runs:
tree /some/path - Error:
zsh: command not found: tree - Detect NixOS environment ✓
- Delegate to nixos agent: "Run 'tree /some/path' with nix shell"
- Agent finds
treepackage, runsnix shell nixpkgs#tree -c tree /some/path - Agent returns: actual directory tree output
Missing jq command
- User runs:
cat data.json | jq '.name' - Error:
command not found: jq - Delegate to nixos agent: "Run 'jq '.name'' with nix shell"
- Agent finds
jqpackage, runs with stdin preserved - Agent returns: actual JSON parsing result
Missing cargo command
- User runs:
cargo build - Error:
command not found: cargo - Delegate to nixos agent: "Run 'cargo build' with nix shell"
- Agent finds
cargopackage, runsnix shell nixpkgs#cargo -c cargo build - Agent returns: actual build output or errors
Edge Cases
Multiple Package Options
Nixos agent handles all selection logic internally:
- Uses nixos MCP tools to find best match
- Considers exact name matches, package descriptions, etc.
- Picks most appropriate option or asks user if truly ambiguous
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
Nixos agent handles this case:
- Detects if already in nix shell
- Still proceeds (might need different package)
- Can inform user about current nix shell context
Error Handling
Package Not Found
Nixos agent handles all error scenarios:
- Tries broader search terms and fallbacks
- Searches programs, options, or suggests alternatives
- Returns helpful error message if no package found
Command Failures
Nixos agent returns actual command results:
- Shows real command output if successful
- Returns actual error messages if command fails
- Distinguishes 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 directoryzsh: command not found: <cmd>bash: <cmd>: command not found
Agent Responsibilities
Nixos agent handles all technical details:
- Maintains current working directory
- Preserves environment variables
- Keeps stdin/stdout/stderr intact
- Shows what package was used
- Provides appropriate feedback
Main Agent Role
Main agent just:
- Detects NixOS environment
- Delegates to nixos agent
- Returns agent's 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
Repository
