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

nixos/opengl: use systemd.tmpfiles.settings #317585

Merged
merged 2 commits into from
Jun 6, 2024
Merged
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
69 changes: 33 additions & 36 deletions nixos/modules/hardware/opengl.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{ config, lib, pkgs, ... }:

with lib;

let

cfg = config.hardware.opengl;
Expand All @@ -25,14 +23,14 @@ in
{

imports = [
(mkRenamedOptionModule [ "services" "xserver" "vaapiDrivers" ] [ "hardware" "opengl" "extraPackages" ])
(mkRemovedOptionModule [ "hardware" "opengl" "s3tcSupport" ] "S3TC support is now always enabled in Mesa.")
(lib.mkRenamedOptionModule [ "services" "xserver" "vaapiDrivers" ] [ "hardware" "opengl" "extraPackages" ])
(lib.mkRemovedOptionModule [ "hardware" "opengl" "s3tcSupport" ] "S3TC support is now always enabled in Mesa.")
];

options = {

hardware.opengl = {
enable = mkOption {
enable = lib.mkOption {
description = ''
Whether to enable OpenGL drivers. This is needed to enable
OpenGL support in X11 systems, as well as for Wayland compositors
Expand All @@ -42,21 +40,21 @@ in
compositor of choice. See services.xserver.enable and
programs.sway.enable.
'';
type = types.bool;
type = lib.types.bool;
default = false;
};

driSupport = mkOption {
type = types.bool;
driSupport = lib.mkOption {
type = lib.types.bool;
default = true;
description = ''
Whether to enable accelerated OpenGL rendering through the
Direct Rendering Interface (DRI).
'';
};

driSupport32Bit = mkOption {
type = types.bool;
driSupport32Bit = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''
On 64-bit systems, whether to support Direct Rendering for
Expand All @@ -66,16 +64,16 @@ in
'';
};

package = mkOption {
type = types.package;
package = lib.mkOption {
type = lib.types.package;
internal = true;
description = ''
The package that provides the OpenGL implementation.
'';
};

package32 = mkOption {
type = types.package;
package32 = lib.mkOption {
type = lib.types.package;
internal = true;
description = ''
The package that provides the 32-bit OpenGL implementation on
Expand All @@ -84,10 +82,10 @@ in
'';
};

extraPackages = mkOption {
type = types.listOf types.package;
extraPackages = lib.mkOption {
type = lib.types.listOf lib.types.package;
default = [];
example = literalExpression "with pkgs; [ intel-media-driver intel-ocl intel-vaapi-driver ]";
example = lib.literalExpression "with pkgs; [ intel-media-driver intel-ocl intel-vaapi-driver ]";
description = ''
Additional packages to add to OpenGL drivers.
This can be used to add OpenCL drivers, VA-API/VDPAU drivers etc.
Expand All @@ -98,10 +96,10 @@ in
'';
};

extraPackages32 = mkOption {
type = types.listOf types.package;
extraPackages32 =lib. mkOption {
type = lib.types.listOf lib.types.package;
default = [];
example = literalExpression "with pkgs.pkgsi686Linux; [ intel-media-driver intel-vaapi-driver ]";
example = lib.literalExpression "with pkgs.pkgsi686Linux; [ intel-media-driver intel-vaapi-driver ]";
description = ''
Additional packages to add to 32-bit OpenGL drivers on 64-bit systems.
Used when {option}`driSupport32Bit` is set. This can be used to add OpenCL drivers, VA-API/VDPAU drivers etc.
Expand All @@ -112,8 +110,8 @@ in
'';
};

setLdLibraryPath = mkOption {
type = types.bool;
setLdLibraryPath = lib.mkOption {
type = lib.types.bool;
internal = true;
default = false;
description = ''
Expand All @@ -128,7 +126,7 @@ in

};

config = mkIf cfg.enable {
config = lib.mkIf cfg.enable {
assertions = [
{ assertion = cfg.driSupport32Bit -> pkgs.stdenv.isx86_64;
message = "Option driSupport32Bit only makes sense on a 64-bit system.";
Expand All @@ -138,24 +136,23 @@ in
}
];

systemd.tmpfiles.rules = [
"L+ /run/opengl-driver - - - - ${package}"
(
systemd.tmpfiles.settings.opengl = {
"/run/opengl-driver"."L+".argument = toString package;
"/run/opengl-drive-32" =
if pkgs.stdenv.isi686 then
"L+ /run/opengl-driver-32 - - - - opengl-driver"
{ "L+".argument = "opengl-driver"; }
else if cfg.driSupport32Bit then
"L+ /run/opengl-driver-32 - - - - ${package32}"
{ "L+".argument = toString package32; }
else
"r /run/opengl-driver-32"
)
];
{ "r" = {}; };
};

environment.sessionVariables.LD_LIBRARY_PATH = mkIf cfg.setLdLibraryPath
([ "/run/opengl-driver/lib" ] ++ optional cfg.driSupport32Bit "/run/opengl-driver-32/lib");
environment.sessionVariables.LD_LIBRARY_PATH = lib.mkIf cfg.setLdLibraryPath
([ "/run/opengl-driver/lib" ] ++ lib.optional cfg.driSupport32Bit "/run/opengl-driver-32/lib");

hardware.opengl.package = mkDefault pkgs.mesa.drivers;
hardware.opengl.package32 = mkDefault pkgs.pkgsi686Linux.mesa.drivers;
hardware.opengl.package = lib.mkDefault pkgs.mesa.drivers;
hardware.opengl.package32 = lib.mkDefault pkgs.pkgsi686Linux.mesa.drivers;

boot.extraModulePackages = optional (elem "virtualbox" videoDrivers) kernelPackages.virtualboxGuestAdditions;
boot.extraModulePackages = lib.optional (lib.elem "virtualbox" videoDrivers) kernelPackages.virtualboxGuestAdditions;
};
}