# baitinq/nixos-config architecture

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

- Interactive diagram: https://gitdiagram.com/baitinq/nixos-config
- Repository: https://github.com/baitinq/nixos-config

## Overview

##### Main Components
- Flake Entry Point:
– flake.nix & flake.lock: The root that ties together all the configurations.
- Modules:
– The “modules” directory contains encapsulated NixOS module configurations (e.g., bluetooth, doas, email, fonts, pipewire, power-save, virtualization, xorg).
- Overlays:
– The “overlays” directory holds nixpkgs overlays that patch or extend package definitions.
- Packages:
– Additional packages are defined and compiled within “packages” to extend or modify the base system.
- Secrets:
– The “secrets” folder (secured by git-crypt) includes encrypted secrets and assets like fonts and WireGuard keys.
- Dotfiles:
– The “dotfiles” directory contains user configuration files for various applications and environments (shell, emacs, tmux, sway, etc.).
- Hosts:
– This directory encapsulates host-specific configurations. It contains a “default.nix”, “configuration.nix”, "home.nix", and sub-folders for distinct hosts (like “luna” and “phobos”) to manage different system roles.
- Hardware:
– The “hardware” directory breaks down configurations based on physical hardware (laptop, chromebook, virtualbox, thinkpad) such as disk partitioning and hardware-specific Nix expressions.
- Documentation:
– Although not part of the runtime configuration, the “Documentation” folder provides installation guides and partitioning details, which is crucial for deployment.

##### Relationships and Interactions
– The central flake (flake.nix) includes and calls upon each component (modules, overlays, packages, secrets, etc.) to build the final configuration.
– Host-specific configurations (found under “hosts”) use the common components and import additional host-tailored settings.
– Hardware-specific directories supply low-level system settings (disk setup, partitions) that are then referenced or merged into host configurations.
– Dotfiles are deployed as part of the user’s environment, tying into both the host configuration and user-level customizations.
– Dependencies exist between the overlays and packages—for example, overlays are used to patch or extend default package definitions, which are then combined with modules.
– Encrypted secrets are imported into the configuration securely via git-crypt for handling sensitive configurations (like passwords and encryption keys).

##### Architectural Patterns and Important Design Principles
- Modularity:
– Every major component (modules, overlays, packages, etc.) is isolated so that configurations can be easily adapted or replaced.
- Customizability and Extensibility:
– Host and hardware configurations allow bespoke setups per environment, perfect for users needing varied deployments.
- Reproducibility:
– The entire configuration is managed via flakes, ensuring that builds are reproducible and easy to deploy.
- Security:
– Incorporation of git-crypt for managing sensitive data (secrets) and secure partitioning with BTRFS.
- Declarative Infrastructure:
– The configuration uses Nix expressions, meaning that the system’s full state is declared within the code structure.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A("Flake Entry (flake.nix & flake.lock)"):::flake
    B("Modules (Bluetooth, Doas, Email, Fonts, Pipewire, Power-save, Virtualisation, Xorg)"):::module
    C("Overlays (Base/Patches)"):::overlay
    D("Packages (Kindlegen, LEmacs, Swhkd)"):::package
    E("Secrets (Encrypted via git-crypt)"):::secret
    F("Dotfiles (User configurations: Bash, Emacs, NMV, Sway, etc.)"):::dotfile
    G("Hosts (Global & Host-specific: Luna, Phobos)"):::host
    H("Hardware (Chromebook, Laptop, PC, Thinkpad, Virtualbox)"):::hardware
    I("Documentation (Installation guides, Partitioning)"):::doc

    A -->|"includes"| B
    A -->|"includes"| C
    A -->|"includes"| D
    A -->|"includes"| E
    A -->|"includes"| F
    A -->|"includes"| G
    A -->|"includes"| H
    A -->|"includes"| I

    C -->|"patches"| D
    G -->|"merges with"| F
    G -->|"references"| H

    %% Click Events
    click A "https://github.com/baitinq/nixos-config/blob/master/flake.nix"
    click B "https://github.com/baitinq/nixos-config/tree/master/modules/"
    click C "https://github.com/baitinq/nixos-config/tree/master/overlays/"
    click D "https://github.com/baitinq/nixos-config/tree/master/packages/"
    click E "https://github.com/baitinq/nixos-config/tree/master/secrets/"
    click F "https://github.com/baitinq/nixos-config/tree/master/dotfiles/"
    click G "https://github.com/baitinq/nixos-config/tree/master/hosts/"
    click H "https://github.com/baitinq/nixos-config/tree/master/hardware/"
    click I "https://github.com/baitinq/nixos-config/tree/master/Documentation/"

    %% Styles
    classDef flake fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef module fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef overlay fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef package fill:#ffccff,stroke:#333,stroke-width:2px;
    classDef secret fill:#ff9999,stroke:#333,stroke-width:2px;
    classDef dotfile fill:#fff2cc,stroke:#333,stroke-width:2px;
    classDef host fill:#ccffff,stroke:#333,stroke-width:2px;
    classDef hardware fill:#e2f0d9,stroke:#333,stroke-width:2px;
    classDef doc fill:#e6e6e6,stroke:#333,stroke-width:2px;
```
