From c2ab7620b09141927f03673f671161c31e76da3a Mon Sep 17 00:00:00 2001 From: kiskaadee Date: Sun, 13 Sep 2026 02:26:59 -0500 Subject: [PATCH] docs: restructure into operational manual and document DMS desktop initialization --- README.md | 28 ++-- docs/adding-software.md | 98 ++++++++++++++ docs/antigravity.md | 221 ------------------------------- docs/configuration.md | 94 +++++++++++++ docs/desktop.md | 108 +++++++++++++++ docs/development-environments.md | 112 ---------------- docs/getting-started.md | 125 +++++++++++++++++ docs/networking.md | 90 +++++++++++++ docs/package-and-secrets.md | 62 --------- docs/reference/antigravity.md | 43 ++++++ docs/reference/neovim.md | 54 ++++++++ docs/reference/shell.md | 59 +++++++++ docs/reference/tmux.md | 49 +++++++ docs/secrets-management.md | 69 ---------- docs/secrets.md | 90 +++++++++++++ docs/system-lifecycle.md | 97 ++++++++++++++ docs/system-maintenance.md | 79 ----------- docs/tmux.md | 72 ---------- 18 files changed, 925 insertions(+), 625 deletions(-) create mode 100644 docs/adding-software.md delete mode 100644 docs/antigravity.md create mode 100644 docs/configuration.md create mode 100644 docs/desktop.md delete mode 100644 docs/development-environments.md create mode 100644 docs/getting-started.md create mode 100644 docs/networking.md delete mode 100644 docs/package-and-secrets.md create mode 100644 docs/reference/antigravity.md create mode 100644 docs/reference/neovim.md create mode 100644 docs/reference/shell.md create mode 100644 docs/reference/tmux.md delete mode 100644 docs/secrets-management.md create mode 100644 docs/secrets.md create mode 100644 docs/system-lifecycle.md delete mode 100644 docs/system-maintenance.md delete mode 100644 docs/tmux.md diff --git a/README.md b/README.md index dc94186..644b5b9 100644 --- a/README.md +++ b/README.md @@ -92,14 +92,15 @@ graph TD Sensitive credentials (tokens, private keys) are managed using `sops` and `age`. Plaintext secrets are never committed to version control. -For bootstrapping, key generation, and decryption workflows, consult the [Secrets Management Guide](docs/secrets-management.md). +For bootstrapping, key generation, and decryption workflows, consult the [Secrets Management Guide](docs/secrets.md). --- ## πŸš€ Quick Start / Deployment -### 1. Installation -Clone the configuration repository into your home folder: +### 1. Installation & Bare-Metal Recovery +For fresh machine setup and disaster recovery, follow the [Getting Started & Disaster Recovery Runbook](docs/getting-started.md). + ```bash git clone https://github.com/kiskaadee/nixos-config.git ~/Config cd ~/Config @@ -121,11 +122,18 @@ sudo nixos-rebuild switch --flake ~/Config#laptop --- -## πŸ“š Reference Documentation +## πŸ“š Workstation Operations Manual -* [Package & Secrets Workflow Guide](docs/package-and-secrets.md) β€” Steps for adding custom applications and managing secrets. -* [System Maintenance Guide](docs/system-maintenance.md) β€” Instructions for safe system updates, health checking, and garbage collection. -* [Declarative Development Environments](docs/development-environments.md) β€” How to use nix-shell, devShells, direnv, and uv for project isolation. -* [Secrets Management Guide](docs/secrets-management.md) β€” GitOps secrets workflow using SOPS and age for homelab Core management. -* [Tmux Terminal Multiplexer](docs/tmux.md) β€” Fast navigation bindings, layouts, and pane splits guide. -* [Google Antigravity Setup](docs/antigravity.md) β€” Technical instructions for packaging and using the Antigravity agent CLI on NixOS. +* [Getting Started & Disaster Recovery](docs/getting-started.md) β€” Bare-metal install, partition scheme, hardware config, and desktop bootstrap. +* [Adding Software](docs/adding-software.md) β€” Decision tree for package placement, `home.packages` vs `programs.foo`, and unfree packages. +* [Configuration Workflow](docs/configuration.md) β€” Day-to-day editing, dry-build validation, testing, and dotfiles management. +* [System Lifecycle & Rebuilds](docs/system-lifecycle.md) β€” Nix rebuild pipeline, generations, bootloader rollback, and garbage collection. +* [Desktop Environment (Niri + DMS)](docs/desktop.md) β€” Compositor stack, declarative vs runtime state boundary, and master shortcut reference. +* [Secrets Management & Homelab GitOps](docs/secrets.md) β€” Operator authoring tooling on laptop vs runtime decryption on Core. +* [Networking & Remote Access](docs/networking.md) β€” NetworkManager, OpenSSH client profiles, and LAN remote access. + +### Reference Manuals +* [Interactive Shell Environment](docs/reference/shell.md) β€” Bash configuration, Starship prompt, and modular shell scripts. +* [Tmux Terminal Multiplexer](docs/reference/tmux.md) β€” Session workflows, layouts, and navigation keybindings. +* [Neovim Editor Architecture](docs/reference/neovim.md) β€” Neovim Lua configuration, LSPs, treesitter, and formatting. +* [Antigravity AI Agent Setup](docs/reference/antigravity.md) β€” Constitution, change protocols, and tooling integration. diff --git a/docs/adding-software.md b/docs/adding-software.md new file mode 100644 index 0000000..f13b7ef --- /dev/null +++ b/docs/adding-software.md @@ -0,0 +1,98 @@ +# πŸ“¦ Adding Software: Placement & Packaging Guide + +This guide defines the architectural decision tree for introducing new software, packages, or services into the workstation configuration. + +--- + +## 1. Package Placement Decision Tree + +When adding a tool or application, follow this priority hierarchy: + +```text +Is it a kernel module, hardware driver, or root systemd daemon? + β”œβ”€β”€ YES ──> system/core.nix or system/hardware.nix + └── NO + β”‚ +Is it a GUI application or desktop utility? + β”œβ”€β”€ YES ──> home/desktop.nix + └── NO + β”‚ +Is it a compiler, LSP, language runtime, or dev tool? + β”œβ”€β”€ YES ──> home/dev.nix + └── NO ──> home/shell.nix (CLI tools, shell integration) +``` + +--- + +## 2. Directory Placement Reference + +| File | Scope | Examples | +| :--- | :--- | :--- | +| **`system/core.nix`** | Root OS fundamentals | Kernel params, OpenSSH daemon, locale, user definitions, Nix-LD | +| **`system/hardware.nix`** | Hardware daemons & root services | PipeWire, Docker, Bluetooth (`bluez`), Power management (`tlp`), CUPS printing | +| **`system/desktop.nix`** | Display server & greeter | Niri compositor enablement, DMS greeter, greetd, system typography/fonts | +| **`home/desktop.nix`** | User graphical applications | Zen Browser, Zed, Obsidian, LibreOffice, GIMP, MPV, grim/slurp, DankSearch | +| **`home/dev.nix`** | Toolchains & development | Rust, Python, Node, Go, language servers (pyright, rust-analyzer), Antigravity, sops/age CLI | +| **`home/shell.nix`** | Interactive shell & CLI tools | Bash, Tmux, Git, Starship, Delta, Fastfetch, ripgrep, fzf, bat, jq, eza | + +--- + +## 3. Package Syntax Styles: When to Use What + +### Pattern A: Simple Package List (`home.packages`) +Use when the tool requires no specialized shell wrappers or generated dotfiles: + +```nix +# Example in home/desktop.nix or home/shell.nix +home.packages = with pkgs; [ + ripgrep + htop + jq +]; +``` + +### Pattern B: Home Manager Program Module (`programs.`) +Use when Home Manager provides an upstream module that configures shell completions, systemd user services, or dotfiles: + +```nix +# Example in home/shell.nix +programs.tmux = { + enable = true; + shortcut = "a"; + terminal = "tmux-256color"; +}; +``` + +*Advantage*: Modules handle initialization scripts, environment variables, and shell aliases automatically. + +### Pattern C: Custom Compiled Scripts (`pkgs.writeScriptBin`) +Use when distributing a bespoke script or python tool into the user's `$PATH`: + +```nix +# Example in home/desktop.nix +let + recordScript = pkgs.writeScriptBin "record" (builtins.readFile ./scripts/record.sh); +in +{ + home.packages = [ recordScript ]; +} +``` + +--- + +## 4. Handling Unfree Software + +Unfree packages are permitted globally in `system/core.nix` and `home/default.nix`: + +```nix +nixpkgs.config.allowUnfree = true; +``` + +You do not need to configure per-package unfree predicate overrides unless isolating builds. + +--- + +## 5. What NOT to Add to this Repository + +1. **Homelab Server Daemons**: Production services (Traefik, DDNS monitors, public web services, databases) belong exclusively in the [`Core`](file:///home/kiskaadee/Projects/active/homelab/Core) repository. +2. **Ephemeral Project Dependencies**: Rather than polluting `home/dev.nix` with temporary project dependencies, create a dedicated `flake.nix` or `shell.nix` in that project's directory and use `direnv`. diff --git a/docs/antigravity.md b/docs/antigravity.md deleted file mode 100644 index 6f9c107..0000000 --- a/docs/antigravity.md +++ /dev/null @@ -1,221 +0,0 @@ -# ❄️ NixOS Installation Guide: Google Antigravity & Antigravity-v2 Apps - -Google Antigravity is a next-generation agentic coding companion and IDE helper. While installation on standard Linux distributions is straightforward, NixOS's unique, purely functional model requires a different approach. Because Antigravity is distributed as a **closed-source pre-compiled binary**, running it directly on NixOS causes immediate failures due to the absence of the Filesystem Hierarchy Standard (FHS). - -This guide explains the underlying problem, technical challenges, packaging strategies, and step-by-step configuration details for integrating Antigravity into a modular NixOS setup. - ---- - -## πŸ›‘ 1. Problem Statement - -On standard Linux distributions (e.g., Ubuntu, Arch), binaries rely on hardcoded paths to load dynamic linkers and shared libraries: -- Dynamic linker/interpreter path (e.g., `/lib64/ld-linux-x86-64.so.2`) -- System libraries (e.g., `/lib`, `/usr/lib`, `/usr/lib64`) - -NixOS breaks away from the FHS. It features a read-only store located at `/nix/store/` where every package is isolated under a unique cryptographic hash. As a result: -1. **Dynamic Linker Failure**: The operating system will immediately refuse to run an unpatched binary because the path to the interpreter `/lib64/ld-linux-x86-64.so.2` does not exist. This results in the cryptic error: - ```bash - bash: ./antigravity: No such file or directory - ``` -2. **Library Resolution Failure**: Even if the dynamic linker is patched, the binary will fail at runtime when trying to locate dynamic dependencies (`.so` files) that are not present in standard system directories. - ---- - -## ⚑ 2. The Technical Challenges - -Packaging Antigravity on NixOS introduces three main challenges: - -### A. Closed-Source Binary Delivery -Because Google Antigravity is proprietary, we cannot compile it from source code. Nix cannot automatically resolve compile-time configurations or inject dependency paths during a compilation phase. Instead, we must patch the pre-compiled binary directly or wrap it in a containerized environment. - -### B. The FHS Sandbox vs. `sudo` Permissions -Historically, Electron applications on NixOS have been packaged using `buildFHSEnv` which sets up a virtual FHS directory layout using `bubblewrap`. -While this is effective for running the app, it sets the kernel's **`no new privileges`** flag. -> [!WARNING] -> If you run Antigravity inside an FHS environment, the integrated terminal **will not support `sudo`**. Running any command requiring elevated privileges (like `sudo nixos-rebuild switch`) will fail immediately because of the bubblewrap restrictions. - -### C. Chromium Runtime Dependency -Antigravity depends on an external browser engine (Google Chrome or Chromium) to render certain previews and dashboards. It expects standard executables like `google-chrome-stable` or `chromium` to be available in the path, and requires proper environment hooks (`CHROME_BIN` and `CHROME_PATH`) to connect to them. - -### D. Hardcoded Electron Scripts -Inside the packaged Electron archive (`asar`), scripts like `@vscode/sudo-prompt` contain hardcoded paths to system executables (e.g., `/usr/bin/pkexec` or `/bin/bash`), which do not exist on NixOS. - ---- - -## πŸ› οΈ 3. Packaging Strategy & Implementation - -The community-maintained repository `jacopone/antigravity-nix` implements a dual-mode package design. A Mermaid diagram below illustrates how dependencies and runtime paths are resolved: - -```mermaid -graph TD - A[Upstream Tarball/Binary] --> B{Package Target} - - B -->|google-antigravity-cli| C[autoPatchelfHook] - C -->|Patch ELF Interpreter & RPATH| D[Exec: agy] - - B -->|google-antigravity| E{useFHS?} - - E -->|true: Default FHS| F[buildFHSEnv Sandbox] - F -->|Virtual /lib & /usr/lib| G[Runs Unpatched Binary] - G -->|Limitation| H[sudo fails in Integrated Terminal] - - E -->|false: Non-FHS| I[autoPatchelfHook + makeWrapper] - I -->|Patch dynamic links & set LD_LIBRARY_PATH| J[Runs Native Nix Package] - J -->|Benefit| K[sudo works in Integrated Terminal] -``` - -### Strategy Details: - -| Component / Mode | Strategy Used | Technical Implementation | Rationale | -| :--- | :--- | :--- | :--- | -| **CLI (`google-antigravity-cli`)** | Binary Patching | Uses `autoPatchelfHook` to overwrite ELF interpreter and inject dependencies into `RPATH`. Renames package binary to `agy`. | High performance, low footprint, integrates natively with any shell configuration without overhead. | -| **GUI App (`google-antigravity`)** | `buildFHSEnv` (FHS) | Creates a virtual FHS root using bubblewrap. Mounts critical system configuration mounts (`/etc/nixos`, `/etc/xdg`) and wraps standard runtime libs. | High compatibility. Guaranteed to run on all setups because the binary acts as if it is on a standard Ubuntu system. | -| **GUI App (`google-antigravity-no-fhs`)** | Native Wrapping | Patches system libraries via `autoPatchelfHook` and uses `makeWrapper` to propagate environment variables (`LD_LIBRARY_PATH`, `CHROME_BIN`). | **Recommended for developers.** Avoids sandbox privilege restrictions, allowing `sudo` commands inside the integrated terminal. | - -#### Automated File Patching -To fix the hardcoded script paths within the Electron components, the flake unpacks the application archives during the build phase: -1. It extracts `resources/app/node_modules.asar` using `asar`. -2. It patches `@vscode/sudo-prompt/index.js` to redirect `/usr/bin/pkexec` -> `/run/wrappers/bin/pkexec` and `/bin/bash` -> Nix store's native `bash` interpreter. -3. It packages it back into the `.asar` file structure. - ---- - -## πŸ“‹ 4. Step-by-Step Installation Guide - -Follow these steps to integrate the Antigravity package suite declaratively into your NixOS configuration using inputs and Home Manager. - -### Step 1: Declare the Input in `flake.nix` - -Add `antigravity-nix` to your flake inputs in `flake.nix`. Ensure that you lock its inputs to follow your system's `nixpkgs` channel for consistency: - -```nix -# flake.nix -{ - description = "My NixOS Configuration"; - - inputs = { - # Official project-hosted channel tarball - nixpkgs.url = "https://channels.nixos.org/nixos-unstable/nixexprs.tar.zst"; - - # Community Flake for Google Antigravity - antigravity = { - url = "github:jacopone/antigravity-nix"; - inputs.nixpkgs.follows = "nixpkgs"; # Keeps dependencies in sync - }; - }; - - outputs = { self, nixpkgs, antigravity, ... }@inputs: { - # System outputs (e.g. nixosConfigurations.laptop) - }; -} -``` - ---- - -### Step 2: Configure System Packages or Home Manager - -You can inject the packages using standard package inputs in your configurations: - -#### Option A: Home Manager Integration (Recommended) -This matches your system's user setup. Add the required package to your developer tools module (e.g., `home/dev.nix`). - -> [!NOTE] -> In this repository's default configuration, only the CLI helper (`google-antigravity-cli`) is installed. The GUI apps (`google-antigravity` and `google-antigravity-no-fhs`) are optional and omitted by default. - -```nix -# home/dev.nix -{ inputs, pkgs, ... }: - -{ - home.packages = with pkgs; [ - # 1. Install the CLI tool (accessible via 'agy') - inputs.antigravity.packages.${pkgs.stdenv.hostPlatform.system}.google-antigravity-cli - - # 2. (Optional) Install the GUI application (uncomment to enable) - # Choose google-antigravity-no-fhs to support sudo in terminal, or google-antigravity for standard FHS. - # inputs.antigravity.packages.${pkgs.stdenv.hostPlatform.system}.google-antigravity-no-fhs - - # 3. (Optional) Install the legacy IDE component (uncomment to enable) - # inputs.antigravity.packages.${pkgs.stdenv.hostPlatform.system}.google-antigravity-ide-no-fhs - ]; -} -``` - -#### Option B: Global System Packages (`configuration.nix`) -To make the application available to all users on the host machine: - -```nix -# configuration.nix -{ inputs, pkgs, ... }: - -{ - environment.systemPackages = [ - # System-wide installation - inputs.antigravity.packages.x86_64-linux.google-antigravity-cli - inputs.antigravity.packages.x86_64-linux.google-antigravity-no-fhs - ]; -} -``` - ---- - -### Step 3: Enable Unfree Packages -Since Google Antigravity and Chrome are proprietary, NixOS will refuse to build the configuration unless unfree packages are explicitly allowed. Ensure this is configured: - -```nix -# configuration.nix or base.nix -{ - nixpkgs.config.allowUnfree = true; -} -``` - ---- - -## πŸ› οΈ 4. Build and Switch - -Run the rebuild switch script or alias for your machine target: - -```bash -# Rebuild the system -sudo nixos-rebuild switch --flake ~/Config#laptop -``` - ---- - -## ⚑ 5. Verification & Alternate Runs - -### Run Without Installing -If you want to run any of the components without modifying your configuration permanently, you can use the `nix run` command directly: - -* **Launch the main CLI tool (`agy`):** - ```bash - nix run github:jacopone/antigravity-nix#google-antigravity-cli -- --help - ``` -* **Launch the GUI application (FHS):** - ```bash - nix run github:jacopone/antigravity-nix#google-antigravity - ``` -* **Launch the GUI application (Non-FHS):** - ```bash - nix run github:jacopone/antigravity-nix#google-antigravity-no-fhs - ``` - ---- - -## πŸ”„ 6. Automatic Updates - -The `jacopone/antigravity-nix` repository is updated automatically approximately three times a week via GitHub Actions to track new releases of the Antigravity binary. - -To update your local installation to the latest available package version: -1. Navigate to your configuration repository: - ```bash - cd ~/Config - ``` -2. Update the lockfile entry for the input: - ```bash - nix flake lock --update-input antigravity - ``` -3. Reapply your configuration: - ```bash - sudo nixos-rebuild switch --flake .#laptop - ``` diff --git a/docs/configuration.md b/docs/configuration.md new file mode 100644 index 0000000..4885752 --- /dev/null +++ b/docs/configuration.md @@ -0,0 +1,94 @@ +# βš™οΈ Configuration & Dotfiles Workflow + +This guide details the day-to-day workflow for modifying system declarations, managing user dotfiles, and safely testing changes without destabilizing the workstation. + +--- + +## 1. The Standard Modification Protocol + +To preserve system reliability and adhere to the architectural invariants: + +```text +Identify Concern + ↓ +Find Owning Module (system/ or home/) + ↓ +Edit Declaration + ↓ +Run Flake Check: nix flake check + ↓ +Run Dry Build: nix build .#nixosConfigurations.laptop.config.system.build.toplevel --no-link + ↓ +Test Activation: sudo nixos-rebuild test --flake .#laptop + ↓ +Permanent Switch: sudo nixos-rebuild switch --flake .#laptop + ↓ +Commit Changes: git commit -am "feat: ..." +``` + +--- + +## 2. The Golden Rule: Build, Never Switch + +> [!CAUTION] +> Autonomous agents and automated scripts must **never** execute `nixos-rebuild switch` autonomously. Only human operators may execute switch or boot operations. + +### Verification Commands (Safe) +```bash +# Check flake schema, lock consistency, and syntax +nix flake check + +# Dry build laptop system closure without creating links or modifying root +nix build .#nixosConfigurations.laptop.config.system.build.toplevel --no-link +``` + +### Activation Commands (Privileged) +```bash +# Test configuration in the active session without updating the bootloader menu +sudo nixos-rebuild test --flake .#laptop + +# Permanently activate and add a new generation to systemd-boot menu +sudo nixos-rebuild switch --flake .#laptop +``` + +--- + +## 3. Dotfiles Management Strategy + +Dotfiles in this repository are managed through two distinct patterns: + +### Pattern A: Immutable Store Symlinks (`home.file` / `xdg.configFile`) +Used for applications whose configuration is purely declarative and must never be mutated at runtime by the application: + +```nix +# Example in home/desktop.nix +home.file.".config/niri/config.kdl".source = ./config/niri/config.kdl; +home.file.".config/niri/custom.kdl".source = ./config/niri/custom.kdl; +home.file.".config/zed/settings.json".source = ./config/zed/settings.json; +``` + +- Target location in `$HOME` is a symlink pointing into `/nix/store/...`. +- If you edit the file in `home/config/`, rebuild the system to update the symlink target. + +### Pattern B: Runtime Mutable Configurations (DMS & Browser State) +Used for tools that provide their own GUI settings editor or dynamic state: + +- `~/.config/DankMaterialShell/settings.json` +- `~/.config/niri/dms/*.kdl` +- Firefox / Zen profiles, history, and extensions + +These directories are **deliberately unmanaged by Home Manager**. They are modified interactively through their respective applications without interference from `nixos-rebuild switch`. + +--- + +## 4. Git Hygiene & Pre-Commit Checks + +1. Verify status before committing: + ```bash + git status + ``` +2. Ensure no decrypted credentials, age private keys, or `.env` files are tracked: + ```bash + git diff + ``` +3. Commit with Conventional Commits (`feat:`, `fix:`, `refactor:`, `docs:`). diff --git a/docs/desktop.md b/docs/desktop.md new file mode 100644 index 0000000..876295f --- /dev/null +++ b/docs/desktop.md @@ -0,0 +1,108 @@ +# 🎨 Desktop Environment: Niri & DankMaterialShell (DMS) + +This document describes the architecture of the workstation's graphical desktop environment, the boundary between declarative configuration and runtime state, and the master shortcut reference. + +--- + +## 1. Desktop Architecture & Components + +The graphical workstation stack is built from modern Wayland components: + +```mermaid +graph TD + GREETD["greetd + dank-greeter
(Display Manager Login)"] -->|Launches Session| NIRI["niri
(Scrollable-Tiling Wayland Compositor)"] + + subgraph "Compositor Configuration (Home Manager)" + NIRI --> CFG["~/.config/niri/config.kdl
(Layout, gestures, input, includes)"] + NIRI --> CUST["~/.config/niri/custom.kdl
(Operator custom keybindings)"] + end + + subgraph "Desktop Shell (DMS Daemon)" + DMS["dms run (systemd --user)
(Quickshell panel, widgets, launcher)"] + DMS --> SPOTLIGHT["Spotlight App Launcher (Alt+Space / Mod+Space)"] + DMS --> CLIPBOARD["Clipboard Manager (Mod+V)"] + DMS --> TASKMGR["Task Manager (Mod+M)"] + DMS --> POWERMENU["Power Menu (Super+X)"] + end + + subgraph "DMS Runtime State (Mutable)" + DMS --> BINDS["~/.config/niri/dms/binds.kdl
(Baseline & GUI shortcuts)"] + DMS --> SETTINGS["~/.config/DankMaterialShell/settings.json
(Panels, widgets, themes)"] + DMS --> DYN["~/.config/niri/dms/outputs.kdl & colors.kdl
(Monitors, Matugen theme)"] + end + + CFG -.->|include optional=true| BINDS +``` + +--- + +## 2. The Ownership & Mutability Boundary + +A critical architectural invariant is respecting the distinction between **declarative specification** and **runtime-mutable state**: + +| Layer | Files | Managed By Git? | Mutability | Rationale | +| :--- | :--- | :--- | :--- | :--- | +| **Declarative Core** | `home/config/niri/config.kdl`
`home/config/niri/custom.kdl` | **Yes** | Immutable store symlinks | Governs compositor rules, gesture bindings, and personal shortcuts. | +| **System Daemon** | `system/desktop.nix` | **Yes** | Immutable NixOS module | Enables Niri, DMS package, Greetd greeter, fonts. | +| **DMS Keybindings** | `~/.config/niri/dms/binds.kdl` | **No** (Seeded) | Mutable (`0644`) | Initialized via `dms setup binds`. Editable in DMS Settings GUI. | +| **DMS UI Preferences** | `~/.config/DankMaterialShell/settings.json` | **No** | Mutable | Stores user's bar widget selections, padding, and corner radius. | +| **Display Outputs** | `~/.config/niri/dms/outputs.kdl` | **No** | Dynamic runtime | Generated by DMS when external displays are connected/repositioned. | +| **Color Schemes** | `~/.config/niri/dms/colors.kdl` | **No** | Dynamic runtime | Extracted by Matugen from the active wallpaper. | + +> [!CAUTION] +> Do not attempt to manage `~/.config/niri/dms/` or `~/.config/DankMaterialShell/settings.json` via Home Manager symlinks. Doing so breaks DMS's runtime ability to persist display changes, theme updates, and interactive settings. + +--- + +## 3. Desktop Initialization (Fresh Install) + +On a fresh machine or new user profile, seed the baseline mutable keybindings with: + +```bash +dms setup binds +``` + +This ensures `~/.config/niri/dms/binds.kdl` is created with proper user write permissions (`0644`) before Niri loads. + +--- + +## 4. Master Shortcut Reference + +### Core Applications & Session +| Shortcut | Action | Scope | +| :--- | :--- | :--- | +| `Mod+Return` | Open Alacritty Terminal | Custom (`custom.kdl`) | +| `Mod+T` | Open Terminal | DMS Default (`binds.kdl`) | +| `Mod+B` | Launch Firefox Browser | Custom (`custom.kdl`) | +| `Mod+O` | Launch Obsidian Notes | Custom (`custom.kdl`) | +| `Mod+Space` / `Alt+Space` | Toggle Spotlight Application Launcher | DMS IPC (`binds.kdl`) | +| `Mod+V` | Toggle Clipboard Manager | DMS IPC (`binds.kdl`) | +| `Mod+M` | Toggle Task Manager / Process List | DMS IPC (`binds.kdl`) | +| `Super+X` | Toggle Power Menu (Lock / Suspend / Shutdown) | DMS IPC (`binds.kdl`) | +| `Mod+Comma` | Open DMS Settings Modal | DMS IPC (`binds.kdl`) | +| `Mod+Tab` / `Mod+O` | Toggle Niri Column Overview | DMS IPC (`binds.kdl`) | +| `Mod+Shift+E` | Quit Niri Session | Niri Native (`binds.kdl`) | + +### Window Management & Resizing +| Shortcut | Action | Scope | +| :--- | :--- | :--- | +| `Mod+Q` | Close Active Window | DMS IPC (`binds.kdl`) | +| `Mod+Shift+Q` | Force Kill Focused Window Process (`kill -9`) | Custom (`custom.kdl`) | +| `Mod+F` | Maximize Focused Column | DMS IPC (`binds.kdl`) | +| `Mod+Shift+F` | Fullscreen Window | DMS IPC (`binds.kdl`) | +| `Mod+Shift+T` | Toggle Window Floating | DMS IPC (`binds.kdl`) | +| `Mod+W` | Toggle Column Tabbed Display | DMS IPC (`binds.kdl`) | +| `Mod+Alt+Right / Left` | Expand / Shrink Column Width (+/- 100px) | Custom (`custom.kdl`) | +| `Mod+Alt+Down / Up` | Expand / Shrink Window Height (+/- 100px) | Custom (`custom.kdl`) | + +### Screenshots, Screen Recording & Utilities +| Shortcut | Action | Scope | +| :--- | :--- | :--- | +| `Mod+S` | Interactive Area Screenshot | Custom (`custom.kdl`) | +| `Mod+Shift+S` | Screenshot Active Window | Custom (`custom.kdl`) | +| `Mod+Alt+S` | Screenshot Full Screen | Custom (`custom.kdl`) | +| `Mod+W` | Record Selected Screen Area (wf-recorder) | Custom (`custom.kdl`) | +| `Mod+Shift+W` | Record Focused Monitor | Custom (`custom.kdl`) | +| `Mod+Ctrl+W` | Record Selected Area + Audio | Custom (`custom.kdl`) | +| `Mod+Shift+C` | Eyedropper Color Picker (copies HEX to clipboard) | Custom (`custom.kdl`) | +| `Mod+Ctrl+Shift+R` | Hot-Reload Niri Configuration | Custom (`custom.kdl`) | diff --git a/docs/development-environments.md b/docs/development-environments.md deleted file mode 100644 index ae92d2d..0000000 --- a/docs/development-environments.md +++ /dev/null @@ -1,112 +0,0 @@ -# πŸ’» 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 [home/dev.nix](file:///home/kiskaadee/Config/home/dev.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: -```nix -{ pkgs ? import {} }: - -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`: -```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`):** - ```bash - use nix - ``` - * **For Flake-based projects (`flake.nix`):** - ```bash - use flake - ``` -3. Allow the environment to load: - ```bash - 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). - -### Recommended Workflow: -1. **Use Nix (`devShells` or `nix-shell`)** to make Python and system dependencies (like OpenSSL or PostgreSQL drivers) available: - ```nix - 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: - ```bash - # 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: - ```bash - use flake - layout python - ``` - This triggers standard Nix tools and sources `.venv/bin/activate` simultaneously upon changing directories. diff --git a/docs/getting-started.md b/docs/getting-started.md new file mode 100644 index 0000000..f3484a9 --- /dev/null +++ b/docs/getting-started.md @@ -0,0 +1,125 @@ +# πŸš€ Getting Started & Disaster Recovery + +This document is the operational procedure for bootstrapping the workstation host (`laptop`) from bare metal or recovering after a catastrophic drive failure. + +--- + +## 1. Prerequisites & Installation Media + +1. Download the latest official NixOS Minimal ISO from [nixos.org](https://nixos.org/download.html). +2. Flash the ISO to a USB flash drive: + ```bash + sudo dd if=nixos-minimal-*.iso of=/dev/sdX bs=4M status=progress conv=fsync + ``` +3. Boot the laptop from the USB drive in UEFI mode. + +--- + +## 2. Disk Partitioning & Mounting + +Assuming NVMe target drive `/dev/nvme0n1`: + +```bash +# 1. Create GPT partition table +parted /dev/nvme0n1 -- mklabel gpt + +# 2. EFI System Partition (1GB, FAT32) +parted /dev/nvme0n1 -- mkpart ESP fat32 1MiB 1024MiB +parted /dev/nvme0n1 -- set 1 esp on + +# 3. Root Partition (remaining space, Ext4 or Btrfs) +parted /dev/nvme0n1 -- mkpart primary ext4 1024MiB 100% + +# 4. Format filesystems +mkfs.fat -F 32 -n BOOT /dev/nvme0n1p1 +mkfs.ext4 -L nixos /dev/nvme0n1p2 + +# 5. Mount targets for installation +mount /dev/disk/by-label/nixos /mnt +mkdir -p /mnt/boot +mount /dev/disk/by-label/BOOT /mnt/boot +``` + +--- + +## 3. Clone Repository & Hardware Detection + +```bash +# Generate hardware configuration scan into a temporary directory +nixos-generate-config --root /mnt + +# Clone the declarative workstation configuration +git clone https://github.com/kiskaadee/Config.git /mnt/etc/nixos + +# Replace the repository hardware configuration with the generated one +cp /mnt/etc/nixos/hardware-configuration.nix /mnt/etc/nixos/system/hardware-configuration.nix +``` + +> [!IMPORTANT] +> Verify that the filesystem UUIDs in `system/hardware-configuration.nix` match the output of `blkid /dev/nvme0n1p*`. + +--- + +## 4. Install & Initial System Build + +```bash +# Enable flakes on the installer shell +export NIX_CONFIG="experimental-features = nix-command flakes" + +# Perform initial system installation using the laptop target +nixos-install --flake /mnt/etc/nixos#laptop + +# Set root and user passwords when prompted, then reboot: +reboot +``` + +--- + +## 5. First Graphical Login & Desktop Bootstrap + +1. Remove the USB flash drive and boot into the installed system. +2. At the `dank-greeter` display manager screen, log in as `kiskaadee`. +3. Open a terminal (`Mod+Return`). + +### Desktop Initialization Phase +On a fresh machine, DMS requires a one-time setup command to seed its mutable baseline keybindings: + +```bash +dms setup binds +``` + +This generates `~/.config/niri/dms/binds.kdl` with standard user write permissions (`0644`). From this point forward: +- Niri loads all standard DMS IPC shortcuts (`Mod+Space` for spotlight launcher, `Mod+V` for clipboard, `Mod+M` for task manager, `Super+X` for power menu, volume and brightness controls). +- DMS owns, updates, and mutates `~/.config/niri/dms/` and `~/.config/DankMaterialShell/settings.json` without conflicting with the declarative Nix store. + +--- + +## 6. Operator Secrets Bootstrap (Access to Core) + +The workstation acts as the administrative cockpit for the homelab. To enable editing and rotating secrets in `Core`: + +1. Restore your personal `age` secret key from a secure backup (e.g. Bitwarden or offline medium) into: + ```bash + mkdir -p ~/.config/sops/age + chmod 700 ~/.config/sops/age + # Place your private key in: + # ~/.config/sops/age/keys.txt + chmod 600 ~/.config/sops/age/keys.txt + ``` +2. Verify operator decryption capability: + ```bash + cd ~/Projects/active/homelab/Core/nixos + sops secrets.yaml + ``` + +--- + +## 7. Verification Checklist + +| Check | Command | Expected Outcome | +| :--- | :--- | :--- | +| Flake Validation | `nix flake check` | Evaluates with zero errors. | +| Dry Build | `nix build .#nixosConfigurations.laptop.config.system.build.toplevel --no-link` | Builds cleanly. | +| Compositor Status | `niri msg version` | Reports running Niri version. | +| DMS Shell Daemon | `systemctl --user status dms.service` | Active (running). | +| Desktop Search | `systemctl --user status dsearch.service` | Active (running) on port 43654. | diff --git a/docs/networking.md b/docs/networking.md new file mode 100644 index 0000000..d02335e --- /dev/null +++ b/docs/networking.md @@ -0,0 +1,90 @@ +# 🌐 Workstation Networking & Remote Access + +This document details network management, OpenSSH client infrastructure, and remote workstation accessibility. + +--- + +## 1. Local Network Stack: NetworkManager + +The workstation manages network interfaces, Wi-Fi connections, and DNS via **NetworkManager** declared in `system/core.nix`: + +```nix +networking = { + hostName = "laptop"; + networkmanager.enable = true; +}; +``` + +### Essential CLI Operations +```bash +# Scan available Wi-Fi networks +nmcli dev wifi list + +# Connect to a Wi-Fi network +nmcli dev wifi connect "SSID_NAME" password "PASSPHRASE" + +# Check active connections +nmcli con show --active + +# Monitor network device status +nmcli device status +``` + +--- + +## 2. Workstation Remote Access: OpenSSH Daemon + +Local SSH access is enabled in `system/core.nix` with strict security defaults: + +```nix +services.openssh = { + enable = true; + settings = { + PermitRootLogin = "no"; + PasswordAuthentication = false; + }; +}; +``` + +> [!NOTE] +> The local OpenSSH daemon is an interactive workstation tool (for remote terminal sessions, LAN editor attachments, and file transfers). It is **not** server infrastructure. + +--- + +## 3. SSH Client Profiles & Homelab Ingress + +SSH client connections are declaratively managed by Home Manager in `home/shell.nix`. + +### Defined Host Blocks +| Host Alias | Destination | Port | Use Case | +| :--- | :--- | :--- | :--- | +| **`server-local`** | `192.168.1.200` | 22 | High-speed LAN access to the 24/7 homelab host. | +| **`server-remote`** | `server.roadtotech.me` | 2222 | Remote WAN access through the external edge firewall. | +| **`gitea.roadtotech.me`** | `server.roadtotech.me` | 2223 | Git SSH operations for self-hosted repositories. | + +### Connecting to the Homelab Host +```bash +# On home Wi-Fi (direct LAN connection): +ssh server-local + +# Outside home (remote connection): +ssh server-remote +``` + +--- + +## 4. Bluetooth & Peripheral Networking + +Bluetooth hardware support and audio integration are managed in `system/hardware.nix`: + +```bash +# Open interactive Bluetooth controller +bluetoothctl + +# Common pairing sequence: +# power on +# scan on +# pair +# connect +# trust +``` diff --git a/docs/package-and-secrets.md b/docs/package-and-secrets.md deleted file mode 100644 index 1989884..0000000 --- a/docs/package-and-secrets.md +++ /dev/null @@ -1,62 +0,0 @@ -# πŸ“¦ Package & Secrets Workflow Guide - -This guide covers the day-to-day workflow for managing user-space packages and sensitive information (secrets) within this NixOS configuration. - ---- - -## πŸš€ Adding a New Package - -User-space applications are managed declaratively using Home Manager in domain modules under `home/`: -- Developer tools, SDKs, LSPs, compilers: [home/dev.nix](file:///home/kiskaadee/Config/home/dev.nix) -- Desktop applications, GUI tools, Wayland utilities: [home/desktop.nix](file:///home/kiskaadee/Config/home/desktop.nix) -- Shell utilities, terminal enhancements: [home/shell.nix](file:///home/kiskaadee/Config/home/shell.nix) - -### Step 1: Find the Package Name -Before adding a package, look up its exact attribute name: -* **Search Engine:** Go to the official [NixOS Package Search](https://search.nixos.org/packages). -* **CLI Search:** - ```bash - nix-env -qaP '' - # Or using modern flake-native search: - nix search nixpkgs - ``` - -### Step 2: Update the Target Domain Module -Open the appropriate module (e.g., [home/dev.nix](file:///home/kiskaadee/Config/home/dev.nix)) and append the package name into `home.packages`: - -```nix - home.packages = with pkgs; [ - # ... existing packages - - # Text Editors / Development - neovim - - # New Package Example - ripgrep # Modern grep alternative for fast directory search - ]; -``` - -### Step 3: Test and Switch -Verify the package builds correctly before switching system-wide: -```bash -# Test build without applying -nix build .#nixosConfigurations.laptop.config.system.build.toplevel --no-link - -# Apply configuration -sudo nixos-rebuild switch --flake .#laptop -``` - ---- - -## πŸ”’ Secrets Management (Operator Workflow) - -The laptop acts as the administrative management station for homelab credentials using `sops` and `age`. Secrets are stored encrypted in Git under the [Core](file:///home/kiskaadee/Projects/active/homelab/Core) repository. - -### Editing Homelab Secrets -To edit or rotate homelab secrets from your laptop: -```bash -sops ~/Projects/active/homelab/Core/nixos/secrets.yaml -``` -SOPS uses your personal age key at `~/.config/sops/age/keys.txt` to decrypt the file locally, and re-encrypts it for both the server and your workstation upon save. - -For detailed architecture diagrams and recovery steps, see the [Secrets Management Guide](docs/secrets-management.md). diff --git a/docs/reference/antigravity.md b/docs/reference/antigravity.md new file mode 100644 index 0000000..dcbc432 --- /dev/null +++ b/docs/reference/antigravity.md @@ -0,0 +1,43 @@ +# πŸ€– Antigravity AI Agent Reference + +This document outlines the Antigravity AI pair programming agent integration, operating boundaries, and tool conventions for this workstation. + +--- + +## 1. Operating Rules & Boundaries + +AI agents operating in this repository are governed by the constitution defined in [`AGENTS.md`](file:///home/kiskaadee/Config/AGENTS.md). + +### The Golden Rule: Build, Never Switch +Autonomous agents must **never** execute `nixos-rebuild switch`, `boot`, `test`, or mutate the running host state. Agents: +1. May **read** repository files. +2. May **modify** declarations in `system/` and `home/`. +3. Must **validate** via dry builds (`nix flake check` and `nix build ... --no-link`). + +--- + +## 2. Second Brain Inbox Capture Rule + +Whenever an agent produces an artifact (`UserFacing: true`) or substantial analysis, a copy must be preserved in the Second Brain staging inbox: + +```text +/home/kiskaadee/Brain/inbox/.md +``` + +With frontmatter: +```yaml +--- +type: inbox +created: YYYY-MM-DD +--- +``` + +--- + +## 3. Toolchains & Local Binaries + +Antigravity executes in an interactive development environment with access to: +- `agy` CLI binary installed via `home/dev.nix`. +- Python runtime, Ruff, and Pyright. +- Git, ripgrep (`rg`), and fd (`find_by_name`). +- Nix CLI (`nix flake check`, `nix build`, `nix eval`). diff --git a/docs/reference/neovim.md b/docs/reference/neovim.md new file mode 100644 index 0000000..560c713 --- /dev/null +++ b/docs/reference/neovim.md @@ -0,0 +1,54 @@ +# πŸ“ Neovim Architecture & Keymaps + +This document outlines the Neovim editor setup declared in `home/dev.nix` and `home/config/nvim/`. + +--- + +## 1. Neovim Configuration Architecture + +Neovim is configured through a hybrid Nix / Lua model: +- **Nix Layer (`home/dev.nix`)**: Packages, tree-sitter grammars, and language server packages (LSPs) installed into `$PATH`. +- **Lua Layer (`home/config/nvim/`)**: Modular Lua configuration symlinked to `~/.config/nvim/`: + - `init.lua`: Editor options, leader key (`Space`), and module loader. + - `lua/plugins.lua`: Lazy/Packer plugin definitions. + - `lua/keymaps.lua`: Core keybindings and normal/visual mode ergonomics. + - `lua/lsp.lua`: Language Server Protocol client handlers and completions. + +--- + +## 2. Integrated Toolchains & LSPs + +The following language servers are installed globally via `home/dev.nix` and attached automatically: + +| Language | Language Server / Tool | Formatter / Linter | +| :--- | :--- | :--- | +| **Nix** | `nil` | `nixfmt-rfc-style` | +| **Rust** | `rust-analyzer` | `rustfmt` | +| **Python** | `pyright` | `ruff` | +| **JavaScript / TypeScript** | `typescript-language-server` | `prettier` | +| **Go** | `gopls` | `gofmt` | +| **Markdown / Documentation** | `marksman` | `prettier` | + +--- + +## 3. Essential Keybindings + +- **Leader Key**: `Space` + +### Navigation & Files +| Shortcut | Action | +| :--- | :--- | +| `ff` | Find files (Telescope). | +| `fg` | Live grep across project. | +| `fb` | Switch active buffer. | +| `e` | Toggle file explorer tree. | + +### LSP & Diagnostics +| Shortcut | Action | +| :--- | :--- | +| `gd` | Go to definition. | +| `gr` | Go to references. | +| `K` | Hover documentation. | +| `rn` | Rename symbol. | +| `ca` | Code action. | +| `[d` / `]d` | Jump to previous / next diagnostic error. | diff --git a/docs/reference/shell.md b/docs/reference/shell.md new file mode 100644 index 0000000..4f7de76 --- /dev/null +++ b/docs/reference/shell.md @@ -0,0 +1,59 @@ +# 🐚 Shell & CLI Environment Reference + +This document catalogs the interactive Bash shell configuration, Starship prompt integration, and custom helper scripts managed in `home/shell.nix` and `home/shell/`. + +--- + +## 1. Shell Configuration Architecture + +The shell environment is modularized: +- **`home/shell.nix`**: Core Home Manager bash module, aliases, environment exports, and tool integrations (Direnv, Starship, Fastfetch). +- **`home/shell/`**: Domain-specific sourced shell scripts: + - `git.sh`: Git helper functions and branch utilities. + - `jump.sh`: Directory navigation and quick jumping. + - `pdf.sh`: PDF compilation, viewing, and OCR helpers. + - `quicklinks.sh`: Shortcuts to primary project directories. + - `todo.sh`: Lightweight terminal task tracking. + - `wayland.sh`: Wayland session environment variables. + +--- + +## 2. Shell Aliases & Shortcuts + +### System & Navigation +| Alias | Target Command | Purpose | +| :--- | :--- | :--- | +| `c` | `clear` | Clear terminal scrollback. | +| `q` | `exit` | Close shell session. | +| `ls` | `eza --icons` | Modern directory listing. | +| `ll` | `eza -la --icons` | Detailed directory listing. | +| `tree` | `eza --tree --icons` | Directory tree visualization. | +| `cat` | `bat --paging=never` | Syntax-highlighted file viewing. | + +### Git & Workflows +| Alias | Target Command | Purpose | +| :--- | :--- | :--- | +| `gs` | `git status` | Quick working tree status. | +| `gd` | `git diff` | Syntax-highlighted git diff via Delta. | +| `gl` | `git log --oneline --graph --decorate` | Compact visual commit graph. | + +--- + +## 3. Modular Shell Scripts (`home/shell/`) + +All files in `home/shell/*.sh` are automatically sourced during interactive bash startup: + +```bash +for script in ~/.config/bash/*.sh; do + [ -r "$script" ] && source "$script" +done +``` + +### Adding a New Shell Extension +To add new bash functions or aliases: +1. Create a new `.sh` file under `home/shell/.sh`. +2. Add the source link in `home/shell.nix`: + ```nix + home.file.".config/bash/.sh".source = ./shell/.sh; + ``` +3. Rebuild and restart the shell. diff --git a/docs/reference/tmux.md b/docs/reference/tmux.md new file mode 100644 index 0000000..d68f156 --- /dev/null +++ b/docs/reference/tmux.md @@ -0,0 +1,49 @@ +# πŸͺŸ Tmux Reference & Workflow + +This document describes the Tmux terminal multiplexer configuration declared in `home/shell.nix` and `home/config/tmux/tmux.conf`. + +--- + +## 1. Core Configuration + +- **Prefix Key**: `Ctrl+A` (remapped from standard `Ctrl+B`). +- **Terminal Capabilities**: TrueColor (`tmux-256color`) with RGB support. +- **Mouse Support**: Enabled for scrolling, pane selection, and resizing. +- **Base Index**: Windows and panes start at index `1` instead of `0`. + +--- + +## 2. Keybindings & Controls + +### Pane Management +| Shortcut | Action | +| :--- | :--- | +| `Ctrl+A \|` | Split window horizontally. | +| `Ctrl+A -` | Split window vertically. | +| `Ctrl+A h / j / k / l` | Navigate left, down, up, right (Vim style). | +| `Ctrl+A H / J / K / L` | Resize pane left, down, up, right. | +| `Ctrl+A z` | Toggle full-screen zoom on current pane. | +| `Ctrl+A x` | Kill active pane. | + +### Window Management +| Shortcut | Action | +| :--- | :--- | +| `Ctrl+A c` | Create new window. | +| `Ctrl+A n` | Next window. | +| `Ctrl+A p` | Previous window. | +| `Ctrl+A 1..9` | Switch directly to window number. | +| `Ctrl+A ,` | Rename current window. | + +--- + +## 3. Persistent Sessions +```bash +# Attach or create session named "dev": +tmux new-session -A -s dev + +# List active sessions: +tmux ls + +# Detach from session: +Ctrl+A d +``` diff --git a/docs/secrets-management.md b/docs/secrets-management.md deleted file mode 100644 index 4d21d01..0000000 --- a/docs/secrets-management.md +++ /dev/null @@ -1,69 +0,0 @@ -# πŸ”’ Homelab & Workstation Secrets Management - -This document describes the GitOps secrets management workflow using **Mozilla SOPS** and **age**. - ---- - -## πŸ›οΈ Architectural Model: Author vs Consumer - -Secrets management follows a strict separation between **authoring** (human operator on the workstation) and **runtime consumption** (headless server): - -```text -β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” -β”‚ WORKSTATION (Author / Operator) β”‚ -β”‚ - Key: ~/.config/sops/age/keys.txt (&laptop) β”‚ -β”‚ - Tooling: sops, age, rbw (installed in home/dev.nix) β”‚ -β”‚ - Action: Decrypt, edit, and re-encrypt secrets locally β”‚ -β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ - β”‚ - Git Commit (Ciphertext in repo) - β”‚ - β–Ό -β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” -β”‚ SERVER (Consumer / Runtime) β”‚ -β”‚ - Key: /etc/ssh/ssh_host_ed25519_key (&server) β”‚ -β”‚ - Tooling: sops-nix systemd activation service (root) β”‚ -β”‚ - Action: Unattended decryption into RAM (/run/secrets) β”‚ -β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ -``` - -* **Why editing secrets directly on the remote server fails**: The server does not have the operator's age key. Its host SSH key is owned by `root:root` with `0600` permissions and is only read by `sops-nix` during systemd activation at boot. -* **Why the workstation is the author**: The operator's private age key resides in `~/.config/sops/age/keys.txt` on the laptop. This allows secure local editing without exposing administrative keys on production nodes. - ---- - -## πŸ› οΈ Managing Secrets for Core - -Production homelab secrets are maintained in the [Core](file:///home/kiskaadee/Projects/active/homelab/Core) repository at `Core/nixos/secrets.yaml`. - -### 1. Edit Secrets Locally -From your laptop, open the encrypted secrets file: -```bash -sops ~/Projects/active/homelab/Core/nixos/secrets.yaml -``` -SOPS uses your local age identity to decrypt the file and re-encrypts it for the recipients configured in `Core/.sops.yaml`, including the workstation operator and server runtime identities. - -### 2. Commit and Deploy -Commit the newly encrypted ciphertext and push to your git remote: -```bash -cd ~/Projects/active/homelab/Core -git add nixos/secrets.yaml -git commit -m "chore(secrets): rotate service credentials" -git push -``` -On the server, pulling and rebuilding will activate the updated secrets into `/run/secrets/`. - ---- - -## πŸ”‘ Workstation Key Bootstrapping - -If setting up a new workstation, generate your operator `age` key pair: -```bash -mkdir -p ~/.config/sops/age -age-keygen -o ~/.config/sops/age/keys.txt -chmod 600 ~/.config/sops/age/keys.txt -``` -To print the public key for addition to `Core/.sops.yaml`: -```bash -grep "public key" ~/.config/sops/age/keys.txt -``` diff --git a/docs/secrets.md b/docs/secrets.md new file mode 100644 index 0000000..80eb3b6 --- /dev/null +++ b/docs/secrets.md @@ -0,0 +1,90 @@ +# πŸ” Secrets Management & Homelab GitOps Workflow + +This document explains the secrets architecture for the workstation (`laptop`) and provides step-by-step operator workflows for managing homelab secrets in [`Core`](file:///home/kiskaadee/Projects/active/homelab/Core). + +--- + +## 1. Secrets Architecture: Author vs. Consumer + +A core architectural principle of this infrastructure is the separation between **Secret Authoring** and **Secret Consumption**: + +```mermaid +graph LR + subgraph "Workstation (Operator / Author)" + LAPTOP_KEY["~/.config/sops/age/keys.txt
(&laptop private key)"] + SOPS_CLI["sops CLI
(home/dev.nix)"] + CORE_LOCAL["Core/nixos/secrets.yaml
(Git clone on laptop)"] + + LAPTOP_KEY --> SOPS_CLI + SOPS_CLI -->|Author & Encrypt| CORE_LOCAL + end + + CORE_LOCAL -->|"git push / pull"| CORE_REMOTE["~/Core/nixos/secrets.yaml
(Server clone)"] + + subgraph "Server (Consumer / Runtime)" + HOST_SSH["/etc/ssh/ssh_host_ed25519_key
(&server private key)"] + SOPS_NIX["sops-nix systemd service
(Runs as root at boot)"] + RAM_FS["/run/secrets/*
(Decrypted into RAM only)"] + + CORE_REMOTE --> SOPS_NIX + HOST_SSH --> SOPS_NIX + SOPS_NIX --> RAM_FS + end +``` + +### Roles & Boundaries +1. **Workstation (`Config`)**: + - Holds **zero** declarative system secrets (`sops-nix` is not imported). + - Provides operator CLI packages (`sops`, `age`, `rbw`) in `home/dev.nix`. + - Stores the operator's personal age identity in `~/.config/sops/age/keys.txt`. +2. **Server (`Core`)**: + - Headless consumer running Docker containers, databases, and Traefik. + - Decrypts secrets at boot into a secure ramfs (`/run/secrets/`) using `/etc/ssh/ssh_host_ed25519_key`. + - Unprivileged SSH sessions cannot edit secrets directly on the server. + +--- + +## 2. Operator Workflow: Authoring & Rotating Secrets + +To rotate or add a secret for homelab services: + +### Step 1: Open Ciphertext Locally on Workstation +```bash +cd ~/Projects/active/homelab/Core/nixos +sops secrets.yaml +``` + +SOPS detects your personal identity in `~/.config/sops/age/keys.txt`, decrypts the file in memory, and opens your default editor (`$EDITOR` / Neovim). + +### Step 2: Make Changes and Save +Edit values as necessary. Upon exiting the editor, SOPS encrypts new values using the public keys defined in `Core/.sops.yaml`. + +### Step 3: Commit and Push +```bash +git add secrets.yaml +git commit -m "sec(core): rotate service credentials" +git push origin main +``` + +### Step 4: Rebuild Server +```bash +ssh server-remote "cd ~/Core && git pull && sudo nixos-rebuild switch --flake .#server" +``` +The server evaluates the new ciphertext, decrypts it into `/run/secrets/`, and restarts affected systemd and Docker containers. + +--- + +## 3. Backing Up & Restoring the Operator Age Key + +The operator key is your cryptographic identity for managing homelab infrastructure: + +```bash +# Location: +~/.config/sops/age/keys.txt + +# File format: +# public key: age1... +AGE-SECRET-KEY-1... +``` + +Store this key securely in a password manager (e.g. Bitwarden/Vaultwarden). If re-installing the workstation, restore this file with mode `0600` before editing `Core` secrets. diff --git a/docs/system-lifecycle.md b/docs/system-lifecycle.md new file mode 100644 index 0000000..2e26702 --- /dev/null +++ b/docs/system-lifecycle.md @@ -0,0 +1,97 @@ +# πŸ”„ System Lifecycle: Rebuilding, Rollbacks & Maintenance + +This document explains the technical lifecycle of the workstationβ€”from Nix flake evaluation down to system activationβ€”and provides operational procedures for rollbacks and disk maintenance. + +--- + +## 1. What Happens During `nixos-rebuild switch`? + +When you execute a system rebuild, NixOS and Home Manager execute a multi-stage pipeline: + +```mermaid +graph TD + FLAKE["flake.nix
(Declarations & Pinned Inputs)"] -->|Evaluate| DRV["Derivation Computation
(/nix/store/*.drv)"] + DRV -->|Compile & Link| CLOSURE["System Closure
(/nix/store/nixos-system-laptop-...)"] + + subgraph Activation Phase ["System Activation (Root / Switch)"] + CLOSURE --> SYS_PROFILE["Update /nix/var/nix/profiles/system"] + SYS_PROFILE --> BOOT_LINK["Install to /boot/EFI/systemd-boot"] + SYS_PROFILE --> SYSD_UNITS["Restart & Reload Modified systemd Services"] + SYS_PROFILE --> PAM_USERS["Sync Users, Groups, and PAM Policies"] + end + + subgraph Home Manager Phase ["User Session Activation"] + CLOSURE --> HM_PROFILE["Update ~/.local/state/nix/profiles/home-manager"] + HM_PROFILE --> SYMLINKS["Update ~/.config and ~/ Symlink Farm"] + HM_PROFILE --> HM_UNITS["Restart systemd --user Units (e.g., dsearch, dms)"] + end +``` + +--- + +## 2. The Command Matrix: Rebuild Actions + +| Command | Rebuilds System? | Boots Next Time? | Affects Active Session? | Use Case | +| :--- | :--- | :--- | :--- | :--- | +| `nix build .#nixosConfigurations.laptop.config.system.build.toplevel --no-link` | Yes (Dry) | No | No | Safe validation of compilation without system mutation. | +| `sudo nixos-rebuild dry-build --flake .#laptop` | Yes (Dry) | No | No | Prints what would be built or downloaded. | +| `sudo nixos-rebuild test --flake .#laptop` | Yes (Live) | No | **Yes** | Test services or configs immediately without polluting bootloader. | +| `sudo nixos-rebuild switch --flake .#laptop` | Yes (Live) | **Yes** | **Yes** | Standard activation. Sets new default boot generation. | +| `sudo nixos-rebuild boot --flake .#laptop` | Yes (Live) | **Yes** | No | Prepares next boot without altering currently running services. | + +--- + +## 3. Generations & Rollback Strategies + +Every time `nixos-rebuild switch` runs, NixOS records a numbered generation. + +### Strategy A: Bootloader Menu Rollback (Disaster Recovery) +If a new generation prevents the display server or network from starting: +1. Reboot the laptop. +2. At the `systemd-boot` menu, press `Space` or arrow keys. +3. Select an earlier generation from the list (e.g. `Generation 42`). +4. Boot into the known working system. + +### Strategy B: Command-Line Rollback (Active Session) +If an update introduced a minor defect and you are logged in: +```bash +# Roll back system to the previous generation +sudo nixos-rebuild --rollback switch + +# Roll back only Home Manager (user session) +home-manager generations +# Select generation ID to activate +``` + +### Strategy C: List Generations +```bash +# List system generations +sudo nix-env -p /nix/var/nix/profiles/system --list-generations +``` + +--- + +## 4. Workstation Maintenance Runbook + +### Routine Disk Cleanup +Over time, old generations accumulate in `/nix/store`: + +```bash +# 1. Delete system generations older than 14 days +sudo nix-collect-garbage --delete-older-than 14d + +# 2. Delete user-level generations older than 14 days +nix-collect-garbage --delete-older-than 14d + +# 3. Clean untracked bootloader entries +sudo nixos-rebuild boot --flake .#laptop +``` + +### Updating Flake Dependencies +```bash +# Update all inputs (including nixpkgs channel tarball) +nix flake update + +# Verify build before committing flake.lock +nix build .#nixosConfigurations.laptop.config.system.build.toplevel --no-link +``` diff --git a/docs/system-maintenance.md b/docs/system-maintenance.md deleted file mode 100644 index 8f1b0c1..0000000 --- a/docs/system-maintenance.md +++ /dev/null @@ -1,79 +0,0 @@ -# πŸ› οΈ System Maintenance Guide - -This document describes how to update the system safely, verify its health post-update, and clean up disk space by removing old configurations. - ---- - -## πŸ”„ Performing Clean & Secure System Updates - -NixOS systems managed with Flakes lock dependency versions inside `flake.lock`. To update the system securely, follow this workflow: - -### Step 1: Update the Flake Inputs -Fetch the latest revisions of your inputs (e.g., `nixpkgs`, `home-manager`, and other plugins): -```bash -nix flake update -``` - -### Step 2: Validate the Build & Formatting -Test-build the derivation without applying it to your bootloader. This prevents dirty installations or builder failures (such as Python PEP8 style errors) from affecting system configuration state: -```bash -nix build .#nixosConfigurations.laptop.config.system.build.toplevel --no-link -``` - -### Step 3: Switch & Apply the Update -Once the test build completes successfully, switch to the new generation: -```bash -sudo nixos-rebuild switch --flake .#laptop -``` - ---- - -## πŸ₯ Post-Update Health Checklist - -Verify system health immediately after a major system switch: - -1. **Systemd Service Status:** Ensure all units are running and no critical services failed: - ```bash - systemctl --failed - systemctl --user --failed - ``` -2. **Display & Window Manager:** Verify that your graphics drivers, audio services (PipeWire/WirePlumber), and hotkeys are responsive. -3. **Secrets Integrity:** Check that decrypted secrets are loaded correctly: - ```bash - ls -la /run/secrets/ - ``` -4. **Network & Connectivity:** Verify internet connectivity and NetworkManager status: - ```bash - systemctl status NetworkManager.service - ping -c 3 google.com - ``` - ---- - -## 🧹 Cleaning Up Old Generations - -Nix keeps older versions (generations) of your system configuration so you can roll back instantly. However, this takes up storage space. - -### Step 1: List System Generations -To view all available system generations: -```bash -sudo nix-env --list-generations --profile /nix/var/nix/profiles/system -``` - -### Step 2: Delete Old Generations -* **Remove older than X days:** - ```bash - sudo nix-env --delete-generations +5d --profile /nix/var/nix/profiles/system - ``` -* **Remove specific generations:** - ```bash - sudo nix-env --delete-generations 42 43 --profile /nix/var/nix/profiles/system - ``` - -### Step 3: Collect Garbage (Reclaim Disk Space) -Deleting generations only updates configuration links. To actually free up disk space and prune unused dependencies: -```bash -# Run garbage collection for system and user profiles -sudo nix-collect-garbage -d -nix-collect-garbage -d -``` diff --git a/docs/tmux.md b/docs/tmux.md deleted file mode 100644 index 6181c3e..0000000 --- a/docs/tmux.md +++ /dev/null @@ -1,72 +0,0 @@ -# πŸŽ›οΈ Tmux Environment & Cheat Sheet - -This repository configures **Tmux** declaratively via Home Manager in [home/shell.nix](file:///home/kiskaadee/Config/home/shell.nix). The configuration is optimized for speed, Vim keybindings, and seamless split-pane navigation. - ---- - -## πŸ”‘ Core Settings - -* **Prefix Key**: Uses the default **`Ctrl+b`**. -* **Status Bar**: Anchored to the **top** of the terminal window. -* **Base Index**: Windows and panes start indexing at **`1`** (aligning with your physical keyboard numbers). -* **Mouse Support**: Enabled. You can scroll, click to select panes, and drag splits to resize them. -* **Zero Esc-Lag**: Keyboard escape latency is set to `0ms` (essential for vim editing response). - ---- - -## 🧭 Seamless Neovim Navigation - -The configuration loads the **`vim-tmux-navigator`** plugin. This allows you to navigate between Vim/Neovim split windows and Tmux splits using the same hotkeys **without pressing the prefix key**: - -| Shortcut | Action | -| :--- | :--- | -| `Ctrl + h` | Focus pane/split to the **left** | -| `Ctrl + j` | Focus pane/split **down** | -| `Ctrl + k` | Focus pane/split **up** | -| `Ctrl + l` | Focus pane/split to the **right** | - ---- - -## πŸ“‹ Common Tmux Keybindings - -For the following shortcuts, press your prefix key **`Ctrl+b`** first, release it, then press the shortcut key. - -### Sessions & Windows -| Key | Action | -| :--- | :--- | -| `d` | **Detach** from the current session (keeps it running in the background) | -| `c` | Create a **new window** (tab) | -| `,` | **Rename** the current window | -| `&` | Kill the current window | -| `1` - `9` | Switch to window by index number | - -### Splits & Panes -| Key | Action | -| :--- | :--- | -| `"` | Split pane **horizontally** (top/bottom) | -| `%` | Split pane **vertically** (left/right) | -| `x` | Close/kill the current pane | -| `z` | **Zoom** the current pane to full screen (press again to restore) | -| `h` / `j` / `k` / `l` | Vim-style switch focus left/down/up/right (alternative to Ctrl+direction) | - ---- - -## πŸ–₯️ Command Line Session Management - -Manage your persistent background sessions directly from your shell: - -```bash -# Start a new named session -tmux new -s my-session-name - -# List all active background sessions -tmux ls - -# Attach to an existing session -tmux a -t my-session-name -# Or attach to the last active session: -tmux a - -# Kill a session -tmux kill-session -t my-session-name -```