Hassleless Droidcam v4l2loopback Config

@MeshVoid we gone and done it (mostly)!

Background

My situation is a little different from most people here. I use iOS and and an old, very old, AMD GPU. Specifically a AMD Radeon R9 290X. However, I suspect the solution may still be useful to others.

Solution

After reading @MeshVoid’s implementation I decided to take a look at the values available to services.xserver.videoDrivers. I noticed that one of them was ati witch I remembered from back in the day when I build my machine. After switching from amdgpu to ati, rebuilding, and rebooting, v4l2loopback device worked! I no longer had to run v4l2loopback-ctl set-caps /dev/video<n> "YU12:<width>x<height>" after each reboot.

Lessens Learned

I think the most common cause of this issue is GPU driver related, so look there first.

Problem(s)

After changing GPU driver Steam takes a loooooong time to start. Once it does, it launches in the background and gives an error popup saying steamwebhelper, a critical Steam component, is not responding. The Steam UI will not be usable. Click here for more information.. Although Steam still works, it’s annoying how long it takes to launch.

I passed in -vgui when launching it (ex. com.valvesoftware.Steam -vgui) as suggested here, but to no avail. I also turned off GPU acceleration in Steam settings, as well as hardware acceleration.

Finally, I removed the Steam flatpak, deleted all local data (ran flatpak uninstall --unused --delete-data, sudo flatpak repair, and flatpak repair), and reinstalled it. Needless to say, this also didn’t work.

To be clear, Steam works just fine, other than the six and a half years it takes to launch. If anyone has any ideas, I’m all ears.

My Configuration

Generic GPU Configuration

{ user, ... }: {
  programs.corectrl = {
    enable = true;
    gpuOverclock.enable = true;
  };

  users.users."${user.name}".extraGroups = [ "corectrl" ];
}

v4l2loopback Configuration

{ config, pkgs, ... }: {
  environment.systemPackages = with pkgs; [
    # Enables v4l2loopback GUI utilities.
    v4l-utils
  ];

  boot = {
    # Make v4l2loopback kernel module available to NixOS.
    extraModulePackages = with config.boot.kernelPackages; [
      v4l2loopback
    ];
    # Activate kernel module(s).
    kernelModules = [
      # Virtual camera.
      "v4l2loopback"
      # Virtual Microphone. Custom DroidCam v4l2loopback driver needed for audio.
#    "snd-aloop"
    ];
  };
}

Host Machine Specific Hardware Configuration

{ config, lib, pkgs, modulesPath, ... }: {
  boot.initrd.availableKernelModules = [ "ahci" "ohci_pci" "ehci_pci" "pata_atiixp" "xhci_pci" "firewire_ohci" "usb_storage" "usbhid" "sd_mod" "sr_mod" ];
  boot.kernelModules = [ "kvm-amd" ];

  hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
}

GPU Specific Configuration

{ pkgs, ... }: {
  boot = {
    initrd.kernelModules = [ "amdgpu" ];
    # Enable support for my old ass AMD ATI R9 290X GPU.
    kernelParams = [ "radeon.cik_support=0" "amdgpu.cik_support=1" ];
  };

 hardware.opengl.extraPackages = [ pkgs.amdvlk ];

  # Enable GPU hardware acceleration.
  # Note(s):
  #   - This doesn't turn x11 on.
  #   - This is used even when running under Wayland.
  #   - `amdgpu` also works, but it breaks v4l2loopback and seems to perform worse.
  services.xserver.videoDrivers = [ "ati" ];
}

Note(s)

  • @MeshVoid I’m as sure as I can be that there’s no need to open ports.
  • For anyone wondering, an option being under xserver doesn’t mean it won’t work or doesn’t apply when running under Wayland.
  • I needed no changes to support iOS via USB because I’m using WiFi.
  • @zaiquiriw I would pay special attention to what video drivers you’re loading. Feel free to post GPU info here as well as your current configuration of boot.extraModulePackages, boot.kernelModules, boot.initrd.kernelModules, boot.kernelParams, and services.xserver.videoDrivers.
2 Likes