refactor: Restructure NixOS configuration to a flake-based multi-host setup with common and host-specific modules.

This commit is contained in:
Nimmo 2026-01-24 23:37:55 +00:00
parent c69c8fa81e
commit afadfd68dd
8 changed files with 351 additions and 472 deletions

343
README.md
View file

@ -1,290 +1,147 @@
# Nimmo's NixOS Setup Guide (Host: electra)
# Nimmo's NixOS Configurations (Electra & Lena)
## 0. Pre-Installation Preparation (Do this NOW on CachyOS)
This repository manages the NixOS configurations for multiple machines using **Flakes**.
Since you are hosting this on `git.nimmog.uk`, we will create the config locally and push it before booting the installer.
* **Electra:** Framework 16 (Strix Point + RTX 5070) - High Performance / Gaming.
* **Lena:** Secondary Laptop - Standard / Light Use.
1. **Create the Repository on your Server:**
## 1. Directory Structure
* Log into `https://git.nimmog.uk`.
* `common/`: Shared configuration (Users, GUI Apps, CLI Tools, Fonts, Plasma Settings).
* `hosts/electra/`: Electra-specific hardware config, kernel parameters, and strict boot modes.
* `hosts/lena/`: Lena-specific hardware config.
* `flake.nix`: Entry point defining both hosts.
* Create a new **empty** repository named `nixos-config`.
---
* *Do not initialize with README or license (keep it empty).*
## 2. Initial Setup (Electra Only - BIOS)
2. **Create Files Locally:**
Open a terminal in CachyOS:
```
mkdir ~/nixos-config
cd ~/nixos-config
# Run the creation script provided by Gemini to generate files here
```
3. **Initialize & Push:**
```
git init
git branch -M main
git add .
git commit -m "Initial commit: Setup for electra"
# Replace with your actual SSH or HTTPS URL
git remote add origin https://git.nimmog.uk/YOUR_USERNAME/nixos-config.git
git push -u origin main
```
## 1. Initial BIOS Setup (Crucial)
Before booting NixOS, you must configure the BIOS to handle the memory split for your LLMs.
1. Reboot and enter BIOS (usually F2 or Del).
**Crucial:** Before booting NixOS on Electra, you must configure the BIOS to handle the memory split for LLMs.
1. Reboot and enter BIOS (F2 or Del).
2. Find **Graphics Memory**, **UMA Frame Buffer**, or **iGPU Memory**.
3. Set this to **16G** (or "Game Optimized").
3. Set this to **16G** (or "Game Optimized" if it equates to high memory).
---
## 2. Installation
## 3. Installation Guide
Once you have booted the **NixOS Unstable ISO**, choose your path below.
Once you have booted the **NixOS Unstable ISO**:
### Path A: Fresh Install (Wipe Everything)
### Step 1: Disk Partitioning & Mounting
*Use this if you want to start completely fresh.*
Follow standard NixOS procedure (or see previous version of this README for BTRFS subvolume layout). Mount your root to `/mnt`.
1. **Partition:** `cfdisk /dev/nvme0n1` (Delete all, Create 4G Boot + Remaining Root).
### Step 2: Clone Configuration
2. **Format:**
We will clone the repo into the user's Scripts folder (persistent location), but for installation we can clone it temporarily or directly to the target.
```
mkfs.fat -F 32 -n BOOT /dev/nvme0n1p1
mkfs.btrfs -L nixos /dev/nvme0n1p2
**Recommended approach for Install:**
1. **Clone to /mnt/etc/nixos (Temporary):**
```bash
# Replace USERNAME with your git user
nix-shell -p git --run "git clone https://git.nimmog.uk/nimmo/nixos-config.git /mnt/etc/nixos"
```
3. **Create Subvolumes:**
2. **Generate Hardware Config:**
```
mount /dev/nvme0n1p2 /mnt
btrfs subvolume create /mnt/@
btrfs subvolume create /mnt/@home
btrfs subvolume create /mnt/@nix
umount /mnt
```
4. **Proceed to Step "Mounting" below.**
### Path B: Migration (Keep /home data)
*Use this to delete CachyOS but KEEP your existing data in `@home`.*
1. **Mount the Top-Level Partition:**
```
mount /dev/nvme0n1p2 /mnt
```
2. **List & Cleanup:**
Run `ls -a /mnt`.
**Delete the OLD Operating System:**
*Warning: Be extremely careful. Do NOT delete `@home`.*
```
# Delete the old root and system folders
btrfs subvolume delete /mnt/@
btrfs subvolume delete /mnt/@root
btrfs subvolume delete /mnt/@srv
btrfs subvolume delete /mnt/@log
btrfs subvolume delete /mnt/@cache
btrfs subvolume delete /mnt/@tmp
btrfs subvolume delete /mnt/@.snapshots
```
3. **Prepare NixOS Subvolumes:**
```
btrfs subvolume create /mnt/@
btrfs subvolume create /mnt/@nix
```
*(Note: Ensure your existing home data is in a subvolume named `@home`.)*
4. **Format Boot Partition:**
```
mkfs.fat -F 32 -n BOOT /dev/nvme0n1p1
```
5. **Unmount:**
```
umount /mnt
```
### Mounting (Common for Both Paths)
1. **Mount Root (`@`):**
```
mount -o compress=zstd,subvol=@ /dev/nvme0n1p2 /mnt
```
2. **Create Mount Points:**
```
mkdir -p /mnt/{home,nix,boot}
```
3. **Mount Home (`@home`):**
```
mount -o compress=zstd,subvol=@home /dev/nvme0n1p2 /mnt/home
```
4. **Mount Nix Store (`@nix`):**
```
mount -o compress=zstd,noatime,subvol=@nix /dev/nvme0n1p2 /mnt/nix
```
5. **Mount Boot:**
```
mount /dev/nvme0n1p1 /mnt/boot
```
### C. Deploy Configuration (Git Method)
1. **Clone Your Repo:**
```
mkdir -p /mnt/etc/nixos
# Replace USERNAME with your git.nimmog.uk user
nix-shell -p git --run "git clone https://git.nimmog.uk/USERNAME/nixos-config.git /mnt/etc/nixos/"
```
2. **Generate Hardware Scan:**
This creates `hardware-configuration.nix` in the folder.
```
```bash
nixos-generate-config --root /mnt
```
*(Ignore the warning about configuration.nix existing)*
3. **Move Hardware Config to Correct Host Folder:**
### D. Install & Set Password
**For Electra:**
```bash
mv /mnt/etc/nixos/hardware-configuration.nix /mnt/etc/nixos/hosts/electra/hardware-configuration.nix
```
**For Lena:**
```bash
mv /mnt/etc/nixos/hardware-configuration.nix /mnt/etc/nixos/hosts/lena/hardware-configuration.nix
```
### Step 3: Install & Set Password
1. **Run the Installer:**
```
**For Electra:**
```bash
nixos-install --flake /mnt/etc/nixos#electra
```
*If prompted to set a ROOT password, go ahead and set one.*
2. **Set USER Password (Critical):**
Do not reboot yet! We need to set the password for `nimmo`.
Enter the new system environment:
**For Lena:**
```bash
nixos-install --flake /mnt/etc/nixos#lena
```
2. **Set User Password:**
Do not reboot yet!
```bash
nixos-enter
```
Set the password:
```
passwd nimmo
```
Exit the environment:
```
exit
```
3. **Reboot:**
3. **Reboot:** `reboot`
```
reboot
---
## 4. Post-Installation & Management
After rebooting, move your config to your home folder for easier management.
1. **Move Config:**
```bash
mkdir -p ~/Scripts
sudo mv /etc/nixos ~/Scripts/nixos-config
sudo chown -R nimmo:users ~/Scripts/nixos-config
```
## 3. Bus ID Configuration (Done)
2. **Apply Changes:**
From now on, edit files in `~/Scripts/nixos-config`.
* **Edit:** `nano ~/Scripts/nixos-config/common/user-apps.nix` (or other files)
* **Rebuild (Electra):**
```bash
sudo nixos-rebuild switch --flake ~/Scripts/nixos-config/#electra
```
* **Rebuild (Lena):**
```bash
sudo nixos-rebuild switch --flake ~/Scripts/nixos-config/#lena
```
3. **Adding Apps:**
* **CLI Tools:** Edit `common/system-utils.nix`
* **GUI Apps:** Edit `common/user-apps.nix`
---
## 5. Electra Specifics
### Boot Modes
Electra has specialized boot modes selectable at startup:
1. **NixOS Default:** NVIDIA + Balanced Power (Use when GPU module is inserted).
2. **Gaming-Zen:** NVIDIA + Zen Kernel + Max Performance.
3. **Eco-Battery:** NVIDIA + TLP (Max Saver).
4. **No-dGPU:** **iGPU Only**. Use this when the GPU module is physically replaced with the Expansion Shell.
### Bus IDs
* **NVIDIA:** 193 (`c1:00.0`)
* **AMD:** 194 (`c2:00.0`)
## 4. Applying Changes (Post-Install)
---
**To apply updates or config changes:**
1. Edit your files in `/etc/nixos/` (or pull changes from git).
2. (Optional) Commit your changes: `git commit -am "Update config"`
3. Rebuild:
```
sudo nixos-rebuild switch --flake /etc/nixos/#electra
```
## 5. Boot Modes (Select at Boot)
You will see **four** options in your bootloader. Use arrow keys to select.
### 1. NixOS Default
* **Setup:** NVIDIA + Balanced Power (KDE).
* **Use when:** NVIDIA Module **INSERTED**.
### 2. Gaming-Zen
* **Setup:** NVIDIA + Zen Kernel + Max Performance.
* **Use when:** Gaming with NVIDIA Module **INSERTED**.
### 3. Eco-Battery
* **Setup:** NVIDIA + TLP (Max Saver).
* **Use when:** Traveling with NVIDIA Module **INSERTED**.
### 4. No-dGPU (Expansion Shell)
* **Setup:** **NO NVIDIA DRIVERS**. iGPU Only.
* **Use when:** You have physically **REMOVED** the GPU module and inserted the blank Expansion Shell.
* *Note: If you boot Default with the GPU removed, the system will likely fail to reach the desktop.*
## 6. Adding New Apps
* **CLI Tools:** Edit `system-utils.nix`.
* **GUI Apps:** Edit `user-apps.nix`.
* **After editing:** Run the rebuild command in step 4.
## 7. Docker
Docker is installed and running in Rootless mode. You can run docker commands immediately as user `nimmo`:
```
## 6. Docker
Docker is installed in Rootless mode.
```bash
docker run hello-world
```
## 8. Fingerprint Reader
1. Go to **System Settings -> Users** and click "Configure Fingerprint".
2. If that fails, run `fprintd-enroll` in a terminal.
3. **Usage:**
* **Login (SDDM):** Password only (required to unlock KWallet).
* **Unlock Screen:** Fingerprint or Password.
* **Sudo (Terminal):** Fingerprint or Password.
## 7. Fingerprint Reader
* **Login:** Password only (required for KWallet).
* **Sudo/Unlock:** Fingerprint enabled.

120
common/default.nix Normal file
View file

@ -0,0 +1,120 @@
{ config, pkgs, lib, ... }:
{
imports =
[
./system-utils.nix # CLI Tools
./user-apps.nix # GUI Apps
];
# ==========================================
# 1. CORE SYSTEM SETTINGS
# ==========================================
# Bootloader (Standard UEFI)
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
# Networking
networking.networkmanager.enable = true;
# Time & Locale
time.timeZone = "Europe/London";
i18n.defaultLocale = "en_US.UTF-8";
# ==========================================
# 2. USER ACCOUNT
# ==========================================
users.users.nimmo = {
isNormalUser = true;
description = "Nimmo";
extraGroups = [ "networkmanager" "wheel" "docker" ];
};
# ==========================================
# 3. COMMON SERVICES
# ==========================================
# Firmware & Updates
services.fwupd.enable = true;
# Power (Standard Profile)
services.power-profiles-daemon.enable = true;
# Filesystem Maintenance
services.fstrim.enable = true;
zramSwap.enable = true;
services.btrfs.autoScrub = {
enable = true;
interval = "weekly";
fileSystems = [ "/" ];
};
# Garbage Collection
nix.gc = {
automatic = true;
dates = "weekly";
options = "--delete-older-than 7d";
};
# Bluetooth
hardware.bluetooth.enable = true;
hardware.bluetooth.powerOnBoot = true;
# Audio (Pipewire)
security.rtkit.enable = true;
services.pipewire = {
enable = true;
alsa.enable = true;
alsa.support32Bit = true;
pulse.enable = true;
};
# Docker
virtualisation.docker.enable = true;
# Steam
programs.steam = {
enable = true;
remotePlay.openFirewall = true;
dedicatedServer.openFirewall = true;
};
# ==========================================
# 4. DESKTOP ENVIRONMENT (Plasma 6)
# ==========================================
services.xserver.enable = true;
services.displayManager.sddm.enable = true;
services.displayManager.sddm.wayland.enable = true;
services.desktopManager.plasma6.enable = true;
services.xserver.xkb.layout = "gb";
# ==========================================
# 5. NIX CORE SETTINGS
# ==========================================
nixpkgs.config.allowUnfree = true;
nix.settings.experimental-features = [ "nix-command" "flakes" ];
system.stateVersion = "24.11";
# ==========================================
# 6. POLISHING
# ==========================================
fonts.packages = with pkgs; [
noto-fonts
noto-fonts-cjk-sans
noto-fonts-emoji
nerd-fonts.jetbrains-mono
];
programs.nix-ld.enable = true;
programs.nix-ld.libraries = with pkgs; [
stdenv.cc.cc.lib
zlib
fuse3
icu
nss
openssl
curl
expat
];
environment.variables.EDITOR = "nano";
}

View file

@ -1,223 +0,0 @@
{ config, pkgs, lib, ... }:
{
imports =
[
./hardware-configuration.nix # Generated by the installer
./system-utils.nix # CLI Tools
./user-apps.nix # GUI Apps
];
# ==========================================
# 1. BOOT & KERNEL STRATEGY
# ==========================================
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
# --- KERNEL PARAMETERS (LLM/AI) ---
# Force AMD GTT to 32GB.
# Combined with 16GB BIOS VRAM, this gives ~48GB total addressable to iGPU.
boot.kernelParams = [ "amdgpu.gttsize=32768" ];
# Load AMDGPU drivers early to prevent blank boot screens on Strix Point
boot.initrd.kernelModules = [ "amdgpu" ];
# --- DEFAULT MODE (Balanced/Daily Use) ---
# boot.kernelPackages = pkgs.linuxPackages_latest; # Use default stable kernel for better Nvidia support
# --- SPECIALISATIONS (Selectable at Boot) ---
specialisation = {
# Option 1: Gaming Mode (Zen Kernel + Max Performance)
gaming-zen.configuration = {
system.nixos.tags = [ "Gaming-Zen" ];
boot.kernelPackages = lib.mkForce pkgs.linuxPackages_zen;
hardware.nvidia.powerManagement.finegrained = lib.mkForce false;
};
# Option 2: Eco/Battery Mode (TLP + No Turbo)
battery-saver.configuration = {
system.nixos.tags = [ "Eco-Battery" ];
services.power-profiles-daemon.enable = lib.mkForce false;
services.tlp = {
enable = lib.mkForce true;
settings = {
CPU_SCALING_GOVERNOR_ON_BAT = "powersave";
CPU_ENERGY_PERF_POLICY_ON_BAT = "power";
CPU_BOOST_ON_BAT = 0;
PLATFORM_PROFILE_ON_BAT = "low-power";
};
};
};
# Option 3: Expansion Shell (Physically Removed GPU)
no-dgpu.configuration = {
system.nixos.tags = [ "No-dGPU" ];
# 1. Force Video Driver to standard modesetting (ignores Nvidia)
services.xserver.videoDrivers = lib.mkForce [ "modesetting" ];
# 2. Blacklist Nvidia Kernel Modules to prevent loading attempts
boot.blacklistedKernelModules = [ "nvidia" "nvidia_modeset" "nvidia_uvm" "nvidia_drm" ];
# 3. Disable Nvidia Hardware Options
hardware.nvidia = {
modesetting.enable = lib.mkForce false;
powerManagement.enable = lib.mkForce false;
open = lib.mkForce false;
nvidiaSettings = lib.mkForce false;
prime.offload.enable = lib.mkForce false;
};
};
};
# ==========================================
# 2. NETWORKING & LOCALES
# ==========================================
networking.hostName = "electra";
networking.networkmanager.enable = true;
time.timeZone = "Europe/London";
i18n.defaultLocale = "en_US.UTF-8";
# ==========================================
# 3. USER ACCOUNT (nimmo)
# ==========================================
users.users.nimmo = {
isNormalUser = true;
description = "Nimmo";
# "docker" group allows running containers without sudo
extraGroups = [ "networkmanager" "wheel" "docker" ];
};
# ==========================================
# 4. HARDWARE & SERVICES
# ==========================================
# Framework 16 Fingerprint Reader
services.fprintd.enable = true;
# Connect Fingerprint to Auth Systems
security.pam.services.sudo.fprintAuth = true;
security.pam.services.kde.fprintAuth = true; # Lock Screen
security.pam.services.sddm.fprintAuth = false; # Disable for login (KWallet)
# Firmware & Updates
services.fwupd.enable = true;
hardware.enableAllFirmware = true;
hardware.cpu.amd.updateMicrocode = true;
# Power Management (Standard: KDE Integration)
services.power-profiles-daemon.enable = true;
# SSD & Filesystem Maintenance
services.fstrim.enable = true;
zramSwap.enable = true;
services.btrfs.autoScrub = {
enable = true;
interval = "weekly";
fileSystems = [ "/" ];
};
# Automatic Garbage Collection
nix.gc = {
automatic = true;
dates = "weekly";
options = "--delete-older-than 7d";
};
# Bluetooth
hardware.bluetooth.enable = true;
hardware.bluetooth.powerOnBoot = true;
# Audio (Pipewire)
security.rtkit.enable = true;
services.pipewire = {
enable = true;
alsa.enable = true;
alsa.support32Bit = true;
pulse.enable = true;
};
# Docker Support
virtualisation.docker.enable = true;
# Steam (Ports & 32-bit dependencies)
programs.steam = {
enable = true;
remotePlay.openFirewall = true;
dedicatedServer.openFirewall = true;
};
# ==========================================
# 5. DESKTOP (Plasma 6)
# ==========================================
services.xserver.enable = true;
services.displayManager.sddm.enable = true;
services.displayManager.sddm.wayland.enable = true;
services.desktopManager.plasma6.enable = true;
services.xserver.xkb.layout = "gb";
# ==========================================
# 6. GRAPHICS (RTX 5070 + Strix Point)
# ==========================================
hardware.graphics = {
enable = true;
enable32Bit = true;
};
services.xserver.videoDrivers = [ "nvidia" ];
hardware.nvidia = {
modesetting.enable = true;
# Power Management (Default: Finegrained/Battery Friendly)
# This puts the GPU to sleep when not in use.
# Note: Overridden to 'false' in Gaming Mode specialisation above.
powerManagement.enable = true;
powerManagement.finegrained = true;
open = true;
nvidiaSettings = true;
package = config.boot.kernelPackages.nvidiaPackages.beta;
prime = {
offload = {
enable = true;
enableOffloadCmd = true;
};
amdgpuBusId = "PCI:194:0:0"; # c2:00.0 -> 194
nvidiaBusId = "PCI:193:0:0"; # c1:00.0 -> 193
};
};
# ==========================================
# 7. NIX CORE SETTINGS
# ==========================================
nixpkgs.config.allowUnfree = true;
nix.settings.experimental-features = [ "nix-command" "flakes" ];
system.stateVersion = "24.11";
# ==========================================
# 8. POLISHING (Fonts & Compatibility)
# ==========================================
fonts.packages = with pkgs; [
noto-fonts
noto-fonts-cjk-sans
noto-fonts-emoji
nerd-fonts.jetbrains-mono
];
programs.nix-ld.enable = true;
programs.nix-ld.libraries = with pkgs; [
stdenv.cc.cc.lib
zlib
fuse3
icu
nss
openssl
curl
expat
];
environment.variables.EDITOR = "nano";
}

View file

@ -1,5 +1,5 @@
{
description = "Nimmo's NixOS Config (Electra)";
description = "Nimmo's NixOS Configurations";
inputs = {
# 1. Official NixOS Unstable (Required for Strix Point/RTX 5070 hardware support)
@ -12,17 +12,29 @@
outputs = { self, nixpkgs, ... }@inputs: {
nixosConfigurations = {
# This name "electra" must match networking.hostName in configuration.nix
# =======================
# 1. ELECTRA (Main Laptop)
# =======================
electra = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
# Pass inputs to modules so user-apps.nix can access Antigravity
specialArgs = { inherit inputs; };
modules = [
./configuration.nix
./hosts/electra/default.nix
];
};
# =======================
# 2. LENA (Secondary Laptop)
# =======================
lena = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
specialArgs = { inherit inputs; };
modules = [
./hosts/lena/default.nix
];
};
};
};
}

98
hosts/electra/default.nix Normal file
View file

@ -0,0 +1,98 @@
{ config, pkgs, lib, ... }:
{
imports =
[
../../common
./hardware-configuration.nix
];
networking.hostName = "electra";
# ==========================================
# 1. HARDWARE SPECIFICS (Framework 16)
# ==========================================
hardware.enableAllFirmware = true;
hardware.cpu.amd.updateMicrocode = true;
# Fingerprint Reader
services.fprintd.enable = true;
security.pam.services.sudo.fprintAuth = true;
security.pam.services.kde.fprintAuth = true;
security.pam.services.sddm.fprintAuth = false;
# ==========================================
# 2. GRAPHICS & KERNEL (Strix Point + RTX 5070)
# ==========================================
# Kernel Params for Strix Point iGPU
boot.kernelParams = [ "amdgpu.gttsize=32768" ];
boot.initrd.kernelModules = [ "amdgpu" ];
# Graphics Drivers
hardware.graphics = {
enable = true;
enable32Bit = true;
};
services.xserver.videoDrivers = [ "nvidia" ];
hardware.nvidia = {
modesetting.enable = true;
powerManagement.enable = true;
powerManagement.finegrained = true;
open = true;
nvidiaSettings = true;
package = config.boot.kernelPackages.nvidiaPackages.beta;
prime = {
offload = {
enable = true;
enableOffloadCmd = true;
};
amdgpuBusId = "PCI:194:0:0";
nvidiaBusId = "PCI:193:0:0";
};
};
# ==========================================
# 3. SPECIALISATIONS (Gaming / Eco / No-dGPU)
# ==========================================
specialisation = {
# Option 1: Gaming Mode (Zen Kernel + Max Performance)
gaming-zen.configuration = {
system.nixos.tags = [ "Gaming-Zen" ];
boot.kernelPackages = lib.mkForce pkgs.linuxPackages_zen;
hardware.nvidia.powerManagement.finegrained = lib.mkForce false;
};
# Option 2: Eco/Battery Mode (TLP + No Turbo)
battery-saver.configuration = {
system.nixos.tags = [ "Eco-Battery" ];
services.power-profiles-daemon.enable = lib.mkForce false;
services.tlp = {
enable = lib.mkForce true;
settings = {
CPU_SCALING_GOVERNOR_ON_BAT = "powersave";
CPU_ENERGY_PERF_POLICY_ON_BAT = "power";
CPU_BOOST_ON_BAT = 0;
PLATFORM_PROFILE_ON_BAT = "low-power";
};
};
};
# Option 3: Expansion Shell (Physically Removed GPU)
no-dgpu.configuration = {
system.nixos.tags = [ "No-dGPU" ];
services.xserver.videoDrivers = lib.mkForce [ "modesetting" ];
boot.blacklistedKernelModules = [ "nvidia" "nvidia_modeset" "nvidia_uvm" "nvidia_drm" ];
hardware.nvidia = {
modesetting.enable = lib.mkForce false;
powerManagement.enable = lib.mkForce false;
open = lib.mkForce false;
nvidiaSettings = lib.mkForce false;
prime.offload.enable = lib.mkForce false;
};
};
};
}

15
hosts/lena/default.nix Normal file
View file

@ -0,0 +1,15 @@
{ config, pkgs, lib, ... }:
{
imports =
[
../../common
./hardware-configuration.nix
];
networking.hostName = "lena";
# Basic hardware support (Microcode updates appropriate for Intel/AMD depending on what Lena is)
# Assuming Lena is standard, we enable firmware. Update if Lena is ancient.
hardware.enableAllFirmware = true;
}