let # Common Power Saving Config (TLP) powerSaving = { 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"; }; }; }; # Common No-dGPU Config (Expansion Shell) noDgpuBase = { systemd.services.dgpu-guard.enable = false; 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; }; }; in { 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. HARDWARE GUARD (dGPU Check) # ========================================== # This prevents a black-screen hang if you boot into an NVIDIA mode # but have the dGPU physically removed. systemd.services.dgpu-guard = { description = "Check for dGPU presence before starting display manager"; before = [ "display-manager.service" ]; wantedBy = [ "display-manager.service" ]; script = '' # Check if device 01:00.0 is NVIDIA (Vendor 10de) if ! ${pkgs.pciutils}/bin/lspci -d 10de: -s 01:00.0 | grep -q "NVIDIA"; then echo "ERROR: NVIDIA dGPU not found at expected Bus ID!" echo "You are likely in a dGPU-enabled boot mode but the module is removed." echo "Falling back to console to prevent black screen hang." exit 1 fi ''; serviceConfig = { Type = "oneshot"; RemainAfterExit = true; }; # Only run this check if the NVIDIA driver is actually requested unitConfig.ConditionPathExists = "/proc/modules"; # Basic sanity check }; # ========================================== # 4. SPECIALISATIONS # ========================================== specialisation = { # --- WITH dGPU MODES --- # 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; }; # 2. dGPU Battery Mode (NVIDIA + TLP) dgpu-battery.configuration = lib.recursiveUpdate powerSaving { system.nixos.tags = [ "dGPU-Battery" ]; }; # --- WITHOUT dGPU MODES --- # 3. No dGPU Mode (Expansion Shell + Balanced) no-dgpu.configuration = lib.recursiveUpdate noDgpuBase { system.nixos.tags = [ "No-dGPU" ]; }; # 4. No dGPU Battery Mode (Expansion Shell + TLP) no-dgpu-battery.configuration = lib.recursiveUpdate (lib.recursiveUpdate noDgpuBase powerSaving) { system.nixos.tags = [ "No-dGPU-Battery" ]; }; }; }