Files
dot/nix/README.md
2026-02-07 14:23:51 +01:00

136 lines
3.9 KiB
Markdown

# Unified Nix Configuration
This repository contains a modular, flake-based Nix configuration for multiple platforms and hosts. It provides a declarative and reproducible environment using NixOS, nix-darwin, and Home Manager.
## Quick Start Guide
### TL;DR - Should I Use Flakes?
**YES!** ✅ Use flakes because:
1. You get **nixpkgs-unstable** (latest packages) with reproducibility.
2. Your config is in **git** with locked versions (`flake.lock`).
3. It's the **modern, recommended approach** for Nix management.
### Daily Usage
```bash
# Apply changes (NixOS WSL)
sudo nixos-rebuild switch --flake .#work --impure
# Apply changes (macOS)
darwin-rebuild switch --flake .#Martins-MacBook-Pro
# Update packages (weekly/monthly)
nix flake update
# ... then run the switch command for your host
```
## Structure
The configuration is organized into `hosts` and `modules`:
```
.
├── flake.nix # Entry point with all system configurations
├── flake.lock # Locked dependency versions
├── hosts/ # Machine-specific configurations
│ ├── home/
│ │ ├── darwin/ # Martins-MacBook-Pro
│ │ ├── nix/ # Standalone Home Manager for Home
│ │ └── nixos/ # Home NixOS Server
│ └── work/
│ ├── nix/ # Standalone Home Manager for Work
│ └── nixos/ # Work NixOS (WSL)
└── modules/ # Shared reusable modules
├── home/ # Home Manager modules (sh, nvim, tmux, etc.)
└── nixos/ # NixOS-specific modules
```
## Available Configurations
### NixOS
- **work**: WSL-based NixOS environment for work (User: `pan`).
- **home**: Server-based NixOS environment for home (User: `martin`).
### Darwin (macOS)
- **Martins-MacBook-Pro**: nix-darwin configuration for macOS.
### Standalone Home Manager
- **pan@work**: Home Manager for non-NixOS Linux at work.
- **martin@mac**: Home Manager for macOS (without nix-darwin).
## Installation & Usage
### 1. Apply Configuration
Navigate to the repository and run the appropriate command for your system:
**NixOS (Work/WSL):**
```bash
sudo nixos-rebuild switch --flake .#work --impure
```
**Darwin (macOS):**
```bash
darwin-rebuild switch --flake .#Martins-MacBook-Pro
```
**Standalone Home Manager:**
```bash
home-manager switch --flake .#pan@work
```
*Note: The `--impure` flag may be required for certain configurations (like NIX_LD).*
### 2. Updating System Packages
To update all packages to the latest versions from nixpkgs-unstable:
```bash
# Update flake inputs
nix flake update
# Apply the updates
sudo nixos-rebuild switch --flake .#work --impure
```
## Maintenance
### Rollback
If something breaks after an update, you can rollback to the previous generation:
- **NixOS**: `sudo nixos-rebuild switch --rollback`
- **Darwin**: `darwin-rebuild --rollback`
### Cleanup
Remove old generations to free up disk space:
```bash
# Delete generations older than 30 days
sudo nix-collect-garbage --delete-older-than 30d
# Or delete all old generations
sudo nix-collect-garbage -d
```
## Modules Detail
### Home Manager Modules (`modules/home/`)
- **sh.nix**: Zsh configuration with completions and aliases.
- **nvim.nix**: Personalized Neovim setup.
- **tmux.nix**: Terminal multiplexer configuration.
- **git.nix**: Git, Lazygit, and Jujutsu settings.
- **dev.nix**: Development tools, language runtimes, and LLM tool configurations.
- **task.nix**: Taskwarrior and productivity tools.
### NixOS Modules (`modules/nixos/`)
- **common.nix**: Shared system settings for all NixOS hosts.
## Create Convenience Alias
Add these to your shell configuration for faster updates:
```bash
# Quick rebuild (adjust to your host)
alias nr='sudo nixos-rebuild switch --flake .#work --impure'
# Update and rebuild
alias nu='nix flake update && sudo nixos-rebuild switch --flake .#work --impure'
```