Youtube Playback Laggy on NixOS WSL

Hi,

I’m setting up NixOS on WSL. My problem is watching youtube videos in wayland. Initially it was unwatchable, stuttering so badly it skipped about 50% of frames, but I’ve now added the intel drivers to my config, and now it’s better, but still very laggy, skipping lots of frames even at 720p.

I think this should be working using just the intel GPU, but I do also have an NVIDIA GPU, however I haven’t loaded the driver for that. I’m not sure how good the support is for switching between GPUs:

$ clinfo | head -n3
Number of platforms                               1
  Platform Name                                   Intel(R) OpenCL Graphics
  Platform Vendor                                 Intel(R) Corporation

I’m a bit lost when it comes to troubleshooting this issue. I haven’t used Wayland before, and I’m more familar with loading and setting drivers in xorg.conf. Does anyone have any ideas for how to debug this issue?

Here is my configuration.nix for reference, the drivers are set at the end:

{ config, lib, pkgs, ... }:

let
  cpConfig = pkgs.writeScriptBin "cpConfig" ''
    cd ~/nixos-config
    cp /etc/nixos/configuration.nix /home/nixos/nixos-config/configuration.nix
    cd /home/nixos/nixos-config/
    git add configuration.nix
    git commit
    git push
  '';
in
{
  imports = [
    <nixos-wsl/modules>
    <home-manager/nixos>
  ];

  wsl.enable = true;
  wsl.defaultUser = "nixos";

  environment.systemPackages = with pkgs; [
    vim
    oh-my-zsh
    zsh
    zsh-completions
    zsh-powerlevel10k
    zsh-syntax-highlighting
    zsh-history-substring-search
    git
    openssh
    wayland
    wayland-utils
    sway
    xwayland
    alacritty
    firefox
    cpConfig
    jetbrains.idea-community
    jdk
    clinfo
  ];
  environment.variables = {
    GDK_BACKEND = "wayland";
    QT_QPA_PLATFORM = "wayland";
  };
  system.stateVersion = "24.05"; # Did you read the comment?
  users.users.nixos.isNormalUser = true;
  users.users.nixos.shell = pkgs.zsh;
  programs.zsh.enable = true;
  home-manager.users.nixos = { pkgs, ... }: {
    home.stateVersion = "24.05";
    home.username = "nixos";
    programs.zsh = {
      enable = true;
      enableCompletion = true;
      oh-my-zsh = {
        enable = true;
        theme = "avit";  # Set the desired theme here
        plugins = [ "git" "vi-mode" "sudo" "z"];
      };
      shellAliases = {
        ll = "ls -la";
        editConf = "sudo vim /etc/nixos/configuration.nix";
        rebu = "sudo nixos-rebuild switch --upgrade ";
        gd = "git diff";
        gs = "g status";
      };
    };
    programs.vim = {
      enable = true;
      settings = {
        shiftwidth = 2;
        expandtab = true;
        tabstop = 2;
        number = true;
      };
    };
    programs.git = {
      enable = true;
      userName = "user";
      aliases = {
        s = "status";
        d = "diff";
        co = "checkout";
        ci = "commit";
        rb = "!git fetch && git rebase origin/main";
        rbi = "!git fetch && git rebase -i origin/main";
        pr = "!git push --set-upstream origin $(git rev-parse --abbre-ref HEAD)";
        m = "checkout main";
        mp = "!git checkout main && git pull";
        rbc = "!git rebase --continue";
      };
      extraConfig = {
        core = {
          editor = "vim -f";
        };
        color = {
          ui = "auto";
        };
        push = {
          default = "simple";
        };
        pull = {
          rebase = "merges";
        };
      };
    };
    services.ssh-agent = {
      enable = true;
    };
  };
  programs.sway.enable = true;
  hardware.opengl = {
    enable = true;
    driSupport = true;
    driSupport32Bit = true;

    setLdLibraryPath = true;

    extraPackages = with pkgs; [
      intel-compute-runtime
      intel-media-driver
      mesa.drivers
    ];
  };
}