summary refs log tree commit diff
path: root/nixos/modules/hardware
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2014-04-29 14:16:34 +0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2014-04-29 14:42:36 +0200
commit02cef04c8187f12fd160d5fedf0ec8a928f02639 (patch)
treec5b52b19ae13347b1b025ab203115a1c53860412 /nixos/modules/hardware
parent3fe96bcca168b8b3ca9b9cb56f2568c338b0936d (diff)
downloadnixlib-02cef04c8187f12fd160d5fedf0ec8a928f02639.tar
nixlib-02cef04c8187f12fd160d5fedf0ec8a928f02639.tar.gz
nixlib-02cef04c8187f12fd160d5fedf0ec8a928f02639.tar.bz2
nixlib-02cef04c8187f12fd160d5fedf0ec8a928f02639.tar.lz
nixlib-02cef04c8187f12fd160d5fedf0ec8a928f02639.tar.xz
nixlib-02cef04c8187f12fd160d5fedf0ec8a928f02639.tar.zst
nixlib-02cef04c8187f12fd160d5fedf0ec8a928f02639.zip
Move the NVIDIA support into its own module
Previously all card-specific stuff was scattered across xserver.nix
and opengl.nix, which is ugly. Now it can be kept together in a single
card-specific module. This required the addition of a few internal
options:

- services.xserver.drivers: A list of { name, driverName, modules,
  libPath } sets.

- hardware.opengl.package: The OpenGL implementation. Note that there
  can be only one OpenGL implementation at a time in a system
  configuration (i.e. no dynamic detection).

- hardware.opengl.package32: The 32-bit OpenGL implementation.
Diffstat (limited to 'nixos/modules/hardware')
-rw-r--r--nixos/modules/hardware/opengl.nix102
-rw-r--r--nixos/modules/hardware/video/nvidia.nix54
2 files changed, 105 insertions, 51 deletions
diff --git a/nixos/modules/hardware/opengl.nix b/nixos/modules/hardware/opengl.nix
index b2c97f0bfad2..2d5643d4d940 100644
--- a/nixos/modules/hardware/opengl.nix
+++ b/nixos/modules/hardware/opengl.nix
@@ -10,6 +10,15 @@ let
 
   videoDrivers = config.services.xserver.videoDrivers;
 
+  makePackage = p: p.buildEnv {
+    name = "mesa-drivers+txc-${p.mesa_drivers.version}";
+    paths =
+      [ p.mesa_drivers
+        p.mesa_noglu # mainly for libGL
+        (if cfg.s3tcSupport then p.libtxc_dxtn else p.libtxc_dxtn_s2tc)
+      ];
+  };
+
 in
 
 {
@@ -52,73 +61,64 @@ in
       '';
     };
 
+    hardware.opengl.package = mkOption {
+      type = types.package;
+      internal = true;
+      description = ''
+        The package that provides the OpenGL implementation.
+      '';
+    };
+
+    hardware.opengl.package32 = mkOption {
+      type = types.package;
+      internal = true;
+      description = ''
+        The package that provides the 32-bit OpenGL implementation on
+        64-bit systems.  Used when <option>driSupport32Bit</option> is
+        set.
+      '';
+    };
+
   };
 
   config = mkIf cfg.enable {
+
     assertions = pkgs.lib.singleton {
       assertion = cfg.driSupport32Bit -> pkgs.stdenv.isx86_64;
-      message = "Option driSupport32Bit only makes sens on a 64-bit system.";
+      message = "Option driSupport32Bit only makes sense on a 64-bit system.";
     };
 
-    system.activationScripts.setup-opengl.deps = [];
-    system.activationScripts.setup-opengl.text = ''
-      rm -f /run/opengl-driver{,-32}
-      ${optionalString (pkgs.stdenv.isi686) "ln -sf opengl-driver /run/opengl-driver-32"}
-    ''
-      #TODO:  The OpenGL driver should depend on what's detected at runtime.
-     +( if elem "nvidia" videoDrivers then
-          ''
-            ln -sf ${kernelPackages.nvidia_x11} /run/opengl-driver
-            ${optionalString cfg.driSupport32Bit
-              "ln -sf ${pkgs_i686.linuxPackages.nvidia_x11.override { libsOnly = true; kernel = null; } } /run/opengl-driver-32"}
-          ''
-        else if elem "nvidiaLegacy173" videoDrivers then
-          "ln -sf ${kernelPackages.nvidia_x11_legacy173} /run/opengl-driver"
-        else if elem "nvidiaLegacy304" videoDrivers then
-          ''
-            ln -sf ${kernelPackages.nvidia_x11_legacy304} /run/opengl-driver
-            ${optionalString cfg.driSupport32Bit
-              "ln -sf ${pkgs_i686.linuxPackages.nvidia_x11_legacy304.override { libsOnly = true; kernel = null; } } /run/opengl-driver-32"}
-          ''
-        else if elem "ati_unfree" videoDrivers then
-          "ln -sf ${kernelPackages.ati_drivers_x11} /run/opengl-driver"
-        else
-          let
-            lib_fun = p: p.buildEnv {
-              name = "mesa-drivers+txc-${p.mesa_drivers.version}";
-              paths = [
-                p.mesa_drivers
-                p.mesa_noglu # mainly for libGL
-                (if cfg.s3tcSupport then p.libtxc_dxtn else p.libtxc_dxtn_s2tc)
-              ];
-            };
-          in
-          ''
-            ${optionalString cfg.driSupport "ln -sf ${lib_fun pkgs} /run/opengl-driver"}
-            ${optionalString cfg.driSupport32Bit
-              "ln -sf ${lib_fun pkgs_i686} /run/opengl-driver-32"}
-          ''
-      );
+    system.activationScripts.setup-opengl =
+      ''
+        ln -sfn ${cfg.package} /run/opengl-driver
+        ${if pkgs.stdenv.isi686 then ''
+          ln -sfn opengl-driver /run/opengl-driver-32
+        '' else if cfg.driSupport32Bit then ''
+          ln -sfn ${cfg.package32} /run/opengl-driver-32
+        '' else ''
+          rm -f /run/opengl-driver-32
+        ''}
+      '';
 
     environment.variables.LD_LIBRARY_PATH =
       [ "/run/opengl-driver/lib" "/run/opengl-driver-32/lib" ];
 
+    # FIXME: move this into card-specific modules.
+    hardware.opengl.package = mkDefault
+      (if elem "ati_unfree" videoDrivers then
+        kernelPackages.ati_drivers_x11
+      else
+        makePackage pkgs);
+
+    hardware.opengl.package32 = mkDefault (makePackage pkgs_i686);
+
     boot.extraModulePackages =
-      optional (elem "nvidia" videoDrivers) kernelPackages.nvidia_x11 ++
-      optional (elem "nvidiaLegacy173" videoDrivers) kernelPackages.nvidia_x11_legacy173 ++
-      optional (elem "nvidiaLegacy304" videoDrivers) kernelPackages.nvidia_x11_legacy304 ++
       optional (elem "virtualbox" videoDrivers) kernelPackages.virtualboxGuestAdditions ++
       optional (elem "ati_unfree" videoDrivers) kernelPackages.ati_drivers_x11;
 
-    boot.blacklistedKernelModules =
-      optionals (elem "nvidia" videoDrivers) [ "nouveau" "nvidiafb" ];
-
     environment.etc =
-      (optionalAttrs (elem "ati_unfree" videoDrivers) {
+      optionalAttrs (elem "ati_unfree" videoDrivers) {
         "ati".source = "${kernelPackages.ati_drivers_x11}/etc/ati";
-      })
-      // (optionalAttrs (elem "nvidia" videoDrivers) {
-        "OpenCL/vendors/nvidia.icd".source = "${kernelPackages.nvidia_x11}/lib/vendors/nvidia.icd";
-      });
+      };
   };
 }
diff --git a/nixos/modules/hardware/video/nvidia.nix b/nixos/modules/hardware/video/nvidia.nix
new file mode 100644
index 000000000000..0ca5558ee104
--- /dev/null
+++ b/nixos/modules/hardware/video/nvidia.nix
@@ -0,0 +1,54 @@
+# This module provides the proprietary NVIDIA X11 / OpenGL drivers.
+
+{ config, lib, pkgs, pkgs_i686, ... }:
+
+with lib;
+
+let
+
+  drivers = config.services.xserver.videoDrivers;
+
+  # FIXME: should introduce an option like
+  # ‘hardware.video.nvidia.package’ for overriding the default NVIDIA
+  # driver.
+  enabled = elem "nvidia" drivers || elem "nvidiaLegacy173" drivers || elem "nvidiaLegacy304" drivers;
+
+  nvidia_x11 =
+    if elem "nvidia" drivers then
+      config.boot.kernelPackages.nvidia_x11
+    else if elem "nvidiaLegacy173" drivers then
+      config.boot.kernelPackages.nvidia_x11_legacy173
+    else if elem "nvidiaLegacy304" videoDrivers then
+      config.boot.kernelPackages.nvidia_x11_legacy304
+    else throw "impossible";
+
+in
+
+{
+
+  config = mkIf enabled {
+
+    services.xserver.drivers = singleton
+      { name = "nvidia"; modules = [ nvidia_x11 ]; libPath = [ nvidia_x11 ]; };
+
+    services.xserver.screenSection =
+      ''
+        Option "RandRRotation" "on"
+      '';
+
+    hardware.opengl.package = nvidia_x11;
+    hardware.opengl.package32 = pkgs_i686.linuxPackages.nvidia_x11.override { libsOnly = true; kernel = null; };
+
+    environment.systemPackages = [ nvidia_x11 ];
+
+    boot.extraModulePackages = [ nvidia_x11 ];
+
+    boot.blacklistedKernelModules = [ "nouveau" "nvidiafb" ];
+
+    services.acpid.enable = true;
+
+    environment.etc."OpenCL/vendors/nvidia.icd".source = "${nvidia_x11}/lib/vendors/nvidia.icd";
+
+  };
+
+}