# manas73/nix-config architecture

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

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

## Overview

##### Main Components
- Entry Point: At the heart is flake.nix – the primary entry point for the entire configuration.
- Hosts & Machine-Specific Configurations: The hosts/ directory contains configurations for individual machines (e.g., “alfred,” “manass-KY4RYYHFF6”), which are applied by the sync scripts.
- System Modules: The system_modules/ directory houses reusable Nix modules dedicated to system-level functionalities like the desktop manager (with submodules for Plasma6 or SDDM and themes), font, keyring, shell, and window manager (supporting various window managers like Hyprland, i3, etc.). These encapsulate the configuration and settings that affect the operating system overall.
- User Modules: The user_modules/ directory handles Home Manager configurations for individual software groups such as browsers, communication (e.g., Slack, Zoom), development tools (e.g., DataGrip, Postman), office suites, terminals, and utility applications.
- Darwin Modules: Special configurations for macOS (in darwin_modules/) are segregated similarly into categories (e.g., browsers, communication, development, office, terminal, utility).
- User-Specific Configurations: The users/ directory contains personal configurations and further customizations for individual accounts.

##### Relationships & Interactions
- The flake.nix acts as the orchestrator, referencing system_modules, user_modules, hosts, and darwin_modules as needed based on the target deployment (NixOS vs. Darwin).
- The sync scripts (sync-system.sh, sync-user.sh, sync.sh, and sync-darwin.sh) drive the deployment process by applying configurations from the corresponding modules to the target machine.
- The hosts/ configurations override or add machine-specific nuances to the base settings provided by the modules.
- There is a clear separation between system-level configurations (system_modules) and user-level configurations (user_modules), which are then applied via Home Manager on NixOS or similar tools on macOS.

##### Architectural Patterns / Design Principles
- Modular Design: Each configuration aspect (e.g., browsers, development tools, window managers) is encapsulated in its own module, making it easy to extend or override.
- Separation of Concerns: Different directories are solely dedicated to system modules, user modules, and host configurations. There’s also a dedicated set of modules for macOS (“darwin_modules”), which recognizes platform-specific needs.
- Reusability and Extensibility: The create_module.sh script hints at a workflow for easily adding new configuration modules. This reinforces the architecture’s modular and extensible nature.
- Declarative Infrastructure: Through Nix Flakes and declarative configuration files, the project gives a clear mapping between desired system states and their corresponding module configurations.

##### Relevant Technologies and Frameworks
- NixOS & Nix Flakes: The entire configuration is managed via Nix’s declarative package management and configuration system.
- Home Manager: For applying user-specific configurations.
- Nix-Darwin: For handling macOS-specific configurations.
- nix-sops (via secrets.yaml): For safely managing sensitive data.
- Shell scripts (sync.sh variants): For deployment orchestration.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entry Point
    EP("Entry Point (flake.nix)"):::entry

    %% Major Configuration Components
    HC("Hosts Config (hosts/)"):::host
    SM("System Modules"):::system
    UM("User Modules"):::user
    DM("Darwin Modules"):::darwin
    UC("User Configs (users/)"):::user

    %% Deployment & Module Creation
    DS("Deployment & Sync Scripts"):::script
    MCS("Module Creation Script"):::moduleCreation
    DSYS("Deployed System"):::script

    %% Subgraphs for System Modules
    subgraph "System Modules"
        SM1("Desktop Manager"):::system
        SM2("Font"):::system
        SM3("Keyring"):::system
        SM4("Shell"):::system
        SM5("Window Manager"):::system
    end

    %% Subgraphs for User Modules
    subgraph "User Modules"
        UM1("Browser"):::user
        UM2("Communication"):::user
        UM3("Development"):::user
        UM4("Office Suite"):::user
        UM5("Terminal"):::user
        UM6("Utility"):::user
    end

    %% Subgraphs for Darwin Modules
    subgraph "Darwin Modules"
        DM1("Browser"):::darwin
        DM2("Communication"):::darwin
        DM3("Development"):::darwin
        DM4("Office Suite"):::darwin
        DM5("Terminal"):::darwin
        DM6("Utility"):::darwin
    end

    %% Subgraph for User Configurations
    subgraph "User Configs"
        UC1("Base User Config"):::user
        UC2("Manas User Config"):::user
        UC3("MS NixOS Config"):::user
    end

    %% Connections from Entry Point to Modules
    EP -->|"aggregates"| HC
    EP -->|"aggregates"| SM
    EP -->|"aggregates"| UM
    EP -->|"aggregates"| DM
    EP -->|"aggregates"| UC

    %% Connections from each config block to Deployment Scripts
    HC --> DS
    SM --> DS
    UM --> DS
    DM --> DS
    UC --> DS

    %% Deployment Process Flow
    DS --> DSYS

    %% Module Creation Script feeds into configuration modules
    MCS --> SM
    MCS --> UM
    MCS --> DM

    %% Styling Definitions
    classDef entry fill:#f3e5f5,stroke:#6a1b9a,stroke-width:2px;
    classDef system fill:#bbdefb,stroke:#0d47a1,stroke-width:2px;
    classDef user fill:#c8e6c9,stroke:#1b5e20,stroke-width:2px;
    classDef darwin fill:#ffe0b2,stroke:#e65100,stroke-width:2px;
    classDef host fill:#ffcdd2,stroke:#b71c1c,stroke-width:2px;
    classDef script fill:#b2ebf2,stroke:#006064,stroke-width:2px;
    classDef moduleCreation fill:#f8bbd0,stroke:#880e4f,stroke-width:2px;

    %% Click Events
    click EP "https://github.com/manas73/nix-config/blob/main/flake.nix"
    click HC "https://github.com/manas73/nix-config/tree/main/hosts/"
    click SM1 "https://github.com/manas73/nix-config/tree/main/system_modules/desktop_manager"
    click SM2 "https://github.com/manas73/nix-config/tree/main/system_modules/font"
    click SM3 "https://github.com/manas73/nix-config/tree/main/system_modules/keyring"
    click SM4 "https://github.com/manas73/nix-config/tree/main/system_modules/shell"
    click SM5 "https://github.com/manas73/nix-config/tree/main/system_modules/window_manager"
    click UM1 "https://github.com/manas73/nix-config/tree/main/user_modules/browser"
    click UM2 "https://github.com/manas73/nix-config/tree/main/user_modules/communication"
    click UM3 "https://github.com/manas73/nix-config/tree/main/user_modules/development"
    click UM4 "https://github.com/manas73/nix-config/tree/main/user_modules/office_suite"
    click UM5 "https://github.com/manas73/nix-config/tree/main/user_modules/terminal"
    click UM6 "https://github.com/manas73/nix-config/tree/main/user_modules/utility"
    click DM1 "https://github.com/manas73/nix-config/tree/main/darwin_modules/browser"
    click DM2 "https://github.com/manas73/nix-config/tree/main/darwin_modules/communication"
    click DM3 "https://github.com/manas73/nix-config/tree/main/darwin_modules/development"
    click DM4 "https://github.com/manas73/nix-config/tree/main/darwin_modules/office_suite"
    click DM5 "https://github.com/manas73/nix-config/tree/main/darwin_modules/terminal"
    click DM6 "https://github.com/manas73/nix-config/tree/main/darwin_modules/utility"
    click UC1 "https://github.com/manas73/nix-config/blob/main/users/base_user.nix"
    click UC2 "https://github.com/manas73/nix-config/tree/main/users/manas.s/"
    click UC3 "https://github.com/manas73/nix-config/tree/main/users/ms-nixos/"
    click MCS "https://github.com/manas73/nix-config/blob/main/create_module.sh"
    click DS "https://github.com/manas73/nix-config/blob/main/sync-system.sh"
    click DS "https://github.com/manas73/nix-config/blob/main/sync-user.sh"
    click DS "https://github.com/manas73/nix-config/blob/main/sync-darwin-work.sh"
    click DS "https://github.com/manas73/nix-config/blob/main/sync.sh"
```
