# mtlks/nixcfg architecture

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

- Interactive diagram: https://gitdiagram.com/mtlks/nixcfg
- Repository: https://github.com/mtlks/nixcfg

## Overview

Key Components to Include:
##### Flake/Root
- Represents the Nix flake entry point and the overall configuration management.
- Includes files like flake.nix and flake.lock, serving as the central orchestrator.
- Directs commands (e.g., nixos-rebuild) that target a given configuration (e.g., glacier or snowdrift).

##### Hosts
- Located in the “hosts” directory. There are separate configurations for “desktop” and “laptop.”
- Each host has a configuration file (configuration.nix) and a hardware-configuration.nix, which specify that machine’s settings and hardware details.
- These components feed into the final system build for each respective machine.

##### Modules
- Found in the “modules” directory, these are the building blocks that define specific application or service configurations (e.g., alacritty, firefox, i3, polybar, vscode).
- Each module generally contains a default.nix file that encapsulates its configuration logic.
- There is also a template and theme file (as seen with rofi) that can be used for consistency and styling.

##### Profiles
- Located under the “profiles” directory, with different profiles like “glacier” and “snowdrift.”
- Each profile (configuration.nix) likely composes specific modules and settings to cater to different environments or user preferences.
- Profiles serve as a higher-level abstraction that aggregates modules, host configurations, and possibly user settings.

##### Users
- Contained within the “users” directory, here you have at least one user configuration (mtlks.nix).
- These define user-specific settings that can be applied across the system configuration.

- At the highest level, represent the Nix flake system (flake.nix/flake.lock) as the starting point. This is the root that coordinates all parts.
- Separate but linked branches for Hosts, Modules, Profiles, and Users:
– Profiles: Represent the profiles (glacier, snowdrift) as nodes that import and compose various modules and then link to the host nodes.
– Users: Create a separate portion where user configurations reside, indicating how they are integrated into the profiles or directly into the system configuration.
– From the flake root to profiles.
– From profiles to hosts (i.e., “glacier” or “snowdrift” being applied to specific hardware configurations).
– From profiles, indicate inclusion of specific modules.
- Optionally, include callouts or notes to highlight configuration files that are central to switching or testing builds (as per the commands in the README).

Architectural Patterns and Design Principles:
- Modularity: The design is very modular, keeping service configurations (modules) separate from hardware-specific implementations (hosts) and aggregated settings (profiles).
- Separation of Concerns: Different directories and configurations handle distinct concerns: system-level hardware setup (hosts), service setup (modules), environment standards (profiles), and user-specific settings.

Since this is a system configuration and deployment project for NixOS:
– Emphasize the separation between host-specific settings and modular services.
– Highlight the “profiles” as an abstraction layer which enables you to switch between different system configurations (as shown by the glacier and snowdrift commands).
– Demonstrate the integration of version-controlled, reproducible builds managed by the flake system.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Flake Root
    Flake["Flake/Root (flake.nix & flake.lock)"]:::flake

    %% Profiles
    subgraph "Profiles"
        Glacier["Profile: Glacier"]:::profile
        Snowdrift["Profile: Snowdrift"]:::profile
    end

    %% Modules
    subgraph "Modules"
        Alacritty["Module: Alacritty"]:::module
        Firefox["Module: Firefox"]:::module
        I3["Module: i3"]:::module
        Polybar["Module: Polybar"]:::module
        VSCode["Module: VSCode"]:::module
        Rofi["Module: Rofi"]:::module
    end

    %% Users
    subgraph "Users"
        Mtlks["User: mtlks"]:::user
    end

    %% Hosts
    subgraph "Hosts"
        Desktop["Host: Desktop (config & hardware)"]:::host
        Laptop["Host: Laptop (config & hardware)"]:::host
    end

    %% Connections from Flake to Profiles
    Flake -->|"builds"| Glacier
    Flake -->|"builds"| Snowdrift

    %% Profiles to Hosts
    Glacier -->|"appliedTo"| Desktop
    Snowdrift -->|"appliedTo"| Laptop

    %% Profiles to Modules (each profile includes modules)
    Glacier -->|"includes"| Alacritty
    Glacier -->|"includes"| Firefox
    Glacier -->|"includes"| I3
    Glacier -->|"includes"| Polybar
    Glacier -->|"includes"| VSCode
    Glacier -->|"includes"| Rofi

    Snowdrift -->|"includes"| Alacritty
    Snowdrift -->|"includes"| Firefox
    Snowdrift -->|"includes"| I3
    Snowdrift -->|"includes"| Polybar
    Snowdrift -->|"includes"| VSCode
    Snowdrift -->|"includes"| Rofi

    %% Profiles merge with User configurations
    Glacier -->|"merges"| Mtlks
    Snowdrift -->|"merges"| Mtlks

    %% Click Events
    click Flake "https://github.com/mtlks/nixcfg/blob/main/flake.nix"
    click Glacier "https://github.com/mtlks/nixcfg/blob/main/profiles/glacier/configuration.nix"
    click Snowdrift "https://github.com/mtlks/nixcfg/blob/main/profiles/snowdrift/configuration.nix"
    click Desktop "https://github.com/mtlks/nixcfg/blob/main/hosts/desktop/configuration.nix"
    click Laptop "https://github.com/mtlks/nixcfg/blob/main/hosts/laptop/configuration.nix"
    click Alacritty "https://github.com/mtlks/nixcfg/blob/main/modules/alacritty/default.nix"
    click Firefox "https://github.com/mtlks/nixcfg/blob/main/modules/firefox/default.nix"
    click I3 "https://github.com/mtlks/nixcfg/blob/main/modules/i3/default.nix"
    click Polybar "https://github.com/mtlks/nixcfg/blob/main/modules/polybar/default.nix"
    click VSCode "https://github.com/mtlks/nixcfg/blob/main/modules/vscode/default.nix"
    click Rofi "https://github.com/mtlks/nixcfg/blob/main/modules/rofi/default.nix"
    click Mtlks "https://github.com/mtlks/nixcfg/blob/main/users/mtlks.nix"

    %% Styles
    classDef flake fill:#cce5ff,stroke:#007bff,stroke-width:2px;
    classDef profile fill:#fff3cd,stroke:#ff8800,stroke-width:2px;
    classDef module fill:#f8d7da,stroke:#dc3545,stroke-width:2px;
    classDef host fill:#d4edda,stroke:#28a745,stroke-width:2px;
    classDef user fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
```
