From 5e944043b18d87a12a8e02a6661e4dc4fb02c2a8 Mon Sep 17 00:00:00 2001 From: Melvin Ragusa Date: Thu, 5 Feb 2026 09:51:31 +0100 Subject: [PATCH] split hosts --- configuration.nix | 18 ----- flake.nix | 36 ++++++--- hosts/README.md | 75 +++++++++++++++++++ hosts/atlas/configuration.nix | 23 ++++++ .../atlas/hardware-configuration.nix | 0 hosts/laptop/configuration.nix | 32 ++++++++ hosts/laptop/hardware-configuration.nix | 63 ++++++++++++++++ hosts/server/configuration.nix | 32 ++++++++ hosts/server/hardware-configuration.nix | 63 ++++++++++++++++ result | 1 + 10 files changed, 314 insertions(+), 29 deletions(-) delete mode 100644 configuration.nix create mode 100644 hosts/README.md create mode 100644 hosts/atlas/configuration.nix rename hardware-configuration.nix => hosts/atlas/hardware-configuration.nix (100%) create mode 100644 hosts/laptop/configuration.nix create mode 100644 hosts/laptop/hardware-configuration.nix create mode 100644 hosts/server/configuration.nix create mode 100644 hosts/server/hardware-configuration.nix create mode 120000 result diff --git a/configuration.nix b/configuration.nix deleted file mode 100644 index 51ab466..0000000 --- a/configuration.nix +++ /dev/null @@ -1,18 +0,0 @@ -# configuration.nix -# Main NixOS configuration entry point -{ - config, - pkgs, - inputs, - lib, - username, - ... -}: - -{ - imports = [ - ./hardware-configuration.nix - ./modules - ./modules/limine-custom-labels.nix - ]; -} diff --git a/flake.nix b/flake.nix index 49164b4..7057dec 100644 --- a/flake.nix +++ b/flake.nix @@ -1,5 +1,5 @@ { - description = "atlas - NixOS Config for Desktop"; + description = "NixOS Configurations - atlas, laptop, and server"; # ═══════════════════════════════════════════════════════════════ # INPUTS @@ -48,18 +48,32 @@ inputs@{ self, nixpkgs, ... }: let system = "x86_64-linux"; - username = "pinj"; # Single source of truth for username + username = "pinj"; + + # Helper function to create NixOS configurations + mkHost = + hostname: + nixpkgs.lib.nixosSystem { + inherit system; + specialArgs = { + inherit inputs username; + }; + modules = [ + ./hosts/${hostname}/configuration.nix + { nixpkgs.overlays = [ inputs.nix-cachyos-kernel.overlays.pinned ]; } + ]; + }; in { - nixosConfigurations.atlas = nixpkgs.lib.nixosSystem { - inherit system; - specialArgs = { - inherit inputs username; - }; - modules = [ - ./configuration.nix - { nixpkgs.overlays = [ inputs.nix-cachyos-kernel.overlays.pinned ]; } - ]; + nixosConfigurations = { + # Desktop - full gaming and media setup + atlas = mkHost "atlas"; + + # Server - headless, core + dev only + server = mkHost "server"; + + # Laptop - desktop environment, no gaming + laptop = mkHost "laptop"; }; }; } diff --git a/hosts/README.md b/hosts/README.md new file mode 100644 index 0000000..a3e9915 --- /dev/null +++ b/hosts/README.md @@ -0,0 +1,75 @@ +# Host Configurations + +This directory contains NixOS configurations for multiple machines. + +## Structure + +``` +hosts/ +├── atlas/ # Desktop gaming machine +│ ├── configuration.nix # Main config (core + hardware + desktop + dev + gaming + services) +│ └── hardware-configuration.nix # Hardware-specific settings +├── laptop/ # Laptop with desktop environment +│ ├── configuration.nix # Main config (core + hardware + desktop + dev + services) +│ └── hardware-configuration.nix # Placeholder - generate on actual machine +└── server/ # Headless server + ├── configuration.nix # Main config (core + hardware[no GPU] + dev + maintenance) + └── hardware-configuration.nix # Placeholder - generate on actual machine +``` + +## Module Assignments + +### All Hosts +- **Core**: boot, networking, users, system, localization +- **Development**: tools, docker, shell + +### Atlas & Laptop Only +- **Hardware**: GPU, audio, storage, power +- **Desktop**: window manager, apps, theming, portals +- **Services**: printing, avahi, maintenance (navidrome only on atlas) + +### Atlas Only +- **Gaming**: steam, gamemode, wine + +### Server Only +- Headless - no desktop or gaming +- SSH enabled for remote management + +## Usage + +### Build a specific host + +```bash +# Build atlas (current desktop) +nixos-rebuild switch --flake .#atlas + +# Build server (once hardware-config is ready) +nixos-rebuild switch --flake .#server + +# Build laptop (once hardware-config is ready) +nixos-rebuild switch --flake .#laptop +``` + +### Setting up a new machine + +1. Install NixOS on the target machine +2. Generate hardware config: + ```bash + sudo nixos-generate-config --show-hardware-config > hardware-configuration.nix + ``` +3. Copy that file to `hosts//hardware-configuration.nix` in this repo +4. Adjust `hosts//configuration.nix` as needed +5. Build and switch: + ```bash + nixos-rebuild switch --flake .# + ``` + +## Adding a new host + +1. Create `hosts//` directory +2. Copy `configuration.nix` from similar host as template +3. Generate `hardware-configuration.nix` on target machine +4. Add to `flake.nix`: + ```nix + nixosConfigurations. = mkHost ""; + ``` diff --git a/hosts/atlas/configuration.nix b/hosts/atlas/configuration.nix new file mode 100644 index 0000000..60b536d --- /dev/null +++ b/hosts/atlas/configuration.nix @@ -0,0 +1,23 @@ +# configuration.nix +# Main NixOS configuration entry point for atlas (desktop) +{ + config, + pkgs, + inputs, + lib, + username, + ... +}: + +{ + imports = [ + ./hardware-configuration.nix + ../../modules/core + ../../modules/hardware + ../../modules/desktop + ../../modules/services + ../../modules/dev + ../../modules/gaming + ../../modules/limine-custom-labels.nix + ]; +} diff --git a/hardware-configuration.nix b/hosts/atlas/hardware-configuration.nix similarity index 100% rename from hardware-configuration.nix rename to hosts/atlas/hardware-configuration.nix diff --git a/hosts/laptop/configuration.nix b/hosts/laptop/configuration.nix new file mode 100644 index 0000000..9dc3d9e --- /dev/null +++ b/hosts/laptop/configuration.nix @@ -0,0 +1,32 @@ +# configuration.nix +# Laptop NixOS configuration - desktop environment, no gaming +{ + config, + pkgs, + inputs, + lib, + username, + ... +}: + +{ + imports = [ + ./hardware-configuration.nix + ../../modules/core + ../../modules/hardware + ../../modules/desktop + ../../modules/dev + ../../modules/services/maintenance.nix + ../../modules/services/printing.nix + ../../modules/services/avahi.nix + # Uncomment if you want music server on laptop: + # ../../modules/services/navidrome.nix + ]; + + # Laptop-specific configuration + # Hostname should be set in hardware-configuration.nix or here + # networking.hostName = "laptop"; + + # Laptop-specific power management tweaks can go here + # The power module already enables power-profiles-daemon +} diff --git a/hosts/laptop/hardware-configuration.nix b/hosts/laptop/hardware-configuration.nix new file mode 100644 index 0000000..17065d2 --- /dev/null +++ b/hosts/laptop/hardware-configuration.nix @@ -0,0 +1,63 @@ +# Do not modify this file! It was generated by ‘nixos-generate-config’ +# and may be overwritten by future invocations. Please make changes +# to /etc/nixos/configuration.nix instead. +{ + config, + lib, + pkgs, + modulesPath, + ... +}: + +{ + imports = [ + (modulesPath + "/installer/scan/not-detected.nix") + ]; + + boot.initrd.availableKernelModules = [ + "xhci_pci" + "ahci" + "nvme" + "usb_storage" + "usbhid" + "uas" + "sd_mod" + ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ "kvm-amd" ]; + boot.extraModulePackages = [ ]; + + fileSystems."/" = { + device = "/dev/mapper/cryptroot"; + fsType = "xfs"; + }; + + boot.initrd.luks.devices."cryptroot".device = + "/dev/disk/by-uuid/ecb02db3-6fe8-499e-9a31-38a8143aa092"; + + # ─── Encrypted Swap ─── + # Include swap keyfile in initramfs (so it's available before root is mounted) + boot.initrd.secrets."/var/lib/secrets/swap.key" = /var/lib/secrets/swap.key; + + boot.initrd.luks.devices."cryptswap" = { + device = "/dev/disk/by-uuid/0e51324d-5929-4b4c-bd6e-a3130cf8adc2"; + keyFile = "/var/lib/secrets/swap.key"; + allowDiscards = true; # Enable TRIM for NVMe SSD + }; + + fileSystems."/boot" = { + device = "/dev/disk/by-uuid/614D-6CCA"; + fsType = "vfat"; + options = [ + "fmask=0022" + "dmask=0022" + ]; + }; + + swapDevices = [ + { device = "/dev/mapper/cryptswap"; } + ]; + + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; + hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; +} diff --git a/hosts/server/configuration.nix b/hosts/server/configuration.nix new file mode 100644 index 0000000..5a368de --- /dev/null +++ b/hosts/server/configuration.nix @@ -0,0 +1,32 @@ +# configuration.nix +# Server NixOS configuration - headless, no desktop environment +{ + config, + pkgs, + inputs, + lib, + username, + ... +}: + +{ + imports = [ + ./hardware-configuration.nix + ../../modules/core + ../../modules/hardware/audio.nix + ../../modules/hardware/storage.nix + ../../modules/hardware/power.nix + ../../modules/dev + ../../modules/services/maintenance.nix + ]; + + # Server-specific overrides + # Hostname should be set in hardware-configuration.nix or here + # networking.hostName = "server"; + + # Enable SSH for remote management + services.openssh.enable = true; + + # Server doesn't need the GPU module (usually headless or different GPU) + # If server has a GPU, add: ../../modules/hardware/gpu-amd.nix +} diff --git a/hosts/server/hardware-configuration.nix b/hosts/server/hardware-configuration.nix new file mode 100644 index 0000000..17065d2 --- /dev/null +++ b/hosts/server/hardware-configuration.nix @@ -0,0 +1,63 @@ +# Do not modify this file! It was generated by ‘nixos-generate-config’ +# and may be overwritten by future invocations. Please make changes +# to /etc/nixos/configuration.nix instead. +{ + config, + lib, + pkgs, + modulesPath, + ... +}: + +{ + imports = [ + (modulesPath + "/installer/scan/not-detected.nix") + ]; + + boot.initrd.availableKernelModules = [ + "xhci_pci" + "ahci" + "nvme" + "usb_storage" + "usbhid" + "uas" + "sd_mod" + ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ "kvm-amd" ]; + boot.extraModulePackages = [ ]; + + fileSystems."/" = { + device = "/dev/mapper/cryptroot"; + fsType = "xfs"; + }; + + boot.initrd.luks.devices."cryptroot".device = + "/dev/disk/by-uuid/ecb02db3-6fe8-499e-9a31-38a8143aa092"; + + # ─── Encrypted Swap ─── + # Include swap keyfile in initramfs (so it's available before root is mounted) + boot.initrd.secrets."/var/lib/secrets/swap.key" = /var/lib/secrets/swap.key; + + boot.initrd.luks.devices."cryptswap" = { + device = "/dev/disk/by-uuid/0e51324d-5929-4b4c-bd6e-a3130cf8adc2"; + keyFile = "/var/lib/secrets/swap.key"; + allowDiscards = true; # Enable TRIM for NVMe SSD + }; + + fileSystems."/boot" = { + device = "/dev/disk/by-uuid/614D-6CCA"; + fsType = "vfat"; + options = [ + "fmask=0022" + "dmask=0022" + ]; + }; + + swapDevices = [ + { device = "/dev/mapper/cryptswap"; } + ]; + + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; + hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; +} diff --git a/result b/result new file mode 120000 index 0000000..85deb9b --- /dev/null +++ b/result @@ -0,0 +1 @@ +/nix/store/32cir8faxycc2f3i5gpq2c73vsgrfzwr-nixos-system-nix-26.05.20260204.00c21e4 \ No newline at end of file