# Nix-Based GPU Training Setup

## The Nix Way

To use your GPU the proper Nix way, you need to enable NVIDIA driver support in your NixOS configuration. This allows Nix builds to access CUDA libraries.

### Step 1: Update System Configuration

Add to `/etc/nixos/configuration.nix`:

```nix
{
  # Enable NVIDIA drivers with CUDA support
  hardware.nvidia = {
    modesetting.enable = true;
    nvidiaSettings = true;
    package = config.boot.kernelPackages.nvidiaPackages.stable;
  };

  # Enable OpenGL and CUDA
  hardware.opengl = {
    enable = true;
    driSupport = true;
  };

  # Allow unfree packages (required for NVIDIA)
  nixpkgs.config.allowUnfree = true;
}
```

### Step 2: Rebuild System

```bash
sudo nixos-rebuild switch
```

### Step 3: Use the GPU Shell

Once rebuilt, you have two options:

#### Option A: Use devenv (if we integrate it)

```bash
devenv shell gpu-training
```

#### Option B: Use the flake directly

```bash
# Enter development environment
nix develop

# Run smoke test
nix run .#smoke-test
```

### Why This Is Necessary

Nix isolates builds from the host system. For CUDA to work:
1. The NVIDIA driver must be in the Nix store
2. Libraries must be exposed via `LD_LIBRARY_PATH`
3. NixOS must configure this automatically via `hardware.opengl.enable = true`

Without this, PyTorch can't find `libcuda.so` even though `nvidia-smi` works.

## Current Status

Your system has:
- ✅ NVIDIA RTX 6000 Ada 48GB
- ✅ Driver 580.142 installed
- ❌ NixOS NVIDIA integration not configured

## Alternative: Hybrid Approach

If you can't modify system configuration, use the manual venv approach in `docs/LOCAL-GPU-QUICKSTART.md`. It's less pure but works immediately.
