summaryrefslogtreecommitdiff
path: root/modules/nixos
diff options
context:
space:
mode:
authorseth <[email protected]>2023-12-19 18:14:57 -0500
committerseth <[email protected]>2023-12-19 18:14:57 -0500
commit60790093490e927fbeb6db5345918140433a5621 (patch)
treeb2acb331fc165b6fc5bc94c1e7399a0fd85e49fc /modules/nixos
parentf5935f93b2cd3c16b58d7261f9c1f34b9a429636 (diff)
modules/features: init nvk
Diffstat (limited to 'modules/nixos')
-rw-r--r--modules/nixos/features/default.nix1
-rw-r--r--modules/nixos/features/nvk/default.nix68
-rw-r--r--modules/nixos/features/nvk/disk_cache-include-dri-driver-path-in-cache-key.patch67
-rw-r--r--modules/nixos/features/nvk/opencl.patch67
4 files changed, 203 insertions, 0 deletions
diff --git a/modules/nixos/features/default.nix b/modules/nixos/features/default.nix
index ade778e..3ef81c3 100644
--- a/modules/nixos/features/default.nix
+++ b/modules/nixos/features/default.nix
@@ -1,5 +1,6 @@
{
imports = [
+ ./nvk
./tailscale.nix
./virtualisation.nix
];
diff --git a/modules/nixos/features/nvk/default.nix b/modules/nixos/features/nvk/default.nix
new file mode 100644
index 0000000..68c92ff
--- /dev/null
+++ b/modules/nixos/features/nvk/default.nix
@@ -0,0 +1,68 @@
+{
+ config,
+ lib,
+ pkgs,
+ ...
+}: let
+ cfg = config.features.nvk;
+
+ mkMesa = pkgs:
+ (pkgs.mesa.override {
+ vulkanDrivers =
+ if pkgs.stdenv.isLinux
+ then
+ [
+ "amd" # AMD (aka RADV)
+ "microsoft-experimental" # WSL virtualized GPU (aka DZN/Dozen)
+ "swrast" # software renderer (aka Lavapipe)
+ "nouveau-experimental" # nvk
+ ]
+ ++ lib.optionals (pkgs.stdenv.hostPlatform.isAarch -> lib.versionAtLeast pkgs.stdenv.hostPlatform.parsed.cpu.version "6") [
+ # QEMU virtualized GPU (aka VirGL)
+ # Requires ATOMIC_INT_LOCK_FREE == 2.
+ "virtio"
+ ]
+ ++ lib.optionals pkgs.stdenv.isAarch64 [
+ "broadcom" # Broadcom VC5 (Raspberry Pi 4, aka V3D)
+ "freedreno" # Qualcomm Adreno (all Qualcomm SoCs)
+ "imagination-experimental" # PowerVR Rogue (currently N/A)
+ "panfrost" # ARM Mali Midgard and up (T/G series)
+ ]
+ ++ lib.optionals pkgs.stdenv.hostPlatform.isx86 [
+ "intel" # Intel (aka ANV), could work on non-x86 with PCIe cards, but doesn't build
+ "intel_hasvk" # Intel Haswell/Broadwell, "legacy" Vulkan driver (https://www.phoronix.com/news/Intel-HasVK-Drop-Dead-Code)
+ ]
+ else ["auto"];
+ })
+ .overrideAttrs (new: old: let
+ replacePatches = patch:
+ {
+ "opencl.patch" = ./opencl.patch;
+ "disk_cache-include-dri-driver-path-in-cache-key.patch" = ./disk_cache-include-dri-driver-path-in-cache-key.patch;
+ }
+ .${baseNameOf patch}
+ or patch;
+ in {
+ version = "23.3.1";
+
+ src = pkgs.fetchurl {
+ urls = [
+ "https://archive.mesa3d.org/mesa-${new.version}.tar.xz"
+ "https://mesa.freedesktop.org/archive/mesa-${new.version}.tar.xz"
+ ];
+
+ hash = "sha256-bkgSbXD9s/IP/rJGygwuQf/cg18GY6A9RSa4v120HeY=";
+ };
+
+ patches = map replacePatches old.patches;
+ });
+in {
+ options.features.nvk.enable = lib.mkEnableOption "nvk";
+
+ config = lib.mkIf cfg.enable {
+ hardware.opengl = {
+ package = (mkMesa pkgs).drivers;
+ package32 = (mkMesa pkgs.pkgsi686Linux).drivers;
+ };
+ };
+}
diff --git a/modules/nixos/features/nvk/disk_cache-include-dri-driver-path-in-cache-key.patch b/modules/nixos/features/nvk/disk_cache-include-dri-driver-path-in-cache-key.patch
new file mode 100644
index 0000000..bd19a9a
--- /dev/null
+++ b/modules/nixos/features/nvk/disk_cache-include-dri-driver-path-in-cache-key.patch
@@ -0,0 +1,67 @@
+Author: David McFarland <[email protected]>
+Date: Mon Aug 6 15:52:11 2018 -0300
+
+ [PATCH] disk_cache: include dri driver path in cache key
+
+ This fixes invalid cache hits on NixOS where all shared library
+ timestamps in /nix/store are zero.
+
+diff --git a/meson_options.txt b/meson_options.txt
+index 9639c516d49..c0bb86908ae 100644
+--- a/meson_options.txt
++++ b/meson_options.txt
+@@ -513,6 +513,13 @@ option(
+ description : 'Enable direct rendering in GLX and EGL for DRI',
+ )
+
++option(
++ 'disk-cache-key',
++ type : 'string',
++ value : '',
++ description : 'Mesa cache key.'
++)
++
+ option('egl-lib-suffix',
+ type : 'string',
+ value : '',
+diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c
+index 8298f9d7b32..e622133f566 100644
+--- a/src/util/disk_cache.c
++++ b/src/util/disk_cache.c
+@@ -226,8 +226,10 @@ disk_cache_type_create(const char *gpu_name,
+
+ /* Create driver id keys */
+ size_t id_size = strlen(driver_id) + 1;
++ size_t key_size = strlen(DISK_CACHE_KEY) + 1;
+ size_t gpu_name_size = strlen(gpu_name) + 1;
+ cache->driver_keys_blob_size += id_size;
++ cache->driver_keys_blob_size += key_size;
+ cache->driver_keys_blob_size += gpu_name_size;
+
+ /* We sometimes store entire structs that contains a pointers in the cache,
+@@ -248,6 +250,7 @@ disk_cache_type_create(const char *gpu_name,
+ uint8_t *drv_key_blob = cache->driver_keys_blob;
+ DRV_KEY_CPY(drv_key_blob, &cache_version, cv_size)
+ DRV_KEY_CPY(drv_key_blob, driver_id, id_size)
++ DRV_KEY_CPY(drv_key_blob, DISK_CACHE_KEY, key_size)
+ DRV_KEY_CPY(drv_key_blob, gpu_name, gpu_name_size)
+ DRV_KEY_CPY(drv_key_blob, &ptr_size, ptr_size_size)
+ DRV_KEY_CPY(drv_key_blob, &driver_flags, driver_flags_size)
+diff --git a/src/util/meson.build b/src/util/meson.build
+index c0c1b9d1fa1..442163c5eac 100644
+--- a/src/util/meson.build
++++ b/src/util/meson.build
+@@ -268,7 +268,12 @@ _libmesa_util = static_library(
+ include_directories : [inc_util, include_directories('format')],
+ dependencies : deps_for_libmesa_util,
+ link_with: [libmesa_util_sse41],
+- c_args : [c_msvc_compat_args],
++ c_args : [
++ c_msvc_compat_args,
++ '-DDISK_CACHE_KEY="@0@"'.format(
++ get_option('disk-cache-key')
++ ),
++ ],
+ gnu_symbol_visibility : 'hidden',
+ build_by_default : false
+ )
diff --git a/modules/nixos/features/nvk/opencl.patch b/modules/nixos/features/nvk/opencl.patch
new file mode 100644
index 0000000..c820700
--- /dev/null
+++ b/modules/nixos/features/nvk/opencl.patch
@@ -0,0 +1,67 @@
+diff --git a/meson.build b/meson.build
+index e4570c5..80203cc 100644
+--- a/meson.build
++++ b/meson.build
+@@ -1797,7 +1797,7 @@ endif
+
+ dep_clang = null_dep
+ if with_clc
+- llvm_libdir = dep_llvm.get_variable(cmake : 'LLVM_LIBRARY_DIR', configtool: 'libdir')
++ llvm_libdir = get_option('clang-libdir')
+
+ dep_clang = cpp.find_library('clang-cpp', dirs : llvm_libdir, required : false)
+
+diff --git a/meson_options.txt b/meson_options.txt
+index 3d8425f..fa7c913 100644
+--- a/meson_options.txt
++++ b/meson_options.txt
+@@ -1,6 +1,13 @@
+ # Copyright © 2017-2019 Intel Corporation
+ # SPDX-License-Identifier: MIT
+
++option(
++ 'clang-libdir',
++ type : 'string',
++ value : '',
++ description : 'Locations to search for clang libraries.'
++)
++
+ option(
+ 'platforms',
+ type : 'array',
+diff --git a/src/gallium/targets/opencl/meson.build b/src/gallium/targets/opencl/meson.build
+index 7c14135..74dc685 100644
+--- a/src/gallium/targets/opencl/meson.build
++++ b/src/gallium/targets/opencl/meson.build
+@@ -39,7 +39,8 @@ if dep_llvm.version().version_compare('>=10.0.0')
+ polly_isl_dep = cpp.find_library('PollyISL', dirs : llvm_libdir, required : false)
+ endif
+
+-dep_clang = cpp.find_library('clang-cpp', dirs : llvm_libdir, required : false)
++clang_libdir = get_option('clang-libdir')
++dep_clang = cpp.find_library('clang-cpp', dirs : clang_libdir, required : false)
+
+ # meson will return clang-cpp from system dirs if it's not found in llvm_libdir
+ linker_rpath_arg = '-Wl,--rpath=@0@'.format(llvm_libdir)
+@@ -123,7 +124,7 @@ if with_opencl_icd
+ configuration : _config,
+ input : 'mesa.icd.in',
+ output : 'mesa.icd',
+- install : true,
++ install : false,
+ install_tag : 'runtime',
+ install_dir : join_paths(get_option('sysconfdir'), 'OpenCL', 'vendors'),
+ )
+diff --git a/src/gallium/targets/rusticl/meson.build b/src/gallium/targets/rusticl/meson.build
+index 8205ed7..a11b700 100644
+--- a/src/gallium/targets/rusticl/meson.build
++++ b/src/gallium/targets/rusticl/meson.build
+@@ -75,7 +75,7 @@ configure_file(
+ configuration : _config,
+ input : 'rusticl.icd.in',
+ output : 'rusticl.icd',
+- install : true,
++ install : false,
+ install_tag : 'runtime',
+ install_dir : join_paths(get_option('sysconfdir'), 'OpenCL', 'vendors'),
+ )