From e32635bba4749ce5f46026a9661bbe3dd871496a Mon Sep 17 00:00:00 2001 From: Benedikt Ritter Date: Sun, 27 Oct 2024 12:05:04 +0100 Subject: [PATCH 1/3] graphics: Introduce amd module Introduces an AMD graphics specific module. For now this module only adds amdgpu video drivers to xserver. --- modules/nixos/facter.nix | 2 +- modules/nixos/graphics/amd.nix | 14 ++++++++++++++ .../nixos/{graphics.nix => graphics/default.nix} | 5 ++++- 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 modules/nixos/graphics/amd.nix rename modules/nixos/{graphics.nix => graphics/default.nix} (93%) diff --git a/modules/nixos/facter.nix b/modules/nixos/facter.nix index 6cd6128..7f29666 100644 --- a/modules/nixos/facter.nix +++ b/modules/nixos/facter.nix @@ -9,7 +9,7 @@ ./disk.nix ./keyboard.nix ./firmware.nix - ./graphics.nix + ./graphics ./networking ./system.nix ./virtualisation.nix diff --git a/modules/nixos/graphics/amd.nix b/modules/nixos/graphics/amd.nix new file mode 100644 index 0000000..79675cd --- /dev/null +++ b/modules/nixos/graphics/amd.nix @@ -0,0 +1,14 @@ +{lib, config,...}: +let + cfg = config.facter.detected.graphics.amd; +in +{ + options.facter.detected.graphics = { + amd.enable = lib.mkEnableOption "Enable the AMD Graphics module" // { + default = builtins.elem "amdgpu" (builtins.map (graphics_card: graphics_card.driver) config.facter.report.hardware.graphics_card); + }; + }; + config = lib.mkIf cfg.enable { + services.xserver.videoDrivers = ["amdgpu"]; + }; +} diff --git a/modules/nixos/graphics.nix b/modules/nixos/graphics/default.nix similarity index 93% rename from modules/nixos/graphics.nix rename to modules/nixos/graphics/default.nix index 8acc8b6..b164b70 100644 --- a/modules/nixos/graphics.nix +++ b/modules/nixos/graphics/default.nix @@ -1,9 +1,12 @@ { lib, config, ... }: let - facterLib = import ../../lib/lib.nix lib; + facterLib = import ../../../lib/lib.nix lib; cfg = config.facter.detected.graphics; in { + imports = [ + ./amd.nix + ]; options.facter.detected = { graphics.enable = lib.mkEnableOption "Enable the Graphics module" // { default = builtins.length (config.facter.report.hardware.monitor or [ ]) > 0; From d2f40f8e13290a8bb4a116e94a46f2b8857486b3 Mon Sep 17 00:00:00 2001 From: Benedikt Ritter Date: Sun, 27 Oct 2024 12:23:49 +0100 Subject: [PATCH 2/3] graphics (amd): Make accessing graphics card drivers more resilient For empty facter reports it's possible that neighter hardware nor graphics_card is set. --- modules/nixos/graphics/amd.nix | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/nixos/graphics/amd.nix b/modules/nixos/graphics/amd.nix index 79675cd..027f067 100644 --- a/modules/nixos/graphics/amd.nix +++ b/modules/nixos/graphics/amd.nix @@ -1,14 +1,20 @@ -{lib, config,...}: +{ lib, config, ... }: let cfg = config.facter.detected.graphics.amd; in { options.facter.detected.graphics = { amd.enable = lib.mkEnableOption "Enable the AMD Graphics module" // { - default = builtins.elem "amdgpu" (builtins.map (graphics_card: graphics_card.driver) config.facter.report.hardware.graphics_card); + default = + let + graphicsDrivers = builtins.map (graphics_card: graphics_card.driver) ( + config.facter.report.hardware.graphics_card or [ ] + ); + in + builtins.elem "amdgpu" graphicsDrivers; }; }; config = lib.mkIf cfg.enable { - services.xserver.videoDrivers = ["amdgpu"]; + services.xserver.videoDrivers = [ "amdgpu" ]; }; } From a1d95f4fbb52236f9a4f7f56514e648a11800f97 Mon Sep 17 00:00:00 2001 From: Benedikt Ritter Date: Sun, 27 Oct 2024 12:35:10 +0100 Subject: [PATCH 3/3] graphics (amd): Use facter lib to access drivers --- modules/nixos/graphics/amd.nix | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/modules/nixos/graphics/amd.nix b/modules/nixos/graphics/amd.nix index 027f067..81dba29 100644 --- a/modules/nixos/graphics/amd.nix +++ b/modules/nixos/graphics/amd.nix @@ -1,17 +1,14 @@ { lib, config, ... }: let + facterLib = import ../../../lib/lib.nix lib; cfg = config.facter.detected.graphics.amd; in { options.facter.detected.graphics = { amd.enable = lib.mkEnableOption "Enable the AMD Graphics module" // { - default = - let - graphicsDrivers = builtins.map (graphics_card: graphics_card.driver) ( - config.facter.report.hardware.graphics_card or [ ] - ); - in - builtins.elem "amdgpu" graphicsDrivers; + default = builtins.elem "amdgpu" ( + facterLib.collectDrivers (config.facter.report.hardware.graphics_card or [ ]) + ); }; }; config = lib.mkIf cfg.enable {