0
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-07-13 21:50:33 +03:00

nixos/nvidia: optimus_prime -> prime.sync

This commit is contained in:
Edmund Wu 2019-08-14 08:15:43 -04:00
parent 5d21e8c92b
commit aca9ffe893
No known key found for this signature in database
GPG key ID: 76AA3F9F2BD3E3A0

View file

@ -34,10 +34,18 @@ let
enabled = nvidia_x11 != null; enabled = nvidia_x11 != null;
cfg = config.hardware.nvidia; cfg = config.hardware.nvidia;
optimusCfg = cfg.optimus_prime; syncCfg = cfg.prime.sync;
in in
{ {
imports =
[
(mkRenamedOptionModule [ "hardware" "nvidia" "optimus_prime" "enable" ] [ "hardware" "nvidia" "prime" "sync" "enable" ])
(mkRenamedOptionModule [ "hardware" "nvidia" "optimus_prime" "allowExternalGpu" ] [ "hardware" "nvidia" "prime" "sync" "allowExternalGpu" ])
(mkRenamedOptionModule [ "hardware" "nvidia" "optimus_prime" "nvidiaBusId" ] [ "hardware" "nvidia" "prime" "sync" "nvidiaBusId" ])
(mkRenamedOptionModule [ "hardware" "nvidia" "optimus_prime" "intelBusId" ] [ "hardware" "nvidia" "prime" "sync" "intelBusId" ])
];
options = { options = {
hardware.nvidia.modesetting.enable = mkOption { hardware.nvidia.modesetting.enable = mkOption {
type = types.bool; type = types.bool;
@ -46,13 +54,13 @@ in
Enable kernel modesetting when using the NVIDIA proprietary driver. Enable kernel modesetting when using the NVIDIA proprietary driver.
Enabling this fixes screen tearing when using Optimus via PRIME (see Enabling this fixes screen tearing when using Optimus via PRIME (see
<option>hardware.nvidia.optimus_prime.enable</option>. This is not enabled <option>hardware.nvidia.prime.sync.enable</option>. This is not enabled
by default because it is not officially supported by NVIDIA and would not by default because it is not officially supported by NVIDIA and would not
work with SLI. work with SLI.
''; '';
}; };
hardware.nvidia.optimus_prime.enable = mkOption { hardware.nvidia.prime.sync.enable = mkOption {
type = types.bool; type = types.bool;
default = false; default = false;
description = '' description = ''
@ -66,8 +74,8 @@ in
be the only driver there. be the only driver there.
If this is enabled, then the bus IDs of the NVIDIA and Intel GPUs have to be If this is enabled, then the bus IDs of the NVIDIA and Intel GPUs have to be
specified (<option>hardware.nvidia.optimus_prime.nvidiaBusId</option> and specified (<option>hardware.nvidia.prime.sync.nvidiaBusId</option> and
<option>hardware.nvidia.optimus_prime.intelBusId</option>). <option>hardware.nvidia.prime.sync.intelBusId</option>).
If you enable this, you may want to also enable kernel modesetting for the If you enable this, you may want to also enable kernel modesetting for the
NVIDIA driver (<option>hardware.nvidia.modesetting.enable</option>) in order NVIDIA driver (<option>hardware.nvidia.modesetting.enable</option>) in order
@ -79,7 +87,7 @@ in
''; '';
}; };
hardware.nvidia.optimus_prime.allowExternalGpu = mkOption { hardware.nvidia.prime.sync.allowExternalGpu = mkOption {
type = types.bool; type = types.bool;
default = false; default = false;
description = '' description = ''
@ -87,7 +95,7 @@ in
''; '';
}; };
hardware.nvidia.optimus_prime.nvidiaBusId = mkOption { hardware.nvidia.prime.sync.nvidiaBusId = mkOption {
type = types.str; type = types.str;
default = ""; default = "";
example = "PCI:1:0:0"; example = "PCI:1:0:0";
@ -97,7 +105,7 @@ in
''; '';
}; };
hardware.nvidia.optimus_prime.intelBusId = mkOption { hardware.nvidia.prime.sync.intelBusId = mkOption {
type = types.str; type = types.str;
default = ""; default = "";
example = "PCI:0:2:0"; example = "PCI:0:2:0";
@ -116,8 +124,8 @@ in
} }
{ {
assertion = !optimusCfg.enable || assertion = !syncCfg.enable ||
(optimusCfg.nvidiaBusId != "" && optimusCfg.intelBusId != ""); (syncCfg.nvidiaBusId != "" && syncCfg.intelBusId != "");
message = '' message = ''
When NVIDIA Optimus via PRIME is enabled, the GPU bus IDs must configured. When NVIDIA Optimus via PRIME is enabled, the GPU bus IDs must configured.
''; '';
@ -139,33 +147,33 @@ in
services.xserver.drivers = singleton { services.xserver.drivers = singleton {
name = "nvidia"; name = "nvidia";
modules = [ nvidia_x11.bin ]; modules = [ nvidia_x11.bin ];
deviceSection = optionalString optimusCfg.enable deviceSection = optionalString syncCfg.enable
'' ''
BusID "${optimusCfg.nvidiaBusId}" BusID "${syncCfg.nvidiaBusId}"
${optionalString optimusCfg.allowExternalGpu "Option \"AllowExternalGpus\""} ${optionalString syncCfg.allowExternalGpu "Option \"AllowExternalGpus\""}
''; '';
screenSection = screenSection =
'' ''
Option "RandRRotation" "on" Option "RandRRotation" "on"
${optionalString optimusCfg.enable "Option \"AllowEmptyInitialConfiguration\""} ${optionalString syncCfg.enable "Option \"AllowEmptyInitialConfiguration\""}
''; '';
}; };
services.xserver.extraConfig = optionalString optimusCfg.enable services.xserver.extraConfig = optionalString syncCfg.enable
'' ''
Section "Device" Section "Device"
Identifier "nvidia-optimus-intel" Identifier "nvidia-optimus-intel"
Driver "modesetting" Driver "modesetting"
BusID "${optimusCfg.intelBusId}" BusID "${syncCfg.intelBusId}"
Option "AccelMethod" "none" Option "AccelMethod" "none"
EndSection EndSection
''; '';
services.xserver.serverLayoutSection = optionalString optimusCfg.enable services.xserver.serverLayoutSection = optionalString syncCfg.enable
'' ''
Inactive "nvidia-optimus-intel" Inactive "nvidia-optimus-intel"
''; '';
services.xserver.displayManager.setupCommands = optionalString optimusCfg.enable '' services.xserver.displayManager.setupCommands = optionalString syncCfg.enable ''
# Added by nvidia configuration module for Optimus/PRIME. # Added by nvidia configuration module for Optimus/PRIME.
${pkgs.xorg.xrandr}/bin/xrandr --setprovideroutputsource modesetting NVIDIA-0 ${pkgs.xorg.xrandr}/bin/xrandr --setprovideroutputsource modesetting NVIDIA-0
${pkgs.xorg.xrandr}/bin/xrandr --auto ${pkgs.xorg.xrandr}/bin/xrandr --auto