blob: ec60d6238504716a66dc1de30e679d7178c4dffb [file] [log] [blame]
Skyler Grey6ec7b412023-01-26 00:38:49 +00001{ pkgs, lib, username, ... }:
Skyler Greyf2335ec2022-11-02 08:10:50 +00002let
3 prime-run = pkgs.writeScriptBin "prime-run" ''
4 export __NV_PRIME_RENDER_OFFLOAD=1
5 export __NV_PRIME_RENDER_OFFLOAD_PROVIDER=NVIDIA-G0
6 export __GLX_VENDOR_LIBRARY_NAME=nvidia
7 export __VK_LAYER_NV_optimus=NVIDIA_only
8 exec "$@"
9 '';
10in
11{
12 config = {
Skyler Greya1683e32022-11-03 08:05:34 +000013 services.xserver.videoDrivers = [ "nvidia" ];
Skyler Greyf2335ec2022-11-02 08:10:50 +000014 hardware = {
15 opengl.enable = true;
16 nvidia = {
17 modesetting.enable = true;
Skyler Grey6ec7b412023-01-26 00:38:49 +000018 powerManagement.enable = true;
Skyler Greyf2335ec2022-11-02 08:10:50 +000019 prime = {
20 offload.enable = true;
21 intelBusId = "PCI:0:2:0";
22 nvidiaBusId = "PCI:1:0:0";
23 };
24 };
25 };
Skyler Grey6ec7b412023-01-26 00:38:49 +000026
27 specialisation.nvidia-sync.configuration = {
28 system.nixos.tags = [ "nvidia-sync" ];
29 hardware.nvidia.powerManagement.enable = lib.mkForce false;
30 hardware.nvidia.prime.offload.enable = lib.mkForce false;
31 hardware.nvidia.prime.sync.enable = lib.mkForce true;
32 services.xserver.dpi = 96;
33
34 home-manager.users.${username}.home.file.".xinitrc".text = lib.mkBefore ''
35 ${pkgs.xorg.xrandr}/bin/xrandr --setprovideroutputsource modesetting NVIDIA-0
36 ${pkgs.xorg.xrandr}/bin/xrandr --output HDMI-0 --primary --mode 3840x2160 --pos 0x0 --rotate normal --output eDP-1-1 --mode 1920x1080 --pos 960x2160 --rotate normal
37 '';
38 };
39
Skyler Greyf2335ec2022-11-02 08:10:50 +000040 internal.allowUnfree = [ "nvidia-x11" "nvidia-settings" "cudatoolkit" ];
41 };
42 home.home.packages = [ pkgs.nvtop prime-run ];
43}