VGPU unlock for nixOS 22.11 - Pin version of nixos-hardware?

What?

tldr;
been working in vGPU unlock, current problem (see " Problem?" down there) is that can’t build nvidia driver because build process changed

I’ve been trying to unlock vGPU functionality for my Nvidia NVIDIA GeForce RTX 2060 card in nixOS 22.11.
There is @danielfullmer’s repository that packaged it into a nixOS module that worked in nixOS 21.05 but seemingly not anymore in 22.11.
The previous post about this topic was this one, quoting from there:

For those who do not know, vGPU allows you to share a single host GPU with several virtual machines, effectively allowing for a really nice Windows VM situation for games and such, with near-native performance, without needing to dedicate a separate GPU to Linux!

I’m still new to nix and I’m not convinced that I’ll get this working without any outside help, have been mostly patching @danielfullmer’s repository till it compiles, I don’t expect someone to come and finish the project unless there’s interest in it but I’ll still tag the relevant folk,
So I’ll use this to post updates on where I’m stuck, how it’s going and maybe get some feedback.

Where?

Here is my fork from @danielfullmer’s repository where I’m working: GitHub - Yeshey/nixos-nvidia-vgpu_nixOS: NixOS NVIDIA vGPU Module

I’m using kernel 5.4 to test this, in my configuration I import the module and enable it like this:

  boot.kernelPackages = pkgs.linuxPackages_5_4; # needed for this
  hardware.nvidia = {
    vgpu = {
      enable = true; # Enable NVIDIA KVM vGPU + GRID driver
      unlock.enable = true; # Unlock vGPU functionality on consumer cards using DualCoder/vgpu_unlock project.
    };
  };

Problem?

I’m trying to make the (Merged-driver 460.73.01) *Pre-unlocked and Recommended!* work, got from the Google Docs vGPU Wiki referenced in the main vgpu_unlock repo, this driver should enable still using the GPU for the host machine as well as for a VM.

I’m overriding the src to get directly from the link in google drive, as it is Pre-unlocked it should be fine

  config = lib.mkIf cfg.enable {
    hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.stable.overrideAttrs (
      { patches ? [], postUnpack ? "", postPatch ? "", preFixup ? "", ... }@attrs: {
        # Overriding https://github.com/NixOS/nixpkgs/tree/nixos-unstable/pkgs/os-specific/linux/nvidia-x11
        # that gets called from the option hardware.nvidia.package from here: https://github.com/NixOS/nixpkgs/blob/3e01f83884b8ed7cbafa784727fb343f1876d56f/nixos/modules/hardware/video/nvidia.nix
      name = "nvidia-x11-${vgpuVersion}-${gridVersion}-${config.boot.kernelPackages.kernel.version}";
      version = "${vgpuVersion}";

      src = pkgs.fetchurl {
              url = "https://drive.google.com/u/0/uc?id=1dCyUteA2MqJaemRKqqTu5oed5mINu9Bw&export=download&confirm=t&uuid=3ebfe434-c85f-47e5-9980-6e086fc3e9a3&at=ANzk5s5BlvlXo-X9pbxIkmBd6P2o:1680699478854";
              sha256 = "sha256-C8KM8TwaTYhFx/iYeXTgS9UnNDIbuNtSbGk4UwrRLHE=";
            };
    });

    systemd.services.nvidia-vgpud = {
        ...

But the build process has changed enough for nvidia-x11 so it fails with

error: builder for '/nix/store/9jmj25djaycl2dcc9y6vvg5jzhmpiqx0-nvidia-x11-460.73.01-460.32.03-5.4.231.drv' failed to produce output path for output 'firmware' at '/nix/store/9jmj25djaycl2dcc9y6vvg5jzhmpiqx0-nvidia-x11-460.73.01-460.32.03-5.4.231.drv.chroot/nix/store/6c7cy9iphl3651qhdx9b7qrj8acv7rs9-nvidia-x11-460.73.01-460.32.03-5.4.231-firmware'

This revision should work:
pkgs ? import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/5bba55eb6e1c627dc1821c9132c5854e0870e2f1.tar.gz"){}
or would I have to override nixos-hardware instead, based on the time this revision should work:
hardware-pinned ? import (fetchTarball "https://github.com/NixOS/nixos-hardware/archive/7da029f26849f8696ac49652312c9171bf9eb170.tar.gz"){}
But I’m having trouble having this nix module use that old revision and overriding too

Thanks in advance!

@

@danielfullmer
@starcraft66

My System Info

> nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 5.4.231, NixOS, 22.11 (Raccoon), 22.11.20230219.0cf4274`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.11.1`
 - channels(root): `"nixos-22.11.3459.884e3b68be0, nixpkgs-22.11.3459.884e3b68be0"`
 - channels(yeshey): `""`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`
> nix-shell -p neofetch --run "neofetch"   
          ▗▄▄▄       ▗▄▄▄▄    ▄▄▄▖            yeshey@nixos 
          ▜███▙       ▜███▙  ▟███▛            ------------ 
           ▜███▙       ▜███▙▟███▛             OS: NixOS 22.11.20230219.0cf4274 (Raccoon) x86_64 
            ▜███▙       ▜██████▛              Host: LENOVO LNVNB161216 
     ▟█████████████████▙ ▜████▛     ▟▙        Kernel: 5.4.231 
    ▟███████████████████▙ ▜███▙    ▟██▙       Uptime: 4 hours, 54 mins 
           ▄▄▄▄▖           ▜███▙  ▟███▛       Packages: 1887 (nix-system), 1917 (nix-user), 29 (flatpak) 
          ▟███▛             ▜██▛ ▟███▛        Shell: bash 5.1.16 
         ▟███▛               ▜▛ ▟███▛         Resolution: 1920x1080, 1920x1080 
▟███████████▛                  ▟██████████▙   DE: Plasma 
▜██████████▛                  ▟███████████▛   WM: KWin 
      ▟███▛ ▟▙               ▟███▛            Icons: breeze-dark [GTK2/3] 
     ▟███▛ ▟██▙             ▟███▛             Terminal: .konsole-wrappe 
    ▟███▛  ▜███▙           ▝▀▀▀▀              CPU: Intel i7-9750H (12) @ 2.600GHz 
    ▜██▛    ▜███▙ ▜██████████████████▛        GPU: NVIDIA GeForce RTX 2060 Mobile 
     ▜▛     ▟████▙ ▜████████████████▛         Memory: 8496MiB / 15988MiB 
           ▟██████▙       ▜███▙
          ▟███▛▜███▙       ▜███▙                                      
         ▟███▛  ▜███▙       ▜███▙                                     
         ▝▀▀▀    ▀▀▀▀▘       ▀▀▀▘

I found out that you don’t really need to pin a version of nixpkgs because you can select older versions of the nvidia driver like so:
config.boot.kernelPackages.nvidiaPackages.legacy_470.overrideAttrs for example