Nix Workstation: Declarative Dev Environment with Nix Flakes & Home Manager

Nov 4, 2025

🧩 Nix Workstation β€” Cobra’s Declarative Dev Environment

A fully reproducible workstation built with Nix flakes and Home Manager.
Features:

  • Zsh + Oh-My-Zsh + Powerlevel10k
  • Autosuggestions & Syntax Highlighting
  • Neovim with lazy.nvim, Treesitter, and LSPs
  • Dev tools (Git, Bat, Eza, Fd, Ripgrep, Fzf, Tmux, Lazygit, etc.)
  • Node 22, Python 3.12, Prettier, Terraform, Docker, AWS CLI
  • ChatGPT CLI alias (chat) via npx
  • Direnv + Flakes + Home Manager integration

πŸš€ Quick Start on a New Machine

  1. Install Nix

    sh <(curl -L https://nixos.org/nix/install) --no-daemon
    mkdir -p ~/.config/nix
    echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf
    
  2. Clone this repo

    git clone https://github.com/YOURUSERNAME/nix-tools.git
    cd nix-tools
    
  3. Activate Home Manager

    nix run home-manager/master -- switch --flake .#cobra@linux
    
  4. Start your new shell

    exec zsh
    

    Powerlevel10k will open its first-time setup wizard.


🧠 Development Shell

Enter your pinned dev environment:

nix develop

Inside you’ll find:

  • Node 22, npm, and pip
  • Language servers (TypeScript, Python, Bash, Lua, YAML)
  • Terraform, kubectl, AWS CLI
  • Aliases and OMZ prompt
  • chat alias for ChatGPT CLI (via npx)

To leave the shell:

exit

πŸ”‘ OpenAI API Key

Create a private key file (do not commit this):

echo 'export OPENAI_API_KEY="sk-...your-key..."' > ~/.openai_api_key
echo 'export TOKEN="$OPENAI_API_KEY"' >> ~/.openai_api_key
chmod 600 ~/.openai_api_key

Reload your shell:

exec zsh

Test ChatGPT:

chat "Write a Nix expression that prints hello world"

βš™οΈ Maintenance

Update all inputs (nixpkgs + Home Manager):

nix flake update
git add flake.lock
git commit -m "update nixpkgs + home-manager"

Re-apply configuration:

nix run home-manager/master -- switch --flake .#cobra@linux

🧹 Troubleshooting

IssueFix
powerlevel10k not foundRun make link-p10k or re-apply HM
direnv conflictRemove old profile installs: nix profile remove direnv nix-direnv
terraform unfree errorallowUnfree = true already set in flake
ChatGPT CLI says TOKEN missingEnsure both OPENAI_API_KEY and TOKEN are exported

πŸ’‘ Tips

  • nd alias β†’ opens zsh in dev shell (nix develop -c zsh)
  • nix fmt β†’ formats your flake
  • nix flake show β†’ inspect available outputs
  • home-manager news β†’ view Home Manager changelog

🧰 Stack Summary

ComponentManaged byNotes
ShellHome ManagerZsh + OMZ + p10k
EditorHome ManagerNeovim (lazy.nvim + LSPs)
CLIsHome ManagerGit, Eza, Bat, Fzf, Ripgrep, etc.
LanguagesDevShellNode 22, Python 3.12
AIAliaschat β†’ ChatGPT CLI
ConfigFlakeOne file (flake.nix) = entire setup

πŸ”’ Reproducibility

Everything except your API key is declarative.
To recreate this environment anywhere:

curl -L https://nixos.org/nix/install | sh -s -- --no-daemon
echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf
git clone https://github.com/YOURUSERNAME/nix-tools.git
cd nix-tools
nix run home-manager/master -- switch --flake .#cobra@linux
exec zsh

Enjoy your reproducible dev environment βš™οΈπŸ’€

RSS
https://justin-napolitano.com/posts/atom.xml