From c3b40967d40d304bc46f4a06768afa0b271fd732 Mon Sep 17 00:00:00 2001 From: Felix Stupp Date: Tue, 26 Nov 2024 23:08:20 +0000 Subject: [PATCH] modules/graphics: add support for NVIDIA --- nix/nixos-modules/graphics.nix | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/nix/nixos-modules/graphics.nix b/nix/nixos-modules/graphics.nix index 59916df..e55c392 100644 --- a/nix/nixos-modules/graphics.nix +++ b/nix/nixos-modules/graphics.nix @@ -19,6 +19,11 @@ in intel.enable = lib.mkEnableOption "Intel graphic drivers"; + nvidia = { + enable = lib.mkEnableOption "Nvidia graphic drivers (meaning newest drivers by default)"; + open = lib.mkEnableOption "open-source kernel module in favor of (check [NixOS Wiki](https://wiki.nixos.org/wiki/Nvidia))"; + }; + }; }; @@ -28,7 +33,7 @@ in { assertions = [ { - assertion = cfg.required -> cfg.amd.enable || cfg.intel.enable; + assertion = cfg.required -> cfg.amd.enable || cfg.intel.enable || cfg.nvidia.enable; message = "'hardware.graphics.required' not fullfilled by any of 'hardware.graphics.*.enable'"; } ]; @@ -57,6 +62,30 @@ in }; }) + # source: https://wiki.nixos.org/wiki/Nvidia + (lib.mkIf cfg.nvidia.enable { + hardware = { + # TODO set priority per case + nvidia = lib.mkDefault { + modesetting.enable = true; + powerManagement.enable = false; + powerManagement.finegrained = false; + open = cfg.nvidia.open; + nvidiaSettings = true; + # TODO select driver based on GPU generation + }; + opengl = { + enable = true; + }; + }; + services.xserver.videoDrivers = lib.singleton "nvidia"; + x-banananetwork.autoUnfree.names = [ + "nvidia-persistenced" + "nvidia-settings" + "nvidia-x11" + ]; + }) + ]; }