Files
nixos-config/docs/development-environments.md
T
kiskaadee 3120028147 feat(flake): switch nixpkgs to official channel tarball and pin registry
- Switch nixpkgs input to official zstd tarball from channels.nixos.org
- Update flake.lock with verified tarball release
- Pin nix.registry.nixpkgs.flake to inputs.nixpkgs in modules/system/base.nix
- Update development environment and antigravity documentation examples
2026-09-11 11:59:08 -05:00

3.3 KiB

💻 Declarative Development Environments

This guide shows how to run isolated project environments using nix-shell or devShells alongside direnv and uv to keep the global system environment clean.


⚡ DevShells and nix-shell

Instead of installing packages globally in apps.nix for one-off projects, define them per-project.

1. Classic shell.nix (Nix Channels)

For standard Nix projects, place a shell.nix in your project root:

{ pkgs ? import <nixpkgs> {} }:

pkgs.mkShell {
  nativeBuildInputs = with pkgs; [
    nodejs_20
    yarn
  ];

  shellHook = ''
    echo "Welcome to the Node.js environment!"
  '';
}

Run nix-shell to drop into this isolated shell with node and yarn pre-loaded.

2. Flake-based devShell

For modern Flake projects, declare your devShell inside your flake.nix:

{
  inputs = {
    # Official project-hosted zstd tarball (faster downloads, forge-independent)
    # nixpkgs-unstable is ideal for standalone dev shells
    nixpkgs.url = "https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.zst";
  };

  outputs = { self, nixpkgs }:
    let
      system = "x86_64-linux";
      pkgs = nixpkgs.legacyPackages.${system};
    in {
      devShells.${system}.default = pkgs.mkShell {
        buildInputs = with pkgs; [
          go
          golangci-lint
        ];
      };
    };
}

Run nix develop to enter this environment.


🔄 Automated Shell Loading with direnv

direnv automatically activates your project-specific environment when you cd into its directory.

Configuration

  1. In your project root, create a file named .envrc.
  2. Add one of the following lines based on your setup:
    • For classic projects (shell.nix):
      use nix
      
    • For Flake-based projects (flake.nix):
      use flake
      
  3. Allow the environment to load:
    direnv allow
    

As soon as you step into the directory, direnv populates $PATH and other variables with your Nix-defined tools. Leaving the folder unloads them automatically.


🐍 Python Projects: Nix + uv Workflow

To prevent library conflicts and keep the host system clean, combine Nix (for system-level packages/binaries like C libraries, python compilers) with uv (for project-level Python packages).

  1. Use Nix (devShells or nix-shell) to make Python and system dependencies (like OpenSSL or PostgreSQL drivers) available:
    pkgs.mkShell {
      buildInputs = with pkgs; [
        python311
        uv
        openssl
      ];
    }
    
  2. Use uv inside that environment to manage the virtual environment and install Python-specific libraries cleanly:
    # Create the virtualenv
    uv venv
    
    # Activate the environment
    source .venv/bin/activate
    
    # Install dependencies lightning-fast without polluting system packages
    uv pip install fastapi uvicorn
    
  3. Ensure .envrc loads both the Nix shell and the virtual environment automatically:
    use flake
    layout python
    
    This triggers standard Nix tools and sources .venv/bin/activate simultaneously upon changing directories.