diff --git a/nixos/doc/manual/configuration/x-windows.chapter.md b/nixos/doc/manual/configuration/x-windows.chapter.md index 2c80b786b267f..e9a06b240f303 100644 --- a/nixos/doc/manual/configuration/x-windows.chapter.md +++ b/nixos/doc/manual/configuration/x-windows.chapter.md @@ -12,7 +12,7 @@ driver from a set of X.org drivers (such as `vesa` and `intel`). You can also specify a driver manually, e.g. ```nix -services.xserver.videoDrivers = [ "r128" ]; +hardware.graphics.videoDrivers = [ "r128" ]; ``` to enable X.org's `xf86-video-r128` driver. @@ -115,11 +115,11 @@ officially updated since 2015. The results vary depending on the hardware, so you may have to try both drivers. Use the option -[](#opt-services.xserver.videoDrivers) +[](#opt-hardware.graphics.videoDrivers) to set one. The recommended configuration for modern systems is: ```nix -services.xserver.videoDrivers = [ "modesetting" ]; +hardware.graphics.videoDrivers = [ "modesetting" ]; services.xserver.useGlamor = true; ``` @@ -127,7 +127,7 @@ If you experience screen tearing no matter what, this configuration was reported to resolve the issue: ```nix -services.xserver.videoDrivers = [ "intel" ]; +hardware.graphics.videoDrivers = [ "intel" ]; services.xserver.deviceSection = '' Option "DRI" "2" Option "TearFree" "true" @@ -144,16 +144,16 @@ better 3D performance than the X.org drivers. It is not enabled by default because it's not free software. You can enable it as follows: ```nix -services.xserver.videoDrivers = [ "nvidia" ]; +hardware.graphics.videoDrivers = [ "nvidia" ]; ``` Or if you have an older card, you may have to use one of the legacy drivers: ```nix -services.xserver.videoDrivers = [ "nvidiaLegacy390" ]; -services.xserver.videoDrivers = [ "nvidiaLegacy340" ]; -services.xserver.videoDrivers = [ "nvidiaLegacy304" ]; +hardware.graphics.videoDrivers = [ "nvidiaLegacy390" ]; +hardware.graphics.videoDrivers = [ "nvidiaLegacy340" ]; +hardware.graphics.videoDrivers = [ "nvidiaLegacy304" ]; ``` You may need to reboot after enabling this driver to prevent a clash @@ -168,7 +168,7 @@ performance. If you still want to use it anyway, you need to explicitly set: ```nix -services.xserver.videoDrivers = [ "amdgpu-pro" ]; +hardware.graphics.videoDrivers = [ "amdgpu-pro" ]; ``` You will need to reboot after enabling this driver to prevent a clash diff --git a/nixos/doc/manual/from_md/configuration/x-windows.chapter.xml b/nixos/doc/manual/from_md/configuration/x-windows.chapter.xml index 274d0d817bc16..4d8fa3e7d2e5b 100644 --- a/nixos/doc/manual/from_md/configuration/x-windows.chapter.xml +++ b/nixos/doc/manual/from_md/configuration/x-windows.chapter.xml @@ -14,7 +14,7 @@ services.xserver.enable = true; manually, e.g. -services.xserver.videoDrivers = [ "r128" ]; +hardware.graphics.videoDrivers = [ "r128" ]; to enable X.org’s xf86-video-r128 driver. @@ -128,11 +128,11 @@ services.xserver.displayManager.autoLogin.user = "alice"; The results vary depending on the hardware, so you may have to try both drivers. Use the option - to set one. + to set one. The recommended configuration for modern systems is: -services.xserver.videoDrivers = [ "modesetting" ]; +hardware.graphics.videoDrivers = [ "modesetting" ]; services.xserver.useGlamor = true; @@ -140,7 +140,7 @@ services.xserver.useGlamor = true; configuration was reported to resolve the issue: -services.xserver.videoDrivers = [ "intel" ]; +hardware.graphics.videoDrivers = [ "intel" ]; services.xserver.deviceSection = '' Option "DRI" "2" Option "TearFree" "true" @@ -161,16 +161,16 @@ services.xserver.deviceSection = '' it as follows: -services.xserver.videoDrivers = [ "nvidia" ]; +hardware.graphics.videoDrivers = [ "nvidia" ]; Or if you have an older card, you may have to use one of the legacy drivers: -services.xserver.videoDrivers = [ "nvidiaLegacy390" ]; -services.xserver.videoDrivers = [ "nvidiaLegacy340" ]; -services.xserver.videoDrivers = [ "nvidiaLegacy304" ]; +hardware.graphics.videoDrivers = [ "nvidiaLegacy390" ]; +hardware.graphics.videoDrivers = [ "nvidiaLegacy340" ]; +hardware.graphics.videoDrivers = [ "nvidiaLegacy304" ]; You may need to reboot after enabling this driver to prevent a @@ -187,7 +187,7 @@ services.xserver.videoDrivers = [ "nvidiaLegacy304" ]; need to explicitly set: -services.xserver.videoDrivers = [ "amdgpu-pro" ]; +hardware.graphics.videoDrivers = [ "amdgpu-pro" ]; You will need to reboot after enabling this driver to prevent a diff --git a/nixos/modules/hardware/graphics.nix b/nixos/modules/hardware/graphics.nix new file mode 100644 index 0000000000000..192557d6a2558 --- /dev/null +++ b/nixos/modules/hardware/graphics.nix @@ -0,0 +1,77 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + # Abbreviations. + cfg = config.hardware.graphics; + xorg = pkgs.xorg; + + +in + +{ + + imports = [ + (mkRenamedOptionModule [ "services" "xserver" "videoDrivers" ] [ "hardware" "graphics" "videoDrivers" ]) + ]; + + + + ###### interface + + options = { + + hardware.graphics = { + + enable = mkOption { + type = types.bool; + default = config.services.xserver.enable; + description = '' + Whether to enable GPU support, whether for graphics like X or Wayland, or other purposes. + ''; + }; + + videoDrivers = mkOption { + type = types.listOf types.str; + default = [ "amdgpu" "radeon" "nouveau" "modesetting" "fbdev" ]; + example = [ + "nvidia" "nvidiaLegacy390" "nvidiaLegacy340" "nvidiaLegacy304" + "amdgpu-pro" + ]; + # TODO(@oxij): think how to easily add the rest, like those nvidia things + relatedPackages = concatLists + (mapAttrsToList (n: v: + optional (hasPrefix "xf86video" n) { + path = [ "xorg" n ]; + title = removePrefix "xf86video" n; + }) pkgs.xorg); + description = '' + The names of the video drivers the configuration + supports. They will be tried in order until one that + supports your card is found. + Don't combine those with "incompatible" OpenGL implementations, + e.g. free ones (mesa-based) with proprietary ones. + + For unfree "nvidia*", the supported GPU lists are on + https://www.nvidia.com/object/unix.html + ''; + }; + + }; + + }; + + + + ###### implementation + + config = mkIf cfg.enable { + + + }; + + # uses relatedPackages + meta.buildDocsInSandbox = false; +} diff --git a/nixos/modules/hardware/opengl.nix b/nixos/modules/hardware/opengl.nix index 0d8aaf734591d..d0a949271c4cb 100644 --- a/nixos/modules/hardware/opengl.nix +++ b/nixos/modules/hardware/opengl.nix @@ -8,7 +8,7 @@ let kernelPackages = config.boot.kernelPackages; - videoDrivers = config.services.xserver.videoDrivers; + videoDrivers = config.hardware.graphics.videoDrivers; package = pkgs.buildEnv { name = "opengl-drivers"; @@ -41,7 +41,7 @@ in like sway and Weston. It is enabled by default by the corresponding modules, so you do not usually have to set it yourself, only if there is no module for your wayland - compositor of choice. See services.xserver.enable and + compositor of choice. See hardware.graphics.enable and programs.sway.enable. ''; type = types.bool; diff --git a/nixos/modules/hardware/video/amdgpu-pro.nix b/nixos/modules/hardware/video/amdgpu-pro.nix index d784befc9b887..da03a4c48a3a0 100644 --- a/nixos/modules/hardware/video/amdgpu-pro.nix +++ b/nixos/modules/hardware/video/amdgpu-pro.nix @@ -6,7 +6,7 @@ with lib; let - drivers = config.services.xserver.videoDrivers; + drivers = config.hardware.graphics.videoDrivers; enabled = elem "amdgpu-pro" drivers; diff --git a/nixos/modules/hardware/video/displaylink.nix b/nixos/modules/hardware/video/displaylink.nix index 912f53da836a8..d47f9c42046e5 100644 --- a/nixos/modules/hardware/video/displaylink.nix +++ b/nixos/modules/hardware/video/displaylink.nix @@ -4,7 +4,7 @@ with lib; let - enabled = elem "displaylink" config.services.xserver.videoDrivers; + enabled = elem "displaylink" config.hardware.graphics.videoDrivers; evdi = config.boot.kernelPackages.evdi; diff --git a/nixos/modules/hardware/video/nvidia.nix b/nixos/modules/hardware/video/nvidia.nix index c0ba60e49a731..4fafbc5136354 100644 --- a/nixos/modules/hardware/video/nvidia.nix +++ b/nixos/modules/hardware/video/nvidia.nix @@ -6,7 +6,7 @@ with lib; let nvidia_x11 = let - drivers = config.services.xserver.videoDrivers; + drivers = config.hardware.graphics.videoDrivers; isDeprecated = str: (hasPrefix "nvidia" str) && (str != "nvidia"); hasDeprecated = drivers: any isDeprecated drivers; in if (hasDeprecated drivers) then @@ -107,7 +107,7 @@ in without a multiplexer. Note that this option only has any effect if the "nvidia" driver is specified - in , and it should preferably + in , and it should preferably be the only driver there. If this is enabled, then the bus IDs of the NVIDIA and Intel GPUs have to be @@ -341,7 +341,7 @@ in # nvidia-uvm is required by CUDA applications. boot.kernelModules = [ "nvidia-uvm" ] ++ - optionals config.services.xserver.enable [ "nvidia" "nvidia_modeset" "nvidia_drm" ]; + optionals config.hardware.graphics.enable [ "nvidia" "nvidia_modeset" "nvidia_drm" ]; # If requested enable modesetting via kernel parameter. boot.kernelParams = optional (offloadCfg.enable || cfg.modesetting.enable) "nvidia-drm.modeset=1" diff --git a/nixos/modules/installer/cd-dvd/system-tarball-sheevaplug.nix b/nixos/modules/installer/cd-dvd/system-tarball-sheevaplug.nix index 458e313a3f751..3762042aa1899 100644 --- a/nixos/modules/installer/cd-dvd/system-tarball-sheevaplug.nix +++ b/nixos/modules/installer/cd-dvd/system-tarball-sheevaplug.nix @@ -134,7 +134,7 @@ in }; # Setting vesa, we don't get the nvidia driver, which can't work in arm. - services.xserver.videoDrivers = [ "vesa" ]; + hardware.graphics.videoDrivers = [ "vesa" ]; documentation.nixos.enable = false; diff --git a/nixos/modules/installer/tools/nixos-generate-config.pl b/nixos/modules/installer/tools/nixos-generate-config.pl index 57aef50a0f6ba..28e11042392d0 100644 --- a/nixos/modules/installer/tools/nixos-generate-config.pl +++ b/nixos/modules/installer/tools/nixos-generate-config.pl @@ -330,7 +330,7 @@ sub findStableDevPath { return $dev; } -push @attrs, "services.xserver.videoDrivers = [ \"$videoDriver\" ];" if $videoDriver; +push @attrs, "hardware.graphics.videoDrivers = [ \"$videoDriver\" ];" if $videoDriver; # Generate the swapDevices option from the currently activated swap # devices. diff --git a/nixos/modules/installer/virtualbox-demo.nix b/nixos/modules/installer/virtualbox-demo.nix index 27a7651382b25..1e799a149f6d3 100644 --- a/nixos/modules/installer/virtualbox-demo.nix +++ b/nixos/modules/installer/virtualbox-demo.nix @@ -18,7 +18,7 @@ with lib; # Add some more video drivers to give X11 a shot at working in # VMware and QEMU. - services.xserver.videoDrivers = mkOverride 40 [ "virtualbox" "vmware" "cirrus" "vesa" "modesetting" ]; + hardwware.graphics.videoDrivers = mkOverride 40 [ "virtualbox" "vmware" "cirrus" "vesa" "modesetting" ]; powerManagement.enable = false; system.stateVersion = mkDefault "18.03"; diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index e782e79661ef1..29dffc522a12c 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -49,6 +49,7 @@ ./hardware/corectrl.nix ./hardware/digitalbitbox.nix ./hardware/device-tree.nix + ./hardware/graphics.nix ./hardware/gkraken.nix ./hardware/flirc.nix ./hardware/gpgsmartcards.nix diff --git a/nixos/modules/services/x11/display-managers/xpra.nix b/nixos/modules/services/x11/display-managers/xpra.nix index c23e479140f09..e1b71a7b65445 100644 --- a/nixos/modules/services/x11/display-managers/xpra.nix +++ b/nixos/modules/services/x11/display-managers/xpra.nix @@ -46,7 +46,7 @@ in ###### implementation config = mkIf cfg.enable { - services.xserver.videoDrivers = ["dummy"]; + hardware.graphics.videoDrivers = ["dummy"]; services.xserver.monitorSection = '' HorizSync 1.0 - 2000.0 diff --git a/nixos/modules/services/x11/terminal-server.nix b/nixos/modules/services/x11/terminal-server.nix index e6b50c21a9526..4f87235a3029e 100644 --- a/nixos/modules/services/x11/terminal-server.nix +++ b/nixos/modules/services/x11/terminal-server.nix @@ -14,7 +14,7 @@ with lib; config = { services.xserver.enable = true; - services.xserver.videoDrivers = []; + hardware.graphics.videoDrivers = []; # Enable GDM. Any display manager will do as long as it supports XDMCP. services.xserver.displayManager.gdm.enable = true; diff --git a/nixos/modules/services/x11/xserver.nix b/nixos/modules/services/x11/xserver.nix index ec6d86d59bdfb..f6f06c2d7c631 100644 --- a/nixos/modules/services/x11/xserver.nix +++ b/nixos/modules/services/x11/xserver.nix @@ -248,32 +248,6 @@ in ''; }; - videoDrivers = mkOption { - type = types.listOf types.str; - default = [ "amdgpu" "radeon" "nouveau" "modesetting" "fbdev" ]; - example = [ - "nvidia" "nvidiaLegacy390" "nvidiaLegacy340" "nvidiaLegacy304" - "amdgpu-pro" - ]; - # TODO(@oxij): think how to easily add the rest, like those nvidia things - relatedPackages = concatLists - (mapAttrsToList (n: v: - optional (hasPrefix "xf86video" n) { - path = [ "xorg" n ]; - title = removePrefix "xf86video" n; - }) pkgs.xorg); - description = '' - The names of the video drivers the configuration - supports. They will be tried in order until one that - supports your card is found. - Don't combine those with "incompatible" OpenGL implementations, - e.g. free ones (mesa-based) with proprietary ones. - - For unfree "nvidia*", the supported GPU lists are on - https://www.nvidia.com/object/unix.html - ''; - }; - videoDriver = mkOption { type = types.nullOr types.str; default = null; @@ -281,7 +255,7 @@ in description = '' The name of the video driver for your graphics card. This option is obsolete; please set the - instead. + instead. ''; }; @@ -607,10 +581,10 @@ in hardware.opengl.enable = mkDefault true; - services.xserver.videoDrivers = mkIf (cfg.videoDriver != null) [ cfg.videoDriver ]; + hardware.graphics.videoDrivers = mkIf (cfg.videoDriver != null) [ cfg.videoDriver ]; # FIXME: somehow check for unknown driver names. - services.xserver.drivers = flip concatMap cfg.videoDrivers (name: + services.xserver.drivers = flip concatMap config.hardware.graphics.videoDrivers (name: let driver = attrByPath [name] (if xorg ? ${"xf86video" + name} @@ -620,6 +594,9 @@ in in optional (driver != null) ({ inherit name; modules = []; driverName = name; display = true; } // driver)); assertions = [ + { assertion = hardware.graphics.enabled; + message = "X11 requires hardware.graphics.enabled to be true, until graphics drivers and X settings are further decoupled."; + } { assertion = config.security.polkit.enable; message = "X11 requires Polkit to be enabled (‘security.polkit.enable = true’)."; } @@ -675,7 +652,7 @@ in xorg.xf86inputevdev.out # get evdev.4 man page pkgs.nixos-icons # needed for gnome and pantheon about dialog, nixos-manual and maybe more ] - ++ optional (elem "virtualbox" cfg.videoDrivers) xorg.xrefresh; + ++ optional (elem "virtualbox" config.hardware.graphics.videoDrivers) xorg.xrefresh; environment.pathsToLink = [ "/share/X11" ]; diff --git a/nixos/modules/virtualisation/qemu-vm.nix b/nixos/modules/virtualisation/qemu-vm.nix index 5143893589470..8913520d7a1f7 100644 --- a/nixos/modules/virtualisation/qemu-vm.nix +++ b/nixos/modules/virtualisation/qemu-vm.nix @@ -970,7 +970,7 @@ in # When building a regular system configuration, override whatever # video driver the host uses. - services.xserver.videoDrivers = mkVMOverride [ "modesetting" ]; + hardware.graphics.videoDrivers = mkVMOverride [ "modesetting" ]; services.xserver.defaultDepth = mkVMOverride 0; services.xserver.resolutions = mkVMOverride [ cfg.resolution ]; services.xserver.monitorSection = diff --git a/nixos/modules/virtualisation/virtualbox-guest.nix b/nixos/modules/virtualisation/virtualbox-guest.nix index 7b55b3b9759ea..b1206d15479f1 100644 --- a/nixos/modules/virtualisation/virtualbox-guest.nix +++ b/nixos/modules/virtualisation/virtualbox-guest.nix @@ -68,7 +68,7 @@ in SUBSYSTEM=="misc", KERNEL=="vboxguest", TAG+="systemd" ''; } (mkIf cfg.x11 { - services.xserver.videoDrivers = [ "vmware" "virtualbox" "modesetting" ]; + hardware.graphics.videoDrivers = [ "vmware" "virtualbox" "modesetting" ]; services.xserver.config = '' diff --git a/nixos/modules/virtualisation/vmware-guest.nix b/nixos/modules/virtualisation/vmware-guest.nix index 3caed746ca91e..4a825ea2816ad 100644 --- a/nixos/modules/virtualisation/vmware-guest.nix +++ b/nixos/modules/virtualisation/vmware-guest.nix @@ -63,8 +63,11 @@ in environment.etc.vmware-tools.source = "${open-vm-tools}/etc/vmware-tools/*"; - services.xserver = mkIf (!cfg.headless) { + hardware.graphics = mkIf (!cfg.headless) { videoDrivers = mkOverride 50 [ "vmware" ]; + }; + + services.xserver = mkIf (!cfg.headless) { modules = [ xf86inputvmmouse ]; config = ''