docs: Overhaul all the documentation
This commit is contained in:
@@ -4,6 +4,13 @@
|
||||
|
||||
{ config, lib, ... }:
|
||||
|
||||
# ============================================================================
|
||||
# Boot & Storage Configuration
|
||||
# ============================================================================
|
||||
# This module defines the Disko partition layout and bootloader settings.
|
||||
# It exposes 'host.filesystem' options to allow per-host overrides of
|
||||
# the target device and swap size.
|
||||
|
||||
{
|
||||
options.host = {
|
||||
filesystem = {
|
||||
@@ -19,6 +26,7 @@
|
||||
};
|
||||
|
||||
config = {
|
||||
# Enable Disko for declarative partitioning
|
||||
disko.enableConfig = true;
|
||||
|
||||
disko.devices = {
|
||||
@@ -28,6 +36,7 @@
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
# EFI System Partition
|
||||
ESP = {
|
||||
name = "ESP";
|
||||
label = "BOOT";
|
||||
@@ -42,6 +51,7 @@
|
||||
};
|
||||
};
|
||||
|
||||
# Swap Partition (size configurable per host)
|
||||
swap = {
|
||||
name = "swap";
|
||||
label = "swap";
|
||||
@@ -49,6 +59,7 @@
|
||||
content = { type = "swap"; };
|
||||
};
|
||||
|
||||
# Root Partition (takes remaining space)
|
||||
root = {
|
||||
name = "root";
|
||||
label = "root";
|
||||
@@ -65,7 +76,7 @@
|
||||
};
|
||||
};
|
||||
|
||||
# Bootloader.
|
||||
# Bootloader Configuration
|
||||
boot = {
|
||||
loader.systemd-boot.enable = true;
|
||||
loader.efi.canTouchEfiVariables = true;
|
||||
|
||||
@@ -1,11 +1,21 @@
|
||||
{ inputs, hosts ? import ../inventory.nix, ... }:
|
||||
|
||||
# ============================================================================
|
||||
# Host Generator
|
||||
# ============================================================================
|
||||
# This file contains the logic to generate NixOS configurations for all hosts
|
||||
# defined in inventory.nix. It handles:
|
||||
# 1. Common module imports (boot, users, software).
|
||||
# 2. Host-specific overrides (filesystem, enabled users).
|
||||
# 3. External flake integration for system overrides.
|
||||
|
||||
let
|
||||
nixpkgs = inputs.nixpkgs;
|
||||
lib = nixpkgs.lib;
|
||||
home-manager = inputs.home-manager;
|
||||
disko = inputs.disko;
|
||||
|
||||
# Modules shared by all hosts
|
||||
commonModules = [
|
||||
./boot.nix
|
||||
./user-config.nix
|
||||
@@ -29,7 +39,23 @@ let
|
||||
}
|
||||
];
|
||||
|
||||
# Helper to create a single NixOS system configuration
|
||||
mkHost = { hostName, system ? "x86_64-linux", extraModules ? [ ] }:
|
||||
let
|
||||
# Load users.nix to find external user flakes
|
||||
# We use legacyPackages to evaluate the simple data structure of users.nix
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
usersData = import ../users.nix { inherit pkgs; };
|
||||
accounts = usersData.modules.users.accounts or {};
|
||||
|
||||
# Extract flakeUrls and convert to modules
|
||||
userFlakeModules = lib.mapAttrsToList (name: user:
|
||||
if (user ? flakeUrl && user.flakeUrl != "") then
|
||||
(builtins.getFlake user.flakeUrl).nixosModules.default
|
||||
else
|
||||
{}
|
||||
) accounts;
|
||||
in
|
||||
lib.nixosSystem {
|
||||
inherit system;
|
||||
|
||||
@@ -37,13 +63,14 @@ let
|
||||
|
||||
modules =
|
||||
commonModules
|
||||
++ userFlakeModules
|
||||
++ extraModules
|
||||
++ [
|
||||
{ networking.hostName = hostName; }
|
||||
];
|
||||
};
|
||||
|
||||
# Function to generate a set of hosts
|
||||
# Function to generate a set of hosts based on inventory count and overrides
|
||||
mkHostGroup = { prefix, count, system ? "x86_64-linux", extraModules ? [], deviceOverrides ? {} }:
|
||||
lib.listToAttrs (map (i: {
|
||||
name = "${prefix}${toString i}";
|
||||
@@ -62,7 +89,7 @@ let
|
||||
then externalFlake.nixosModules.default
|
||||
else {};
|
||||
|
||||
# Config override module
|
||||
# Config override module (filesystem, users)
|
||||
overrideModule = { ... }:
|
||||
let
|
||||
# Remove special keys that are not filesystem options
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
{ pkgs, config, lib, ... }:
|
||||
|
||||
# ============================================================================
|
||||
# User Configuration Module
|
||||
# ============================================================================
|
||||
# This module defines the schema for user accounts and handles their creation.
|
||||
# It bridges the gap between the data in 'users.nix' and the actual NixOS
|
||||
# and Home Manager configuration.
|
||||
|
||||
let
|
||||
# Submodule defining the structure of a user account
|
||||
userSubmodule = lib.types.submodule {
|
||||
options = {
|
||||
isNormalUser = lib.mkOption { type = lib.types.bool; default = true; };
|
||||
@@ -12,6 +21,7 @@ let
|
||||
extraImports = lib.mkOption { type = lib.types.listOf lib.types.path; default = []; };
|
||||
flakeUrl = lib.mkOption { type = lib.types.str; default = ""; description = "URL of a flake to import Home Manager configuration from (e.g. github:user/dotfiles)."; };
|
||||
opensshKeys = lib.mkOption { type = lib.types.listOf lib.types.str; default = []; description = "List of SSH public keys for the user."; };
|
||||
shell = lib.mkOption { type = lib.types.nullOr lib.types.package; default = null; description = "The shell for this user."; };
|
||||
};
|
||||
};
|
||||
in
|
||||
@@ -19,7 +29,7 @@ in
|
||||
options.modules.users = {
|
||||
shell = lib.mkOption {
|
||||
type = lib.types.package;
|
||||
default = pkgs.zsh;
|
||||
default = pkgs.bash;
|
||||
description = "The default shell for users.";
|
||||
};
|
||||
accounts = lib.mkOption {
|
||||
@@ -35,6 +45,7 @@ in
|
||||
};
|
||||
|
||||
config = {
|
||||
# Default enabled users (always present)
|
||||
modules.users.enabledUsers = [ "root" "engr-ugaif" ];
|
||||
|
||||
# Generate NixOS users
|
||||
@@ -53,7 +64,7 @@ in
|
||||
description = if user.description != null then user.description else lib.mkDefault "";
|
||||
openssh.authorizedKeys.keys = user.opensshKeys;
|
||||
packages = finalPackages;
|
||||
shell = config.modules.users.shell;
|
||||
shell = if user.shell != null then user.shell else config.modules.users.shell;
|
||||
}
|
||||
) enabledAccounts;
|
||||
|
||||
@@ -68,8 +79,7 @@ in
|
||||
enabledAccounts = lib.filterAttrs (name: _: lib.elem name config.modules.users.enabledUsers) config.modules.users.accounts;
|
||||
in
|
||||
lib.mapAttrs (name: user: { ... }: {
|
||||
imports = user.extraImports ++ [ ../sw/theme.nix ../sw/nvim.nix ] ++
|
||||
(lib.optional (user.flakeUrl != "") (builtins.getFlake user.flakeUrl).homeManagerModules.default);
|
||||
imports = user.extraImports ++ [ ../sw/theme.nix ../sw/nvim.nix ];
|
||||
home.username = name;
|
||||
home.homeDirectory = if name == "root" then "/root" else "/home/${name}";
|
||||
home.stateVersion = "25.11";
|
||||
|
||||
Reference in New Issue
Block a user