NixOS Configuration Structure Overview

The NixOS setup in this repository (nixri) is built around Nix Flakes and is heavily modularized to provide a clean, maintainable, and easily customizable environment.

High-Level Directory Structure

  • flake.nix & flake.lock: The core entry points of the configuration. It defines inputs (like NixOS unstable, Home Manager, sops-nix, etc.) and constructs the NixOS systems.
  • hosts/: Contains configurations specific to individual machines (hosts).
  • modules/: The core of the repository, containing reusable functional blocks (core system settings, programs, desktop environments, etc.).
  • installer.nix: A work-in-progress installer package to help set up the configuration on a new machine.

Host Configuration: hosts/

This directory manages machine-specific settings. By default, there is a default host, but you can easily duplicate it to create configurations for multiple computers (e.g., Laptop, Desktop).

  • configuration.nix: The primary NixOS configuration file for the host. It sets the hostname, timezone, locale, and imports necessary modules.
  • hardware-configuration.nix: The machine-specific hardware setup (filesystems, swap, kernel modules) typically generated by nixos-generate-config.
  • host-packages.nix: A dedicated list of packages meant only for this specific host.
  • variables.nix: A highly convenient configuration file that defines user preferences as variables (e.g., desktop = "niri", browser = "zen", editor = "neovim"). These variables are used dynamically by the modules to install and configure the correct software.

Modular Configuration: modules/

This repository uses a modular design to keep the configuration organized. The main entry point for these modules is modules/default.nix, which evaluates the variables defined in your hostโ€™s variables.nix and imports the appropriate sub-modules.

  • core/: Foundational system configurations that are almost universally applied. Includes setups for:
    • System`boot, hardware, memory,games, fonts, dns, and networking cofig.
    • Core utilities, shell environments e.g.ย bash, fish, and display & file manager.
    • Users, security, printing, and services.
  • desktop/: Contains configurations for Desktop Environments or Window Managers. Currently focused on Wayland setups like Niri.
  • hardware/: Hardware-specific configurations, such as video drivers (NVIDIA, AMD, Intel) and extra drive mounts.
  • programs/: Application-specific configurations. Separated into logical categories:
    • browser/: Web browsers (e.g., Firefox, Zen-browser).
    • terminal/: Terminal emulators (e.g., Kitty, Fish).
    • editor/: Text editors and IDEs (e.g., Neovim, VSCode, Antigravity).
    • cli/: Command-line tools and utilities (e.g., Tmux, Btop, Lazygit).
    • media/: Media and communication apps (e.g., Discord, Spicetify, mpv).
    • tuning/: Power management tools.

Flake Setup: flake.nix

The flake.nix file binds everything together:

  • Inputs: Pulls from nixos-unstable for up-to-date packages. It also brings in powerful community tools like home-manager (for user-level dotfiles), sops-nix (for secret management), niri flake, nvf (Neovim flake), and various other flakes for themes, browsers (e.g., zen-browser), and specific applications.
  • Outputs: Defines the nixosConfigurations. The mkHost function automatically constructs the NixOS system for each host by injecting standard modules, overlays, and system variables, creating a highly reproducible build.