From a3905e5b3d7ba7a3a32c159264ab90fdc5a6d4c3 Mon Sep 17 00:00:00 2001 From: hektor Date: Fri, 9 Oct 2026 21:47:29 +0200 Subject: [PATCH] feat(graphics): generalize to graphics module --- hosts/andromache/default.nix | 8 +- hosts/andromache/facter.json | 114 ++++-------------- hosts/astyanax/default.nix | 25 ++-- modules/graphics/default.nix | 56 +++++++++ modules/graphics/intel-arc-140t.nix | 27 +++++ modules/graphics/intel-uhd-770.nix | 25 ++++ .../default.nix => graphics/nvidia.nix} | 6 +- 7 files changed, 148 insertions(+), 113 deletions(-) create mode 100644 modules/graphics/default.nix create mode 100644 modules/graphics/intel-arc-140t.nix create mode 100644 modules/graphics/intel-uhd-770.nix rename modules/{nvidia/default.nix => graphics/nvidia.nix} (75%) diff --git a/hosts/andromache/default.nix b/hosts/andromache/default.nix index 8026a6a..b38dde5 100644 --- a/hosts/andromache/default.nix +++ b/hosts/andromache/default.nix @@ -35,6 +35,13 @@ in desktop.niri.enable = true; gaming.enable = true; git.enable = true; + graphics = { + enable = true; + intel = { + enable = true; + model = "uhd-770"; + }; + }; keyboard.enable = true; localization.enable = true; my = { @@ -54,7 +61,6 @@ in hostId = "80eef97e"; useDHCP = lib.mkDefault true; }; - nvidia.enable = true; restic-backup = { enable = true; paths = [ diff --git a/hosts/andromache/facter.json b/hosts/andromache/facter.json index 9e0efdd..1f6080c 100644 --- a/hosts/andromache/facter.json +++ b/hosts/andromache/facter.json @@ -1404,8 +1404,8 @@ ], "graphics_card": [ { - "index": 45, - "attached_to": 41, + "index": 27, + "attached_to": 0, "class_list": [ "graphics_card", "pci" @@ -1416,8 +1416,8 @@ "value": 4 }, "slot": { - "bus": 1, - "number": 0 + "bus": 0, + "number": 2 }, "base_class": { "hex": "0003", @@ -1435,34 +1435,34 @@ "value": 0 }, "vendor": { - "hex": "10de", - "name": "nVidia Corporation", - "value": 4318 + "hex": "8086", + "name": "Intel Corporation", + "value": 32902 }, "sub_vendor": { "hex": "1043", "value": 4163 }, "device": { - "hex": "2204", - "value": 8708 + "hex": "a780", + "value": 42880 }, "sub_device": { - "hex": "87b3", - "value": 34739 + "hex": "8882", + "value": 34946 }, "revision": { - "hex": "00a1", - "value": 161 + "hex": "0004", + "value": 4 }, - "model": "nVidia VGA compatible controller", - "sysfs_id": "/devices/pci0000:00/0000:00:01.0/0000:01:00.0", - "sysfs_bus_id": "0000:01:00.0", + "model": "Intel VGA compatible controller", + "sysfs_id": "/devices/pci0000:00/0000:00:02.0", + "sysfs_bus_id": "0000:00:02.0", "resources": [ { "type": "io", "base": 28672, - "range": 128, + "range": 64, "enabled": true, "access": "read_write" } @@ -1474,15 +1474,15 @@ "secondary_bus": 0, "prog_if": 0 }, - "driver": "nvidia", - "driver_module": "nvidia", + "driver": "i915", + "driver_module": "i915", "drivers": [ - "nvidia" + "i915" ], "driver_modules": [ - "nvidia" + "i915" ], - "module_alias": "pci:v000010DEd00002204sv00001043sd000087B3bc03sc00i00" + "module_alias": "pci:v00008086d0000A780sv00001043sd00008882bc03sc00i00" } ], "hub": [ @@ -2152,7 +2152,7 @@ "monitor": [ { "index": 64, - "attached_to": 45, + "attached_to": 27, "class_list": [ "monitor" ], @@ -3437,72 +3437,6 @@ ], "module_alias": "pci:v00008086d00007A50sv00001043sd000087FBbc04sc03i00", "label": "Intel HD Audio" - }, - { - "index": 58, - "attached_to": 41, - "class_list": [ - "sound", - "pci" - ], - "bus_type": { - "hex": "0004", - "name": "PCI", - "value": 4 - }, - "slot": { - "bus": 1, - "number": 0 - }, - "base_class": { - "hex": "0004", - "name": "Multimedia controller", - "value": 4 - }, - "sub_class": { - "hex": "0003", - "value": 3 - }, - "vendor": { - "hex": "10de", - "name": "nVidia Corporation", - "value": 4318 - }, - "sub_vendor": { - "hex": "1043", - "value": 4163 - }, - "device": { - "hex": "1aef", - "value": 6895 - }, - "sub_device": { - "hex": "87b3", - "value": 34739 - }, - "revision": { - "hex": "00a1", - "value": 161 - }, - "model": "nVidia Multimedia controller", - "sysfs_id": "/devices/pci0000:00/0000:00:01.0/0000:01:00.1", - "sysfs_bus_id": "0000:01:00.1", - "detail": { - "function": 1, - "command": 6, - "header_type": 0, - "secondary_bus": 0, - "prog_if": 0 - }, - "driver": "snd_hda_intel", - "driver_module": "snd_hda_intel", - "drivers": [ - "snd_hda_intel" - ], - "driver_modules": [ - "snd_hda_intel" - ], - "module_alias": "pci:v000010DEd00001AEFsv00001043sd000087B3bc04sc03i00" } ], "storage_controller": [ @@ -6218,4 +6152,4 @@ } } } -} \ No newline at end of file +} diff --git a/hosts/astyanax/default.nix b/hosts/astyanax/default.nix index b3a2579..76d8858 100644 --- a/hosts/astyanax/default.nix +++ b/hosts/astyanax/default.nix @@ -33,6 +33,13 @@ in bootloader.enable = true; desktop.niri.enable = true; git.enable = true; + graphics = { + enable = true; + intel = { + enable = true; + model = "arc-140t"; + }; + }; keyboard.enable = true; localization.enable = true; my = { @@ -67,23 +74,7 @@ in docker.enable = true; nfc.enable = true; - hardware = { - cpu.intel.updateMicrocode = true; - # https://wiki.nixos.org/wiki/Intel_Graphics - graphics = { - enable = true; - extraPackages = with pkgs; [ - intel-media-driver - vpl-gpu-rt - intel-compute-runtime - ]; - }; - }; - - # https://wiki.nixos.org/wiki/Intel_Graphics - environment.sessionVariables = { - LIBVA_DRIVER_NAME = "iHD"; - }; + hardware.cpu.intel.updateMicrocode = true; environment.systemPackages = [ (pkgs.writeShellApplication { diff --git a/modules/graphics/default.nix b/modules/graphics/default.nix new file mode 100644 index 0000000..94e77d6 --- /dev/null +++ b/modules/graphics/default.nix @@ -0,0 +1,56 @@ +{ lib, config, ... }: + +let + cfg = config.graphics; + cardCount = lib.count lib.id [ + cfg.intel.enable + cfg.nvidia.enable + ]; +in +{ + imports = [ + ./intel-arc-140t.nix + ./intel-uhd-770.nix + ./nvidia.nix + ]; + + options.graphics = { + enable = lib.mkEnableOption "graphics"; + intel = { + enable = lib.mkEnableOption "Intel graphics"; + model = lib.mkOption { + type = lib.types.nullOr ( + lib.types.enum [ + "arc-140t" + "uhd-770" + ] + ); + default = null; + }; + }; + nvidia.enable = lib.mkEnableOption "NVIDIA graphics"; + }; + + config = { + assertions = [ + { + assertion = !(cfg.enable && cardCount != 1); + message = "'graphics.enable' requires one and only one graphics card"; + } + { + assertion = !(cardCount > 0 && !cfg.enable); + message = "'graphics.*.enable' require 'graphics.enable'"; + } + { + assertion = !(cfg.intel.enable && cfg.intel.model == null); + message = "'graphics.intel.enable' requires 'graphics.intel.model'"; + } + { + assertion = !(cfg.intel.model != null && !cfg.intel.enable); + message = "'graphics.intel.model' requires 'graphics.intel.enable'"; + } + ]; + + hardware.graphics.enable = lib.mkIf cfg.enable true; + }; +} diff --git a/modules/graphics/intel-arc-140t.nix b/modules/graphics/intel-arc-140t.nix new file mode 100644 index 0000000..f35116a --- /dev/null +++ b/modules/graphics/intel-arc-140t.nix @@ -0,0 +1,27 @@ +{ + lib, + config, + pkgs, + ... +}: + +{ + config = + lib.mkIf + ( + config.graphics.enable && config.graphics.intel.enable && config.graphics.intel.model == "arc-140t" + ) + { + boot.initrd.kernelModules = [ "i915" ]; + hardware.graphics = { + enable32Bit = true; + extraPackages = with pkgs; [ + intel-compute-runtime + intel-media-driver + vpl-gpu-rt + ]; + extraPackages32 = with pkgs; [ driversi686Linux.intel-media-driver ]; + }; + environment.sessionVariables.LIBVA_DRIVER_NAME = "iHD"; + }; +} diff --git a/modules/graphics/intel-uhd-770.nix b/modules/graphics/intel-uhd-770.nix new file mode 100644 index 0000000..7812a02 --- /dev/null +++ b/modules/graphics/intel-uhd-770.nix @@ -0,0 +1,25 @@ +{ + lib, + config, + pkgs, + ... +}: + +{ + config = + lib.mkIf + (config.graphics.enable && config.graphics.intel.enable && config.graphics.intel.model == "uhd-770") + { + boot.initrd.kernelModules = [ "i915" ]; + hardware.graphics = { + enable32Bit = true; + extraPackages = with pkgs; [ + intel-compute-runtime + intel-media-driver + vpl-gpu-rt + ]; + extraPackages32 = with pkgs; [ driversi686Linux.intel-media-driver ]; + }; + environment.sessionVariables.LIBVA_DRIVER_NAME = "iHD"; + }; +} diff --git a/modules/nvidia/default.nix b/modules/graphics/nvidia.nix similarity index 75% rename from modules/nvidia/default.nix rename to modules/graphics/nvidia.nix index 381f649..527f782 100644 --- a/modules/nvidia/default.nix +++ b/modules/graphics/nvidia.nix @@ -1,17 +1,13 @@ { lib, config, ... }: { - options.nvidia.enable = lib.mkEnableOption "NVIDIA graphics"; - - config = lib.mkIf config.nvidia.enable { + config = lib.mkIf (config.graphics.enable && config.graphics.nvidia.enable) { nixpkgs.allowedUnfree = [ "nvidia-x11" "nvidia-persistenced" "nvidia-settings" ]; - hardware.graphics.enable = true; - hardware.nvidia = { modesetting.enable = true; powerManagement.enable = true;