2023-06-18 23:36:17 +02:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
{
|
|
|
|
# assumes common-gpu-nvidia from nixos-hardware is also added
|
|
|
|
# TODO: should we move it from flake.nix to here?
|
2024-02-26 11:08:16 +01:00
|
|
|
# https://github.com/NixOS/nixos-hardware/blob/master/common/gpu/nvidia/default.nix
|
|
|
|
# https://github.com/NixOS/nixos-hardware/blob/master/common/gpu/nvidia/prime.nix
|
2023-06-18 23:36:17 +02:00
|
|
|
|
2024-02-26 11:08:16 +01:00
|
|
|
hardware.opengl.enable = true;
|
|
|
|
hardware.opengl.driSupport = true;
|
|
|
|
hardware.opengl.driSupport32Bit = true;
|
2023-06-18 23:36:17 +02:00
|
|
|
|
2024-02-26 11:08:16 +01:00
|
|
|
nixpkgs.config.openglSupport = true; # why is this not set by hardware.opengl.enable ?
|
2024-03-05 01:41:36 +01:00
|
|
|
nixpkgs.config.cudaSupport = true;
|
2024-02-26 11:08:16 +01:00
|
|
|
nixpkgs.config.vdpauSupport = true;
|
|
|
|
nixpkgs.config.vaapiSupport = true;
|
2024-03-05 01:41:36 +01:00
|
|
|
nixpkgs.config.nvidiaSupport = true;
|
2023-07-04 16:32:09 +02:00
|
|
|
|
2023-06-18 23:36:17 +02:00
|
|
|
nixpkgs.config.allowUnfreePredicate = pkg: lib.any (x: x) [
|
|
|
|
(lib.hasInfix "nvidia" (lib.toLower (lib.getName pkg)))
|
|
|
|
(lib.hasInfix "cuda" (lib.toLower (lib.getName pkg)))
|
|
|
|
(lib.hasInfix "cudnn" (lib.toLower (lib.getName pkg)))
|
|
|
|
(lib.hasInfix "cublas" (lib.toLower (lib.getName pkg)))
|
|
|
|
];
|
|
|
|
|
2024-02-26 11:08:16 +01:00
|
|
|
# https://nixos.wiki/wiki/Nvidia
|
|
|
|
|
2024-02-26 11:03:25 +01:00
|
|
|
hardware.opengl.extraPackages = [
|
2024-02-26 11:08:16 +01:00
|
|
|
#pkgs.vaapiVdpau # added by nixos-hardware
|
2024-02-26 11:03:25 +01:00
|
|
|
#pkgs.libvdpau-va-gl
|
|
|
|
pkgs.nvidia-vaapi-driver
|
2023-06-24 14:48:53 +02:00
|
|
|
];
|
|
|
|
|
2023-06-24 19:11:49 +02:00
|
|
|
hardware.nvidia.modesetting.enable = lib.mkDefault true; # needed for most wayland compositors
|
2023-12-03 20:54:58 +01:00
|
|
|
hardware.nvidia.nvidiaSettings = lib.mkDefault true;
|
2023-06-18 23:36:17 +02:00
|
|
|
|
2023-12-03 20:54:58 +01:00
|
|
|
virtualisation.docker.enableNvidia = lib.mkDefault true;
|
|
|
|
virtualisation.podman.enableNvidia = lib.mkDefault true;
|
2023-07-04 16:32:09 +02:00
|
|
|
|
2024-02-26 11:08:16 +01:00
|
|
|
# only do these per-host
|
2024-02-26 11:03:25 +01:00
|
|
|
|
|
|
|
#hardware.nvidia.open = lib.mkDefault true; # open source version of kernel module, only on driver 515.43.04+
|
|
|
|
#hardware.nvidia.powerManagement.enable = lib.mkDefault true; # Fix graphical corruption on suspend/resume
|
|
|
|
#hardware.nvidia.powerManagement.finegrained = lib.mkDefault false; # Turns off GPU when not in use, Turing or newer
|
|
|
|
|
|
|
|
# https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/os-specific/linux/nvidia-x11/default.nix
|
|
|
|
#hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.stable;
|
|
|
|
#hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.production;
|
|
|
|
#hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.latest;
|
|
|
|
#hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.beta;
|
|
|
|
|
2023-06-18 23:36:17 +02:00
|
|
|
#hardware.nvidia.prime = {
|
|
|
|
# offload.enable = true;
|
|
|
|
# # Bus IDs. You can find them using lspci, grepping for "3D" or "VGA"
|
|
|
|
# intelBusId = "PCI:0:2:0";
|
|
|
|
# nvidiaBusId = "PCI:1:0:0";
|
|
|
|
#};
|
|
|
|
|
2024-02-25 21:26:02 +01:00
|
|
|
environment.systemPackages = [
|
2024-07-04 02:16:29 +02:00
|
|
|
(pkgs.nvtopPackages.nvidia or pkgs.nvtop-nvidia)
|
2023-06-24 19:11:49 +02:00
|
|
|
] ++ lib.optionals config.hardware.nvidia.prime.offload.enable [
|
2024-02-25 21:26:02 +01:00
|
|
|
(pkgs.writeShellScriptBin "prime-run" ''
|
2023-06-18 23:36:17 +02:00
|
|
|
export __NV_PRIME_RENDER_OFFLOAD=1
|
|
|
|
export __NV_PRIME_RENDER_OFFLOAD_PROVIDER=NVIDIA-G0
|
|
|
|
export __GLX_VENDOR_LIBRARY_NAME=nvidia
|
|
|
|
export __VK_LAYER_NV_optimus=NVIDIA_only
|
|
|
|
exec "$@"
|
|
|
|
'')
|
|
|
|
# already added by nixos-hardware.common-gpu-nvidia
|
2024-02-25 21:26:02 +01:00
|
|
|
#(pkgs.writeShellScriptBin "nvidia-offload" ''
|
2023-06-18 23:36:17 +02:00
|
|
|
# export __NV_PRIME_RENDER_OFFLOAD=1
|
|
|
|
# export __NV_PRIME_RENDER_OFFLOAD_PROVIDER=NVIDIA-G0
|
|
|
|
# export __GLX_VENDOR_LIBRARY_NAME=nvidia
|
|
|
|
# export __VK_LAYER_NV_optimus=NVIDIA_only
|
|
|
|
# exec "$@"
|
|
|
|
#'')
|
2024-02-25 21:26:02 +01:00
|
|
|
];
|
2023-12-03 20:54:58 +01:00
|
|
|
|
|
|
|
# nvidia bad
|
|
|
|
nixpkgs.config.packageOverrides = (pkgs: {
|
2024-01-26 01:46:33 +01:00
|
|
|
/** /
|
2023-12-03 20:54:58 +01:00
|
|
|
teams = pkgs.teams.overrideAttrs (old: rec {
|
|
|
|
postInstall = (old.postInstall or "") + ''
|
|
|
|
substituteInPlace $out/share/applications/teams.desktop \
|
|
|
|
--replace 'Exec=teams' 'Exec=teams --use-gl=desktop'
|
|
|
|
'';
|
|
|
|
# --replace 'Exec=teams' 'Exec=teams --disable-gpu'
|
|
|
|
});
|
2024-01-26 01:46:33 +01:00
|
|
|
/**/
|
2023-12-03 20:54:58 +01:00
|
|
|
discord = pkgs.discord.overrideAttrs (old: rec {
|
|
|
|
desktopItem = old.desktopItem.override (old: {
|
|
|
|
#exec = "env NIXOS_OZONE_WL=1 ${old.exec}";
|
|
|
|
exec = "${old.exec} --use-gl=desktop";
|
|
|
|
});
|
|
|
|
postInstall = ''
|
|
|
|
ln -sf "${desktopItem}/share/applications" $out/share/
|
|
|
|
'' + old.postInstall;
|
|
|
|
});
|
2024-01-26 01:46:33 +01:00
|
|
|
/** /
|
2023-12-03 20:54:58 +01:00
|
|
|
slack = pkgs.slack.overrideAttrs (old: {
|
|
|
|
postInstall = old.postInstall or "" + ''
|
|
|
|
substituteInPlace $out/share/applications/slack.desktop \
|
|
|
|
--replace "$out/bin/slack " "$out/bin/slack --use-gl=desktop "
|
|
|
|
'';
|
|
|
|
# --replace "$out/bin/slack " "$out/bin/slack --disable-gpu --in-process-gpu "
|
|
|
|
});
|
|
|
|
element-desktop = pkgs.element-desktop.overrideAttrs (old: {
|
|
|
|
desktopItem = old.desktopItem.override (old: {
|
|
|
|
#exec = "env NIXOS_OZONE_WL=1 element-desktop %u";
|
|
|
|
#exec = "element-desktop --disable-gpu --in-process-gpu %u";
|
|
|
|
exec = "element-desktop --use-gl=desktop %u";
|
|
|
|
});
|
|
|
|
});
|
2024-01-26 01:46:33 +01:00
|
|
|
/**/
|
2023-12-03 20:54:58 +01:00
|
|
|
});
|
2023-06-18 23:36:17 +02:00
|
|
|
}
|