# wendingtuo/nix-config architecture

> Architecture diagram of the GitHub repository wendingtuo/nix-config, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wendingtuo/nix-config
- Repository: https://github.com/wendingtuo/nix-config

## Overview

##### Project Type & Purpose
- This is an “Infrastructure‑as‑Code” repository using Nix flakes to manage both NixOS system configurations (in `hosts/…`) and user (home‑manager) configurations (in `modules/home‑manager/…`).
- Purpose: Provide a single flake entrypoint (`flake.nix`) that composes OS modules, home modules, and overlays to produce reproducible builds for a host (`nixvm`) and a user (`blake`).

##### File Structure
- Top Level:
- `flake.nix` / `flake.lock` – root flake definition and lockfile
- `hosts/nixvm/` – NixOS machine‑specific module + hardware config
- `modules/` – reusable NixOS and home‑manager module sets
- `overlays/` – package overlays or customizations
- `result` – symlink to the last flake build
- Modules split:
- `modules/nixos/common` + `desktop` + `services`
- `modules/home-manager/common` + `desktop` + `programs`

##### README
- The README describes clone/build commands:
- `nixos-rebuild switch --impure --flake .#hostname`
- `home-manager switch --flake .#user@hostname`
- Manual steps are outside Nix (WireGuard, Nextcloud login, etc.), but the repo governs software installation & GNOME/Hyprland theming, Tailscale, Syncthing, etc.

##### Main Components
a. Flake Entrypoint
- `flake.nix` (defines inputs: nixpkgs, home‑manager, modules, overlays)
- `flake.lock`
b. NixOS Configuration Layer
- Hosts directory → `hosts/nixvm/default.nix` + `hardware-configuration.nix`
- Aggregates modules from `modules/nixos/*`
c. Home‑Manager Configuration Layer
- User directory under flake outputs → references `modules/home-manager/*`
d. Overlays
- Custom nixpkgs overlays in `overlays/default.nix`
e. Build & Activation Tools
- `nixos-rebuild` CLI → systemd activation on host
- `home-manager` CLI → user profiles
f. External Systems
- GitHub (source of flake)
- Nix package registry (nixpkgs)
- Target VM/hardware
- Optional: Wireguard/NetworkManager, Nextcloud, Firefox sync, Syncthing – shown as post‑activation services.

##### Relationships & Data Flow
- Flake inputs (nixpkgs, overlays, modules) → evaluated by Nix daemon → produces two outputs: “nixosConfigurations.nixvm.config” and “homeConfigurations.blake@…”.
- `nixos-rebuild switch` reads the flake’s `nixosConfiguration` output → builds system closure → pushes config to `/etc/nixos` → systemd switch.
- `home-manager switch` reads the flake’s `homeConfigurations` → builds user profile → symlinks `~/.config` & activates services.

##### Architectural Patterns & Principles
- Functional, declarative infrastructure.
- Composition via flakes: single source of truth, modular design.
- Separation of concerns: OS vs user config.
- Reusability: common modules for desktop, services, programs.

##### Final Checklist
[ ] Flake entrypoint block
[ ] Inputs grouping (nixpkgs, overlays, modules)
[ ] Outputs grouping (nixosConfigurations, homeConfigurations)
[ ] External service nodes

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Inputs
    subgraph "Inputs" 
        direction TB
        nixpkgs["nixpkgs"]:::code
        overlays["overlays"]:::code
        modules_nixos["modules/nixos"]:::code
        modules_home["modules/home-manager"]:::code
        hosts["hosts/nixvm"]:::code
    end

    %% Flake Entrypoint
    flake["flake.nix + flake.lock"]:::code

    %% Evaluation
    nix_daemon["Nix Daemon"]:::evaluator

    %% Outputs
    subgraph "Flake Outputs"
        direction TB
        nixos_out["nixosConfigurations.nixvm"]:::code
        home_out["homeConfigurations.blake"]:::code
    end

    %% Build & Activation Tools
    subgraph "Activation Tools"
        direction TB
        nixos_rebuild["nixos-rebuild switch"]:::tool
        home_manager["home-manager switch"]:::tool
    end

    %% External Services
    subgraph "External Services"
        direction TB
        github["GitHub"]:::external
        registry["Nixpkgs Registry"]:::external
        vm["Target VM/Host"]:::external
        nextcloud["Nextcloud, Syncthing, Tailscale"]:::external
    end

    %% Relationships
    overlays -->|feeds| nixpkgs
    nixpkgs -->|inputs| flake
    modules_nixos -->|inputs| flake
    modules_home -->|inputs| flake
    hosts -->|inputs| flake
    github -->|source| flake

    flake -->|eval| nix_daemon
    nix_daemon -->|produces| nixos_out
    nix_daemon -->|produces| home_out

    nixos_out -->|build & switch| nixos_rebuild
    home_out -->|build & switch| home_manager

    nixos_rebuild -->|deploys to| vm
    home_manager -->|configures| vm

    vm -->|post-activation| nextcloud

    registry -->|provides| nixpkgs

    %% Click Events
    click flake.nix "https://github.com/wendingtuo/nix-config/blob/main/flake.nix"
    click flake.lock "https://github.com/wendingtuo/nix-config/blob/main/flake.lock"
    click hosts "https://github.com/wendingtuo/nix-config/tree/main/hosts/nixvm/"
    click modules_nixos "https://github.com/wendingtuo/nix-config/tree/main/modules/nixos/"
    click modules_home "https://github.com/wendingtuo/nix-config/tree/main/modules/home-manager/"
    click overlays "https://github.com/wendingtuo/nix-config/blob/main/overlays/default.nix"

    %% Styles
    classDef code fill:#D6EAF8,stroke:#1B4F72,stroke-width:1px
    classDef evaluator fill:#D5F5E3,stroke:#1D8348,stroke-width:1px
    classDef tool fill:#FCF3CF,stroke:#B7950B,stroke-width:1px
    classDef external fill:#F5EEF8,stroke:#7D3C98,stroke-width:1px
```
