From 827665f2374b8ab850661fa2ea3bfe2ce3f3688e Mon Sep 17 00:00:00 2001 From: r-vdp Date: Wed, 25 Sep 2024 10:50:38 +0200 Subject: [PATCH] Add the graphics card driver modules to the initrd --- lib/lib.nix | 4 +++- modules/nixos/boot.nix | 7 +++---- modules/nixos/graphics.nix | 12 ++++++++++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/lib.nix b/lib/lib.nix index 957d053..b4224c5 100644 --- a/lib/lib.nix +++ b/lib/lib.nix @@ -23,9 +23,11 @@ let vendor_name == name ) cpus; + collectDrivers = list: lib.foldl' (lst: value: lst ++ value.driver_modules or [ ]) [ ] list; + stringSet = list: builtins.attrNames (builtins.groupBy lib.id list); in { - inherit hasCpu; + inherit hasCpu collectDrivers stringSet; hasAmdCpu = hasCpu "AuthenticAMD"; hasIntelCpu = hasCpu "GenuineIntel"; } diff --git a/modules/nixos/boot.nix b/modules/nixos/boot.nix index 17adc2a..199492c 100644 --- a/modules/nixos/boot.nix +++ b/modules/nixos/boot.nix @@ -1,10 +1,9 @@ { lib, config, ... }: let + facterLib = import ../../lib/lib.nix lib; cfg = config.facter.boot; inherit (config.facter) report; - collectDriver = list: lib.foldl' (lst: value: lst ++ value.driver_modules or [ ]) [ ] list; - stringSet = list: builtins.attrNames (builtins.groupBy lib.id list); in { options.facter.boot.enable = lib.mkEnableOption "Enable the Facter Boot module" // { @@ -14,8 +13,8 @@ in config = with lib; mkIf cfg.enable { - boot.initrd.availableKernelModules = stringSet ( - collectDriver ( + boot.initrd.availableKernelModules = facterLib.stringSet ( + facterLib.collectDrivers ( # Needed if we want to use the keyboard when things go wrong in the initrd. (report.hardware.usb_controller or [ ]) # A disk might be attached. diff --git a/modules/nixos/graphics.nix b/modules/nixos/graphics.nix index 4fd3be3..64d1dc8 100644 --- a/modules/nixos/graphics.nix +++ b/modules/nixos/graphics.nix @@ -1,8 +1,16 @@ { lib, config, ... }: +let + facterLib = import ../../lib/lib.nix lib; +in { options.facter.graphics.enable = lib.mkEnableOption "Enable the Graphics module" // { - default = builtins.length (config.facter.report.hardware.monitor or []) > 0; + default = builtins.length (config.facter.report.hardware.monitor or [ ]) > 0; }; - config.hardware.graphics.enable = lib.mkIf config.facter.graphics.enable (lib.mkDefault true); + config = lib.mkIf config.facter.graphics.enable { + hardware.graphics.enable = lib.mkDefault true; + boot.initrd.kernelModules = facterLib.stringSet ( + facterLib.collectDrivers (config.facter.report.hardware.graphics_card or [ ]) + ); + }; }