From 450cb04f16cc2214c2a298fe26bb4c306cf84fb3 Mon Sep 17 00:00:00 2001 From: Frederik Rietdijk Date: Sat, 3 Nov 2018 19:50:12 +0100 Subject: [PATCH] nixos: hardware.nvidia.package option for selecting nvidia package Make it possible to select a derivation to use. This also moves some logic that belongs to the derivation back into it. --- nixos/modules/hardware/video/nvidia.nix | 51 ++++++++----------- pkgs/os-specific/linux/nvidia-x11/default.nix | 16 ++++-- pkgs/os-specific/linux/nvidia-x11/generic.nix | 4 ++ 3 files changed, 36 insertions(+), 35 deletions(-) diff --git a/nixos/modules/hardware/video/nvidia.nix b/nixos/modules/hardware/video/nvidia.nix index d1cf7d05c1b8..f3a617379aba 100644 --- a/nixos/modules/hardware/video/nvidia.nix +++ b/nixos/modules/hardware/video/nvidia.nix @@ -5,36 +5,17 @@ with lib; let - - drivers = config.services.xserver.videoDrivers; - - # FIXME: should introduce an option like - # ‘hardware.video.nvidia.package’ for overriding the default NVIDIA - # driver. - nvidiaForKernel = kernelPackages: - if elem "nvidia" drivers then - kernelPackages.nvidia_x11 - else if elem "nvidiaBeta" drivers then - kernelPackages.nvidia_x11_beta - else if elem "nvidiaVulkanBeta" drivers then - kernelPackages.nvidia_x11_vulkan_beta - else if elem "nvidiaLegacy304" drivers then - kernelPackages.nvidia_x11_legacy304 - else if elem "nvidiaLegacy340" drivers then - kernelPackages.nvidia_x11_legacy340 - else if elem "nvidiaLegacy390" drivers then - kernelPackages.nvidia_x11_legacy390 - else null; - - nvidia_x11 = nvidiaForKernel config.boot.kernelPackages; - nvidia_libs32 = - if versionOlder nvidia_x11.version "391" then - ((nvidiaForKernel pkgs.pkgsi686Linux.linuxPackages).override { libsOnly = true; kernel = null; }).out - else - (nvidiaForKernel config.boot.kernelPackages).lib32; + nvidia_x11 = let + drivers = config.services.xserver.videoDrivers; + isDeprecated = str: (hasPrefix "nvidia" str) && (str != "nvidia"); + hasDeprecated = drivers: any isDeprecated drivers; + in if (hasDeprecated drivers) then + throw '' + Selecting an nvidia driver has been modified for NixOS 19.03. The version is now set using `hardware.nvidia.package`. + '' + else if (elem "nvidia" drivers) then cfg.package else null; enabled = nvidia_x11 != null; - cfg = config.hardware.nvidia; pCfg = cfg.prime; @@ -151,6 +132,16 @@ in GPUs stay awake even during headless mode. ''; }; + + hardware.nvidia.package = lib.mkOption { + type = lib.types.package; + default = config.boot.kernelPackages.nvidiaPackages.stable; + defaultText = "config.boot.kernelPackages.nvidiaPackages.stable"; + description = '' + The NVIDIA X11 derivation to use. + ''; + example = "config.boot.kernelPackages.nvidiaPackages.legacy340"; + }; }; config = mkIf enabled { @@ -230,9 +221,9 @@ in }; hardware.opengl.package = mkIf (!offloadCfg.enable) nvidia_x11.out; - hardware.opengl.package32 = mkIf (!offloadCfg.enable) nvidia_libs32; + hardware.opengl.package32 = mkIf (!offloadCfg.enable) nvidia_x11.lib32; hardware.opengl.extraPackages = optional offloadCfg.enable nvidia_x11.out; - hardware.opengl.extraPackages32 = optional offloadCfg.enable nvidia_libs32; + hardware.opengl.extraPackages32 = optional offloadCfg.enable nvidia_x11.lib32; environment.systemPackages = [ nvidia_x11.bin nvidia_x11.settings ] ++ optionals nvidiaPersistencedEnabled [ nvidia_x11.persistenced ]; diff --git a/pkgs/os-specific/linux/nvidia-x11/default.nix b/pkgs/os-specific/linux/nvidia-x11/default.nix index 4b0c060f9ce4..dd491f884f66 100644 --- a/pkgs/os-specific/linux/nvidia-x11/default.nix +++ b/pkgs/os-specific/linux/nvidia-x11/default.nix @@ -1,11 +1,17 @@ -{ lib, callPackage, fetchpatch, fetchurl, stdenv }: +{ lib, callPackage, fetchpatch, fetchurl, stdenv, pkgsi686Linux }: let - -generic = args: -if ((!lib.versionOlder args.version "391") + generic = args: let + imported = import ./generic.nix args; + in if ((!lib.versionOlder args.version "391") && stdenv.hostPlatform.system != "x86_64-linux") then null - else callPackage (import ./generic.nix args) { }; + else callPackage imported { + lib32 = (pkgsi686Linux.callPackage imported { + libsOnly = true; + kernel = null; + }).out; + }; + kernel = callPackage # a hacky way of extracting parameters from callPackage ({ kernel, libsOnly ? false }: if libsOnly then { } else kernel) { }; diff --git a/pkgs/os-specific/linux/nvidia-x11/generic.nix b/pkgs/os-specific/linux/nvidia-x11/generic.nix index 1587ad06bc30..8d102e501afd 100644 --- a/pkgs/os-specific/linux/nvidia-x11/generic.nix +++ b/pkgs/os-specific/linux/nvidia-x11/generic.nix @@ -25,6 +25,8 @@ , # don't include the bundled 32-bit libraries on 64-bit platforms, # even if it’s in downloaded binary disable32Bit ? false + # 32 bit libs only version of this package +, lib32 ? null }: with stdenv.lib; @@ -93,6 +95,8 @@ let }; persistenced = mapNullable (hash: callPackage (import ./persistenced.nix self hash) { }) persistencedSha256; inherit persistencedVersion settingsVersion; + } // optionalAttrs (!i686bundled) { + inherit lib32; }; meta = with lib; {