Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start decoupling X and graphics support with videoDrivers #153808

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions nixos/doc/manual/configuration/x-windows.chapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -115,19 +115,19 @@ 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;
```

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"
Expand All @@ -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
Expand All @@ -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
Expand Down
18 changes: 9 additions & 9 deletions nixos/doc/manual/from_md/configuration/x-windows.chapter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ services.xserver.enable = true;
manually, e.g.
</para>
<programlisting language="bash">
services.xserver.videoDrivers = [ &quot;r128&quot; ];
hardware.graphics.videoDrivers = [ &quot;r128&quot; ];
</programlisting>
<para>
to enable X.org’s <literal>xf86-video-r128</literal> driver.
Expand Down Expand Up @@ -128,19 +128,19 @@ services.xserver.displayManager.autoLogin.user = &quot;alice&quot;;
<para>
The results vary depending on the hardware, so you may have to try
both drivers. Use the option
<xref linkend="opt-services.xserver.videoDrivers" /> to set one.
<xref linkend="opt-hardware.graphics.videoDrivers" /> to set one.
The recommended configuration for modern systems is:
</para>
<programlisting language="bash">
services.xserver.videoDrivers = [ &quot;modesetting&quot; ];
hardware.graphics.videoDrivers = [ &quot;modesetting&quot; ];
services.xserver.useGlamor = true;
</programlisting>
<para>
If you experience screen tearing no matter what, this
configuration was reported to resolve the issue:
</para>
<programlisting language="bash">
services.xserver.videoDrivers = [ &quot;intel&quot; ];
hardware.graphics.videoDrivers = [ &quot;intel&quot; ];
services.xserver.deviceSection = ''
Option &quot;DRI&quot; &quot;2&quot;
Option &quot;TearFree&quot; &quot;true&quot;
Expand All @@ -161,16 +161,16 @@ services.xserver.deviceSection = ''
it as follows:
</para>
<programlisting language="bash">
services.xserver.videoDrivers = [ &quot;nvidia&quot; ];
hardware.graphics.videoDrivers = [ &quot;nvidia&quot; ];
</programlisting>
<para>
Or if you have an older card, you may have to use one of the
legacy drivers:
</para>
<programlisting language="bash">
services.xserver.videoDrivers = [ &quot;nvidiaLegacy390&quot; ];
services.xserver.videoDrivers = [ &quot;nvidiaLegacy340&quot; ];
services.xserver.videoDrivers = [ &quot;nvidiaLegacy304&quot; ];
hardware.graphics.videoDrivers = [ &quot;nvidiaLegacy390&quot; ];
hardware.graphics.videoDrivers = [ &quot;nvidiaLegacy340&quot; ];
hardware.graphics.videoDrivers = [ &quot;nvidiaLegacy304&quot; ];
</programlisting>
<para>
You may need to reboot after enabling this driver to prevent a
Expand All @@ -187,7 +187,7 @@ services.xserver.videoDrivers = [ &quot;nvidiaLegacy304&quot; ];
need to explicitly set:
</para>
<programlisting language="bash">
services.xserver.videoDrivers = [ &quot;amdgpu-pro&quot; ];
hardware.graphics.videoDrivers = [ &quot;amdgpu-pro&quot; ];
</programlisting>
<para>
You will need to reboot after enabling this driver to prevent a
Expand Down
77 changes: 77 additions & 0 deletions nixos/modules/hardware/graphics.nix
Original file line number Diff line number Diff line change
@@ -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 {


};
Comment on lines +70 to +73
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note nothing happens yet, because the boot modules are appended per-card.


# uses relatedPackages
meta.buildDocsInSandbox = false;
}
4 changes: 2 additions & 2 deletions nixos/modules/hardware/opengl.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/hardware/video/amdgpu-pro.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ with lib;

let

drivers = config.services.xserver.videoDrivers;
drivers = config.hardware.graphics.videoDrivers;

enabled = elem "amdgpu-pro" drivers;

Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/hardware/video/displaylink.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions nixos/modules/hardware/video/nvidia.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -107,7 +107,7 @@ in
without a multiplexer.

Note that this option only has any effect if the "nvidia" driver is specified
in <option>services.xserver.videoDrivers</option>, and it should preferably
in <option>hardware.graphics.videoDrivers</option>, 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
Expand Down Expand Up @@ -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" ];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just ran into this myself, I think. This is what I was looking for. 👍


# If requested enable modesetting via kernel parameter.
boot.kernelParams = optional (offloadCfg.enable || cfg.modesetting.enable) "nvidia-drm.modeset=1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/installer/tools/nixos-generate-config.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/installer/virtualbox-demo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
1 change: 1 addition & 0 deletions nixos/modules/module-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/services/x11/display-managers/xpra.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/services/x11/terminal-server.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
37 changes: 7 additions & 30 deletions nixos/modules/services/x11/xserver.nix
Original file line number Diff line number Diff line change
Expand Up @@ -248,40 +248,14 @@ 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;
example = "i810";
description = ''
The name of the video driver for your graphics card. This
option is obsolete; please set the
<option>services.xserver.videoDrivers</option> instead.
<option>hardware.graphics.videoDrivers</option> instead.
'';
};

Expand Down Expand Up @@ -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}
Expand All @@ -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’).";
}
Expand Down Expand Up @@ -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" ];

Expand Down
Loading