From 5314db937f68bdc84540515a95f20ad45dd7b4c0 Mon Sep 17 00:00:00 2001 From: kiskaadee Date: Sat, 5 Sep 2026 07:50:28 -0500 Subject: [PATCH] refactor(modules): restructure user home-manager modules into clean CLI/GUI tiers - Update `architecture.md` to reflect the 3-host topology (`server`, `desktop`, `laptop`) and tiered user module design. - Strip Wayland and GUI dependencies from Tier 1 CLI modules (`base.nix`, `terminal.nix`). - Centralize Alacritty configuration, Wayland screen tools (`grim`, `slurp`, `wf-recorder`, `obs-studio`), and GUI applications into `modules/user/graphical.nix`. - Clean up host-specific `home.nix` files to remove duplicated package lists. - Add `tea` (Gitea CLI) to developer applications. --- architecture.md | 108 +++++++++++++++++++++---------------- hosts/desktop/home.nix | 2 - hosts/laptop/home.nix | 6 +-- modules/user/apps.nix | 4 +- modules/user/base.nix | 7 ++- modules/user/graphical.nix | 76 ++++++++++++++++++++++++++ modules/user/terminal.nix | 70 ------------------------ 7 files changed, 144 insertions(+), 129 deletions(-) diff --git a/architecture.md b/architecture.md index 69e0e0b..40029da 100644 --- a/architecture.md +++ b/architecture.md @@ -2,7 +2,7 @@ ## Core Principles -This repository manages a declarative NixOS configuration for multiple host targets (`desktop`, `laptop`) and shared user environments via Home Manager. +This repository manages a declarative NixOS configuration for multiple host targets (`server`, `desktop`, `laptop`) and shared user environments via Home Manager. 1. **Git is the Source of Truth**: Every persistent system configuration must be declaratively defined within this repository. 2. **Runtime State Separation**: Runtime state (Docker volumes, dynamic IP caches, `/run/secrets/`, mutable state) must not become configuration state. @@ -16,10 +16,19 @@ This repository manages a declarative NixOS configuration for multiple host targ Config/ ├── flake.nix # Flake inputs and nixosConfigurations public entrypoint ├── flake.lock # Pinned dependencies -├── home.nix # Root Home Manager shared entrypoint +├── home.nix # Root Home Manager shared entrypoint (Pure CLI: base, neovim, terminal) ├── .sops.yaml # SOPS encryption keys and path rules │ ├── hosts/ # Machine-specific configurations +│ ├── server/ +│ │ ├── configuration.nix # Server NixOS configuration (headless homelab node) +│ │ ├── hardware-configuration.nix # Generated hardware configuration +│ │ ├── home.nix # Server-specific Home Manager profile (diagnostics CLI) +│ │ ├── secrets.yaml # Encrypted server secrets (SOPS) +│ │ ├── dynu.nix # Dynu DDNS update service +│ │ ├── homeserver.nix # Core homelab runtime services (Docker) +│ │ └── traefik-deployments.nix # Traefik edge reverse proxy +│ │ │ ├── desktop/ │ │ ├── configuration.nix # Desktop NixOS configuration & server specialization │ │ ├── hardware-configuration.nix # Generated hardware configuration @@ -32,7 +41,7 @@ Config/ │ └── laptop/ │ ├── configuration.nix # Laptop NixOS configuration (Niri compositor) │ ├── hardware-configuration.nix # Generated hardware configuration -│ ├── home.nix # Laptop-specific Home Manager profile +│ ├── home.nix # Laptop-specific Home Manager profile (Niri dotfiles) │ └── secrets.yaml # Encrypted laptop secrets (SOPS) │ ├── modules/ @@ -40,11 +49,12 @@ Config/ │ │ ├── base.nix # Core OS settings, networking, audio, docker, bluetooth │ │ └── graphical.nix # Shared display manager (greetd / DMS) & graphical daemons │ │ -│ └── user/ # Reusable Home Manager modules (shared across hosts) -│ ├── base.nix # Core shell, utilities, Git, common environment -│ ├── apps.nix # Centralized user applications & CLI tools -│ ├── graphical.nix # Graphical user tools & Neovim configuration -│ ├── terminal.nix # Terminal emulators (Alacritty), multiplexers (Tmux), prompt +│ └── user/ # Reusable Home Manager modules (tiered split) +│ ├── base.nix # Tier 1: Pure CLI shell, utilities, Git, common environment +│ ├── terminal.nix # Tier 1: Pure CLI multiplexer (tmux) & prompt (starship) +│ ├── neovim.nix # Tier 1: Modular Neovim editor configuration +│ ├── apps.nix # Tier 2: Developer & user applications (Tea, Antigravity, SDKs) +│ ├── graphical.nix # Tier 3: Graphical user tools, Alacritty, Wayland stack, LSPs │ ├── shell/ # Modular shell scripts, aliases, and functions │ ├── scripts/ # Standalone helper scripts │ └── config/ # Managed application dotfiles @@ -58,42 +68,48 @@ Config/ ```mermaid graph TD - A[flake.nix] --> B[nixosConfigurations.desktop] - A --> C[nixosConfigurations.laptop] + A[flake.nix] --> B[nixosConfigurations.server] + A --> C[nixosConfigurations.desktop] + A --> D[nixosConfigurations.laptop] + + subgraph Server Host ["hosts/server/"] + B --> S_CONF[configuration.nix] + S_CONF --> S_HW[hardware-configuration.nix] + S_CONF --> S_DY[dynu.nix] + S_CONF --> S_TR[traefik-deployments.nix] + S_CONF --> S_HS[homeserver.nix] + end subgraph Desktop Host ["hosts/desktop/"] - B --> D[configuration.nix] - D --> D1[hardware-configuration.nix] - D --> D2[dynu.nix] - D --> D3[traefik-deployments.nix] - D --> D4[homeserver.nix] - D --> D5["specialisation.server"] + C --> D_CONF[configuration.nix] + D_CONF --> D_HW[hardware-configuration.nix] + D_CONF --> D_DY[dynu.nix] + D_CONF --> D_TR[traefik-deployments.nix] + D_CONF --> D_HS[homeserver.nix] + D_CONF --> D_SP["specialisation.server"] end subgraph Laptop Host ["hosts/laptop/"] - C --> L[configuration.nix] - L --> L1[hardware-configuration.nix] + D --> L_CONF[configuration.nix] + L_CONF --> L_HW[hardware-configuration.nix] end - subgraph Shared System ["modules/system/"] - D --> S1[base.nix] - D --> S2[graphical.nix] - L --> S1 - L --> S2 - end - - subgraph Shared User HM ["home.nix -> modules/user/"] + subgraph Tier1 Shared CLI HM ["home.nix (All Hosts)"] B --> H[home.nix] C --> H + D --> H H --> U1[base.nix] - H --> U2[apps.nix] - H --> U3[graphical.nix] - H --> U4[terminal.nix] + H --> U2[neovim.nix] + H --> U3[terminal.nix] end - subgraph Host-Specific HM ["hosts//home.nix"] - B --> DH[desktop/home.nix] - C --> LH[laptop/home.nix] + subgraph Tier23 Workstation HM ["Workstation Extensions (Desktop & Laptop)"] + C --> DH[desktop/home.nix] + D --> LH[laptop/home.nix] + DH --> UA[apps.nix] + DH --> UG[graphical.nix] + LH --> UA + LH --> UG end ``` @@ -107,21 +123,19 @@ graph TD - **Includes**: - `hardware-configuration.nix`: Generated hardware and kernel parameters (managed by `nixos-generate-config`). - `configuration.nix`: Hostname, bootloader, host-specific users, GPU/display drivers, and specialisations. - - `home.nix`: User packages and dotfiles tied to the host's desktop environment. + - `home.nix`: User packages and dotfiles tied to the host's desktop environment or headless role. - `secrets.yaml`: SOPS-encrypted secrets for that machine. - - Host infrastructure services (e.g., `homeserver.nix`, `dynu.nix`, `traefik-deployments.nix` on `desktop`). + - Host infrastructure services (e.g., `homeserver.nix`, `dynu.nix`, `traefik-deployments.nix` on `server`/`desktop`). ### 3. `modules/system/` - **Role**: Reusable system configuration shared by multiple hosts. - **Rule**: A module must only be placed here when its assumptions are valid for every host importing it. If a configuration is meaningful only for one host, keep it under `hosts//`. ### 4. `modules/user/` -- **Role**: Reusable Home Manager modules managing user packages, shell environments, and dotfiles. -- **Subcomponents**: - - Shared user applications belong under `modules/user/`. `apps.nix` is the current central application module. - - `base.nix`: Git, shell baseline, session variables. - - `graphical.nix`: User-level graphical tools and modular Neovim configuration. - - `terminal.nix`: Multiplexers (`tmux`), terminal emulators (`alacritty`), prompt (`starship`). +- **Role**: Reusable Home Manager modules organized into clean, predictable layers: + - **Tier 1: Pure CLI Base** (`base.nix`, `terminal.nix`, `neovim.nix` via `home.nix`): Imported on all hosts (headless server, laptop, desktop). Provides pure terminal tools (`tmux`, `starship`), editor, Git, and essential CLI diagnostics. + - **Tier 2: Developer & User Apps** (`apps.nix`): Imported by workstation profiles. Provides developer toolchains, cloud SDKs, Git forge clients (`tea`, `gh`), and media tools. + - **Tier 3: Graphical Desktop Environment** (`graphical.nix`): Imported by workstation profiles. Provides Alacritty, Firefox, Zen Browser, Zed, DankSearch, Wayland capture/clipboard utilities (`wl-clipboard`, `grim`, `slurp`, `swappy`, `wf-recorder`, `obs-studio`), and Language Servers. - `shell/`, `scripts/`, `config/`: Shell utility files and structured dotfiles. --- @@ -134,13 +148,15 @@ graph TD | **Shared System Services** | `modules/system/` | Systemd services, system packages, or OS features valid for all importing hosts. | | **Host System Settings** | `hosts//configuration.nix` | Hostname, bootloader, user groups, machine-specific daemons. | | **Hardware / Disks** | `hosts//hardware-configuration.nix` | Generated configuration. Do not manually restructure or refactor. | -| **Shared User Apps** | `modules/user/` (`apps.nix`) | Default location for CLI and GUI user software common across hosts. | -| **Host-Specific User Apps** | `hosts//home.nix` | Tools relevant only to that host (e.g., Hyprland screen recorders on desktop). | +| **Shared CLI Foundations** | `modules/user/base.nix`, `terminal.nix` | Tier 1 pure CLI tools (Git, tmux, starship, core utilities) shared across all hosts. | +| **Workstation Dev Tools** | `modules/user/apps.nix` | Tier 2 developer CLI & cloud tools (`tea`, `antigravity`, compilers, SDKs). | +| **Workstation Graphical Stack** | `modules/user/graphical.nix` | Tier 3 GUI applications, terminal emulator (`alacritty`), Wayland tools, LSPs. | +| **Host-Specific User Apps** | `hosts//home.nix` | Tools relevant only to that host (e.g., Hyprland `grimblast` on desktop). | | **Shared Shell Tools** | `modules/user/shell/` | Modular bash/zsh helpers, aliases, and functions. | | **Standalone Scripts** | `modules/user/scripts/` | Executable user shell scripts. | | **Application Dotfiles** | `modules/user/config/` | Managed static configuration files linked into `$HOME/.config/`. | | **Encrypted Secrets** | `hosts//secrets.yaml` | Encrypted with SOPS/age; referenced via `config.sops.secrets.*.path`. | -| **Desktop Homelab / DDNS** | `hosts/desktop/` | Desktop-specific homelab infrastructure, reverse proxy, and DDNS monitor. | +| **Homelab Services / DDNS** | `hosts/server/` or `hosts/desktop/` | Machine-specific homelab infrastructure, reverse proxy, and DDNS monitor. | | **How-To Guides** | `docs/` | Operational procedures and maintenance workflows. | --- @@ -150,10 +166,10 @@ graph TD These rules define the repository boundaries and must not be violated: 1. **Flake Public Entrypoint Invariant**: `flake.nix` is the sole public entrypoint for building the repository's NixOS host configurations. -2. **Package Ownership Invariant**: Shared user applications belong under `modules/user/` (with `apps.nix` as the central application module). Do not introduce arbitrary package lists in `modules/system/` unless they are strictly required for system-wide root maintenance or core OS services. -3. **Host Isolation Invariant**: Desktop-specific homelab infrastructure (`homeserver.nix`, `traefik-deployments.nix`, `dynu.nix`) must remain isolated under `hosts/desktop/` and must never be imported into `hosts/laptop/`. +2. **Package Ownership Invariant**: Shared user applications belong under `modules/user/` categorized by tier (`base.nix` / `terminal.nix` for pure CLI, `apps.nix` for developer tools, `graphical.nix` for GUI/Wayland). Do not introduce arbitrary package lists in `modules/system/` unless strictly required for system-wide root maintenance or core OS services. +3. **Host Isolation Invariant**: Machine-specific homelab infrastructure (`homeserver.nix`, `traefik-deployments.nix`, `dynu.nix`) must remain isolated under their respective host directories and must never be imported into `hosts/laptop/`. 4. **Desktop Server Specialisation Invariant**: `hosts/desktop/configuration.nix` defines `specialisation.server.configuration`. The server specialization must remain valid, bootable, and strictly headless (disabling display managers, PipeWire, Bluetooth, and desktop sleep targets). 5. **Secrets Security Invariant**: Secrets must stay encrypted in Git via SOPS. Plaintext secrets must never be committed. Configurations must refer to secrets at runtime via `/run/secrets/` or `config.sops.secrets..path`. Never decrypt secrets into tracked or persistent working-tree files. Never add, modify, or rotate SOPS/age keys unless explicitly requested. 6. **Hardware Configuration Invariant**: `hardware-configuration.nix` is generated configuration. Do not manually restructure, clean up, or refactor it. Hardware-specific changes should normally be produced by `nixos-generate-config`; deliberate manual additions require explicit justification. -7. **Consumer Validation Invariant**: Changes to shared modules (`modules/system/` or `modules/user/`) or composed host configurations must be evaluated against all downstream consumers in the import graph (`desktop` and `laptop`). +7. **Consumer Validation Invariant**: Changes to shared modules (`modules/system/` or `modules/user/`) or composed host configurations must be evaluated against all downstream consumers in the import graph (`server`, `desktop`, and `laptop`). 8. **State Compatibility Invariant**: `system.stateVersion` and `home.stateVersion` (`26.05`) are compatibility declarations for stateful data and must not be bumped casually as part of routine maintenance or package updates. diff --git a/hosts/desktop/home.nix b/hosts/desktop/home.nix index 7414c2a..b51e8e5 100644 --- a/hosts/desktop/home.nix +++ b/hosts/desktop/home.nix @@ -12,8 +12,6 @@ # Host-specific package installations for desktop (Hyprland environment) home.packages = with pkgs; [ grimblast # Screenshot utility for Hyprland - obs-studio # High-feature video capture and streaming studio - wf-recorder # Light recorder for Wayland-based window managers ]; # Mount custom Hyprland and DankMaterialShell configuration files declaratively diff --git a/hosts/laptop/home.nix b/hosts/laptop/home.nix index d591f65..e154f66 100644 --- a/hosts/laptop/home.nix +++ b/hosts/laptop/home.nix @@ -9,11 +9,7 @@ ../../modules/user/graphical.nix ]; - # Host-specific package installations for laptop workstation - home.packages = with pkgs; [ - obs-studio # High-feature video capture and streaming studio - wf-recorder # Light recorder for Wayland-based window managers - ]; + # Niri WM declarative configuration files home.file.".config/niri/config.kdl".source = ../../modules/user/config/niri/config.kdl; diff --git a/modules/user/apps.nix b/modules/user/apps.nix index 469f8d8..31d196b 100644 --- a/modules/user/apps.nix +++ b/modules/user/apps.nix @@ -13,7 +13,6 @@ in # Local CLI & Workflow utilities bundleProject recordScript - wf-recorder # Light recorder for Wayland-based window managers # Media, Note-taking & Graphical Tools mpv # Fast, scriptable, keyboard-driven CLI media player @@ -25,7 +24,8 @@ in obsidian # Markdown-based personal knowledge wiki and note-taking app libreoffice # Comprehensive open-source office suite (Writer, Calc, Impress, Draw) - # Cloud CLI, Database Management & Archive tools + # Cloud CLI, Git Forge & Database Management + tea # Gitea official command line client google-cloud-sdk # GCP administration utilities turso-cli # Management interface for Turso libSQL cloud databases postgresql # PostgreSQL client utilities (psql, pg_dump) diff --git a/modules/user/base.nix b/modules/user/base.nix index c1dd00f..93da31b 100644 --- a/modules/user/base.nix +++ b/modules/user/base.nix @@ -269,10 +269,9 @@ }; }; - # Standalone System dependencies + # Standalone CLI utilities & system dependencies home.packages = with pkgs; [ - ripgrep fd glow jq tree wl-clipboard sqlite python3 nodejs - bc qpdf tty-clock grim slurp swappy libnotify uv - curl parallel tuxedo sops age + ripgrep fd glow jq tree sqlite python3 nodejs + bc qpdf tty-clock uv curl parallel tuxedo sops age ]; } diff --git a/modules/user/graphical.nix b/modules/user/graphical.nix index 72a4b66..7e898e7 100644 --- a/modules/user/graphical.nix +++ b/modules/user/graphical.nix @@ -4,12 +4,26 @@ { inputs, pkgs, ... }: +let + # Parse true ASCII Escape (0x1b) and DEL (0x7f) bytes so TOML serialization generates real escape sequences + esc = builtins.fromJSON "\"\\u001b\""; + del = builtins.fromJSON "\"\\u007f\""; +in { # Graphical packages managed via Home Manager home.packages = with pkgs; [ inputs.zen-browser.packages.${pkgs.stdenv.hostPlatform.system}.default # Modern browser build zed-editor # GPU-accelerated desktop text editor + # Wayland Clipboard, Screenshot & Screen Capture Utilities + wl-clipboard + grim + slurp + swappy + libnotify + wf-recorder + obs-studio + # Language Servers for Zed (and general dev use) rust-analyzer pyright @@ -24,6 +38,68 @@ prettier ]; + # GPU-Accelerated Terminal Emulator (Alacritty) + programs.alacritty = { + enable = true; + settings = { + general = { + import = [ + "~/.config/alacritty/dank-theme.toml" + ]; + }; + + font = { + normal = { family = "FiraCode Nerd Font"; style = "Regular"; }; + bold = { family = "FiraCode Nerd Font"; style = "Bold"; }; + italic = { family = "FiraCode Nerd Font"; style = "Italic"; }; + bold_italic = { family = "FiraCode Nerd Font"; style = "Bold Italic"; }; + size = 11.0; + }; + + window = { + decorations = "None"; + padding = { x = 12; y = 12; }; + opacity = 1.0; + }; + + scrolling = { + history = 3023; + }; + + cursor = { + style = { shape = "Block"; blinking = "On"; }; + blink_interval = 500; + unfocused_hollow = true; + }; + + mouse = { + hide_when_typing = true; + }; + + selection = { + save_to_clipboard = false; + }; + + bell = { + duration = 0; + }; + + keyboard = { + bindings = [ + { key = "C"; mods = "Control|Shift"; action = "Copy"; } + { key = "V"; mods = "Control|Shift"; action = "Paste"; } + { key = "N"; mods = "Control|Shift"; action = "SpawnNewInstance"; } + { key = "Equals"; mods = "Control|Shift"; action = "IncreaseFontSize"; } + { key = "Minus"; mods = "Control"; action = "DecreaseFontSize"; } + { key = "Key0"; mods = "Control"; action = "ResetFontSize"; } + { key = "Enter"; mods = "Shift"; chars = "\n"; } + { key = "Delete"; mods = "Control"; chars = "${esc}[3;5~"; } + { key = "Back"; mods = "Control"; chars = "${esc}${del}"; } + ]; + }; + }; + }; + # Firefox configuration programs.firefox = { enable = true; diff --git a/modules/user/terminal.nix b/modules/user/terminal.nix index d1f2bab..3720bee 100644 --- a/modules/user/terminal.nix +++ b/modules/user/terminal.nix @@ -1,76 +1,6 @@ -# 🖥️ Terminal Environment configuration -# Defines user-space preferences for Alacritty, Tmux, and Starship. - { pkgs, ... }: -let - # Parse true ASCII Escape (0x1b) and DEL (0x7f) bytes so TOML serialization generates real escape sequences - esc = builtins.fromJSON "\"\\u001b\""; - del = builtins.fromJSON "\"\\u007f\""; -in { - # GPU-Accelerated Terminal Emulator (Alacritty) - programs.alacritty = { - enable = true; - settings = { - general = { - import = [ - "~/.config/alacritty/dank-theme.toml" - ]; - }; - - font = { - normal = { family = "FiraCode Nerd Font"; style = "Regular"; }; - bold = { family = "FiraCode Nerd Font"; style = "Bold"; }; - italic = { family = "FiraCode Nerd Font"; style = "Italic"; }; - bold_italic = { family = "FiraCode Nerd Font"; style = "Bold Italic"; }; - size = 11.0; - }; - - window = { - decorations = "None"; - padding = { x = 12; y = 12; }; - opacity = 1.0; - }; - - scrolling = { - history = 3023; - }; - - cursor = { - style = { shape = "Block"; blinking = "On"; }; - blink_interval = 500; - unfocused_hollow = true; - }; - - mouse = { - hide_when_typing = true; - }; - - selection = { - save_to_clipboard = false; - }; - - bell = { - duration = 0; - }; - - keyboard = { - bindings = [ - { key = "C"; mods = "Control|Shift"; action = "Copy"; } - { key = "V"; mods = "Control|Shift"; action = "Paste"; } - { key = "N"; mods = "Control|Shift"; action = "SpawnNewInstance"; } - { key = "Equals"; mods = "Control|Shift"; action = "IncreaseFontSize"; } - { key = "Minus"; mods = "Control"; action = "DecreaseFontSize"; } - { key = "Key0"; mods = "Control"; action = "ResetFontSize"; } - { key = "Enter"; mods = "Shift"; chars = "\n"; } - { key = "Delete"; mods = "Control"; chars = "${esc}[3;5~"; } - { key = "Back"; mods = "Control"; chars = "${esc}${del}"; } - ]; - }; - }; - }; - # Terminal Multiplexer (Tmux) # Allows maintaining persistent shell sessions, window splitting, and tabs. programs.tmux = {