Hi, I’m an Arch Linux user and recently I wanted to try out NixOS. I have an Nvidia Optimus laptop (Dell XPS 15 9570) with a GTX 1050 Ti. When I was using Arch I could fully disable/reenable the GPU without the need to reboot or log out by following [the instructions on the Arch Wiki].(Dell XPS 15 (9570) - ArchWiki).
I’ve tried to replicate that setup on NixOS, here’s what I added to my configuration.nix
file:
hardware.opengl = {
enable = true;
driSupport = true;
driSupport32Bit = true;
};
nixpkgs.config.allowUnfreePredicate = pkg:
builtins.elem (lib.getName pkg) [
"nvidia-x11"
"nvidia-settings"
];
services.xserver.videoDrivers = lib.mkDefault ["intel" "nvidia"];
hardware.nvidia = {
modesetting.enable = true;
nvidiaSettings = true;
};
hardware.nvidia.prime = {
offload = {
enable = true;
enableOffloadCmd = true;
};
intelBusId = "PCI:0:2:0";
nvidiaBusId = "PCI:1:0:0";
};
boot.blacklistedKernelModules = [
"nouveau"
"nv"
"rivafb"
"nvidiafb"
"rivatv"
"nvidia"
"nvidia-drm"
"nvidia-modeset"
"nvidia-uvm"
"ipmi_msghandler"
"ipmi_devintf"
];
systemd.services.disable-nvidia-on-shutdown = {
enable = true;
description = "Disables Nvidia GPU on OS shutdown";
unitConfig = {
Type = "oneshot";
RemainAfterExit = true;
};
serviceConfig = {
ExecStart = "${pkgs.coreutils}/bin/true";
ExecStop =
''
/bin/sh -c "mv /etc/modprobe.d/disable-nvidia.conf.disable /etc/modprobe.d/disable-nvidia.conf || true"
'';
};
wantedBy = ["multi-user.target"];
};
I’ve also created the /etc/modprobe.d/disable-nvidia.conf
file as in the Arch wiki, since I don’t know how to do it the “Nix” way yet.
My laptop boots up without the Nvidia GPU running - lsmod | grep nvidia
returns nothing and its power usage is low. I can turn the GPU on by using the enableGPU.sh
script from the Arch Wiki (its fans start spinning) but lsmod | grep nvidia
returns nothing. I can also turn the GPU off accordingly. When the GPU is turned on, the nvidia-offload
script from the NixOS Wiki doesn’t do anything. None of my programs can see the Nvidia GPU (I’ve tried Blender, glxinfo, and Dolphin Emulator).
How should I do this properly?