fix: complete hybridGPU wiring + make state-derived options overridable
Two related fixes that together close the "minimal wiring" gap behind
`nomarchy.system.features.hybridGPU`.
1. Complete the NVIDIA driver stack inside hardware.nix's hybridGPU
mkIf block.
Before: `hybridGPU = true` enabled supergfxd and... that was it.
supergfxd manages mode switching by black/unblacklisting the nvidia
kernel module, but without the rest of the NVIDIA stack actually
loaded the dGPU has no driver to drive. Hyprland/Wayland silently
stayed on the iGPU regardless of mode.
After: hybridGPU=true also wires
services.xserver.videoDrivers = ["nvidia"] (loads the driver
under Wayland too)
hardware.graphics.{enable,enable32Bit}
hardware.nvidia.modesetting.enable (required for
Wayland)
hardware.nvidia.powerManagement.enable
hardware.nvidia.package = config.boot.kernelPackages
.nvidiaPackages.stable
boot.kernelParams += "nvidia-drm.modeset=1"
All wired with lib.mkDefault so a downstream system.nix can pin a
beta driver, flip to the open kernel module, or set
`hardware.nvidia.prime.{offload.enable, intelBusId, nvidiaBusId}`
for render-offload. The bus IDs are per-machine (find via
`lspci -D`) so they stay user-supplied; docs/OPTIONS.md has the
full recipe.
2. Add lib.mkDefault to every state.json-derived assignment in
core/system/state.nix and core/home/state.nix.
Same priority bug on both sides: assignments like
`features.hybridGPU = systemState.features.hybridGPU or false`
landed at default priority. A downstream system.nix saying
`nomarchy.system.features.hybridGPU = true` would then conflict
with the state-derived value at the same priority, and Nix would
refuse the merge with "conflicting definition values" — the
user's override couldn't take effect.
Verified by an explicit eval: extending the default nixosConfig
with `nomarchy.system.features.hybridGPU = true` now resolves
cleanly and the full driver stack engages.
Side-effect: core/system/state.nix now reads from
lib/state-schema.nix like the home side does, completing the
schema-centralization started two batches ago.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -14,36 +14,40 @@ let
|
||||
togglesState = nomarchyLib.readHomeState config.home.homeDirectory;
|
||||
in
|
||||
{
|
||||
# Every assignment uses lib.mkDefault so a downstream /etc/nixos/home.nix
|
||||
# can override the state.json-derived value. Without mkDefault, every
|
||||
# option here would resolve at default priority and conflict on
|
||||
# assignment from the user's config.
|
||||
config = {
|
||||
nomarchy = {
|
||||
toggles = {
|
||||
suspend = togglesState.suspend or schema.home.suspend;
|
||||
screensaver = togglesState.screensaver or schema.home.screensaver;
|
||||
idle = togglesState.idle or schema.home.idle;
|
||||
nightlight = togglesState.nightlight or schema.home.nightlight;
|
||||
waybar = togglesState.waybar or schema.home.waybar;
|
||||
skipVsCodeTheme = togglesState.skipVsCodeTheme or schema.home.skipVsCodeTheme;
|
||||
suspend = lib.mkDefault (togglesState.suspend or schema.home.suspend);
|
||||
screensaver = lib.mkDefault (togglesState.screensaver or schema.home.screensaver);
|
||||
idle = lib.mkDefault (togglesState.idle or schema.home.idle);
|
||||
nightlight = lib.mkDefault (togglesState.nightlight or schema.home.nightlight);
|
||||
waybar = lib.mkDefault (togglesState.waybar or schema.home.waybar);
|
||||
skipVsCodeTheme = lib.mkDefault (togglesState.skipVsCodeTheme or schema.home.skipVsCodeTheme);
|
||||
};
|
||||
nightlightTemperature = togglesState.nightlightTemperature or schema.home.nightlightTemperature;
|
||||
theme = togglesState.theme or schema.home.theme;
|
||||
wallpaper = togglesState.wallpaper or schema.home.wallpaper;
|
||||
panelPosition = togglesState.panelPosition or schema.home.panelPosition;
|
||||
nightlightTemperature = lib.mkDefault (togglesState.nightlightTemperature or schema.home.nightlightTemperature);
|
||||
theme = lib.mkDefault (togglesState.theme or schema.home.theme);
|
||||
wallpaper = lib.mkDefault (togglesState.wallpaper or schema.home.wallpaper);
|
||||
panelPosition = lib.mkDefault (togglesState.panelPosition or schema.home.panelPosition);
|
||||
hyprland = {
|
||||
gaps_in = togglesState.hyprland.gaps_in or schema.home.hyprland.gaps_in;
|
||||
gaps_out = togglesState.hyprland.gaps_out or schema.home.hyprland.gaps_out;
|
||||
border_size = togglesState.hyprland.border_size or schema.home.hyprland.border_size;
|
||||
gaps_in = lib.mkDefault (togglesState.hyprland.gaps_in or schema.home.hyprland.gaps_in);
|
||||
gaps_out = lib.mkDefault (togglesState.hyprland.gaps_out or schema.home.hyprland.gaps_out);
|
||||
border_size = lib.mkDefault (togglesState.hyprland.border_size or schema.home.hyprland.border_size);
|
||||
};
|
||||
fonts.monospace = togglesState.font or schema.home.font;
|
||||
fonts.monospace = lib.mkDefault (togglesState.font or schema.home.font);
|
||||
|
||||
# Derived properties from the theme directory
|
||||
isLightMode = nomarchyLib.isThemeLightMode {
|
||||
isLightMode = lib.mkDefault (nomarchyLib.isThemeLightMode {
|
||||
themeName = togglesState.theme or schema.home.theme;
|
||||
inherit assetsPath;
|
||||
};
|
||||
iconsTheme = nomarchyLib.getIconsTheme {
|
||||
});
|
||||
iconsTheme = lib.mkDefault (nomarchyLib.getIconsTheme {
|
||||
themeName = togglesState.theme or schema.home.theme;
|
||||
inherit assetsPath;
|
||||
};
|
||||
});
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -70,8 +70,47 @@ in
|
||||
})
|
||||
|
||||
(mkIf config.nomarchy.system.features.hybridGPU {
|
||||
# supergfxd manages mode switching (Integrated / Hybrid / Vfio /
|
||||
# AsusEgpu). It blacklists/unblacklists the nvidia kernel module via
|
||||
# /etc/modprobe.d/ depending on the active mode. ExecStartPre sleep
|
||||
# gives udev time to settle so the daemon doesn't see a half-attached
|
||||
# GPU on cold boot.
|
||||
services.supergfxd.enable = true;
|
||||
systemd.services.supergfxd.serviceConfig.ExecStartPre = "-${pkgs.coreutils}/bin/sleep 5";
|
||||
|
||||
# Load the NVIDIA driver so the dGPU has something to drive. Without
|
||||
# these, supergfxd switches modes successfully but the X/Wayland
|
||||
# stack has no NVIDIA driver loaded — render-offload silently no-ops
|
||||
# and Hyprland renders everything on the iGPU regardless of mode.
|
||||
# mkDefault throughout so downstream system.nix can override
|
||||
# (pin to a beta driver, flip to the open kernel module, etc.).
|
||||
services.xserver.videoDrivers = lib.mkDefault [ "nvidia" ];
|
||||
hardware.graphics.enable = lib.mkDefault true;
|
||||
hardware.graphics.enable32Bit = lib.mkDefault true;
|
||||
hardware.nvidia = {
|
||||
modesetting.enable = lib.mkDefault true;
|
||||
powerManagement.enable = lib.mkDefault true;
|
||||
open = lib.mkDefault false;
|
||||
package = lib.mkDefault config.boot.kernelPackages.nvidiaPackages.stable;
|
||||
};
|
||||
# Required for Wayland compositors (Hyprland) to render via NVIDIA.
|
||||
boot.kernelParams = [ "nvidia-drm.modeset=1" ];
|
||||
|
||||
# PRIME render-offload (the part that lets `nvidia-offload <cmd>`
|
||||
# actually use the dGPU) needs bus IDs, which are per-machine.
|
||||
# We deliberately don't enable `hardware.nvidia.prime.offload.enable`
|
||||
# here — without the correct intelBusId / nvidiaBusId the nvidia
|
||||
# kernel module panics on load. The user adds this to their own
|
||||
# /etc/nixos/system.nix after running `lspci -D`:
|
||||
#
|
||||
# hardware.nvidia.prime = {
|
||||
# offload.enable = true;
|
||||
# offload.enableOffloadCmd = true;
|
||||
# intelBusId = "PCI:0:2:0"; # or amdgpuBusId for AMD iGPU
|
||||
# nvidiaBusId = "PCI:1:0:0";
|
||||
# };
|
||||
#
|
||||
# See docs/OPTIONS.md for the full recipe.
|
||||
})
|
||||
];
|
||||
}
|
||||
|
||||
@@ -2,19 +2,28 @@
|
||||
|
||||
let
|
||||
nomarchyLib = import ../../lib { inherit lib; };
|
||||
# Same canonical schema as core/home/state.nix and the options.nix
|
||||
# files — keeps every state default in one place.
|
||||
schema = import ../../lib/state-schema.nix { inherit lib; };
|
||||
systemState = nomarchyLib.readSystemState;
|
||||
in
|
||||
{
|
||||
# Every assignment is lib.mkDefault so a downstream /etc/nixos/system.nix
|
||||
# can still set e.g. `nomarchy.system.features.hybridGPU = true;`
|
||||
# without colliding with the state.json-derived value. Without
|
||||
# mkDefault, every state.json-driven option was unoverridable from
|
||||
# Nix — flipping hybridGPU required jq'ing the state file rather
|
||||
# than declaring it in your config.
|
||||
config.nomarchy.system = {
|
||||
dns = systemState.dns or "DHCP";
|
||||
customDns = systemState.customDns or [];
|
||||
wifi.powersave = systemState.wifi.powersave or true;
|
||||
timezone = systemState.timezone or "UTC";
|
||||
dns = lib.mkDefault (systemState.dns or schema.system.dns);
|
||||
customDns = lib.mkDefault (systemState.customDns or schema.system.customDns);
|
||||
wifi.powersave = lib.mkDefault (systemState.wifi.powersave or schema.system.wifi.powersave);
|
||||
timezone = lib.mkDefault (systemState.timezone or schema.system.timezone);
|
||||
features = {
|
||||
fingerprint = systemState.features.fingerprint or false;
|
||||
fido2 = systemState.features.fido2 or false;
|
||||
hybridGPU = systemState.features.hybridGPU or false;
|
||||
fingerprint = lib.mkDefault (systemState.features.fingerprint or schema.system.features.fingerprint);
|
||||
fido2 = lib.mkDefault (systemState.features.fido2 or schema.system.features.fido2);
|
||||
hybridGPU = lib.mkDefault (systemState.features.hybridGPU or schema.system.features.hybridGPU);
|
||||
};
|
||||
theme = systemState.theme or "nord";
|
||||
theme = lib.mkDefault (systemState.theme or schema.system.theme);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user