How to hide this dummy video device?

To enable a webcam with MIPI, I needed to use the configuration below (see details in Tracking Issue: Intel MIPI/IPU6 webcam-support · Issue #225743 · NixOS/nixpkgs · GitHub). While it works great, it also create a dummy video device that is not useful called “Dummy video device”, on top of the main Intel MIPI (and some others, but they only appear in obs, so not so much an issue):

image

Do you know how to get rid of it, or at least not to take it as the default one? The software takes by default the dummy one, which fails.

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

let
  ivsc-firmware = with pkgs;
    stdenv.mkDerivation rec {
      pname = "ivsc-firmware";
      version = "main";

      src = pkgs.fetchFromGitHub {
        owner = "intel";
        repo = "ivsc-firmware";
        rev = "10c214fea5560060d387fbd2fb8a1af329cb6232";
        sha256 = "sha256-kEoA0yeGXuuB+jlMIhNm+SBljH+Ru7zt3PzGb+EPBPw=";

      };

      installPhase = ''
        mkdir -p $out/lib/firmware/vsc/soc_a1_prod

        cp firmware/ivsc_pkg_ovti01a0_0.bin $out/lib/firmware/vsc/soc_a1_prod/ivsc_pkg_ovti01a0_0_a1_prod.bin
        cp firmware/ivsc_skucfg_ovti01a0_0_1.bin $out/lib/firmware/vsc/soc_a1_prod/ivsc_skucfg_ovti01a0_0_1_a1_prod.bin
        cp firmware/ivsc_fw.bin $out/lib/firmware/vsc/soc_a1_prod/ivsc_fw_a1_prod.bin
      '';
    };
in
{
  # Load also non-free firmwares in the kernel
  hardware.enableRedistributableFirmware = lib.mkDefault true;

  # for sake of ipu6-camera-bins
  nixpkgs.config.allowUnfree = true;

  environment.systemPackages = with pkgs; [
    # https://discourse.nixos.org/t/v4l2loopback-cannot-find-module/26301/5
    v4l-utils
  ];

  boot.initrd.availableKernelModules = [ "xhci_pci" "thunderbolt" "nvme" "usb_storage" "usbhid" "sd_mod" "i915" ];
  boot.initrd.kernelModules = [];
  boot.kernelModules = [ "kvm-intel" ];
 
  boot.extraModulePackages = [];

  # https://discourse.nixos.org/t/i915-driver-has-bug-for-iris-xe-graphics/25006/10
  # resolved: i915 0000:00:02.0: [drm] Selective fetch area calculation failed in pipe A
  boot.kernelParams = [
    "i915.enable_psr=0"
  ];

  hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;

  # Tracking Issue: Intel MIPI/IPU6 webcam-support
  # https://github.com/NixOS/nixpkgs/issues/225743#issuecomment-1849613797
  # Infrastructure Processing Unit
  hardware.ipu6 = {
    enable = true;
    platform = "ipu6ep";
  };

  hardware.firmware = [
    ivsc-firmware
  ];

  # environment.etc.camera.source = "${ipu6-camera-hal}/share/defaults/etc/camera";
}

I have the following in my config, which is doing something similar for opposite purposes (more write-up at the commented link). Perhaps you can adapt it?

  boot.kernelModules = [ "v4l2loopback" ];
  boot.extraModulePackages = [ pkgs.linuxPackages.v4l2loopback ];
  # hide real cams from chromium because uggh.  From: https://www.scs.stanford.edu/~dm/blog/hide-webcam.html
  boot.extraModprobeConfig = "options v4l2loopback nr_devices=2 exclusive_caps=1,1,1,1,1,1,1,1 video_nr=0,1 card_label=v4l2lo0,v4l2lo1";
  services.udev.extraRules = ''
    SUBSYSTEM!="video4linux", GOTO="hide_cam_end"
    ATTR{name}=="v4l2lo[0-9]", GOTO="hide_cam_end"

    ACTION=="add", RUN+="${pkgs.coreutils}/bin/mkdir -p /dev/obs-only"
    ACTION=="add", RUN+="${pkgs.coreutils}/bin/mv -f $env{DEVNAME} /dev/obs-only/"
    ACTION=="add", ATTR{index}=="0", RUN+="${pkgs.coreutils}/bin/ln -fs $name /dev/obs-only/$env{ID_SERIAL}"

    ACTION=="remove", RUN+="${pkgs.coreutils}/bin/rm -f /dev/obs-only/$name"
    ACTION=="remove", RUN+="${pkgs.coreutils}/bin/rm -f /dev/obs-only/$env{ID_SERIAL}"

    LABEL="hide_cam_end"
  '';

However, perhaps you can also just not load the v4l2loopback module, if you don’t want it.

1 Like

Thanks a lot I’ll try! But what do you mean exactly:

What do you mean? I don’t even know how it is loaded ^^’ And I guess I can’t disable it completely as the other webcam seems to also use v4l2loopback (MIPI is a bit special as I understand)

It looks (on more careful reading of your screenshot) like the module is maybe being pulled in as a dependency and is used to create the MIPI camera instance, as well as a default one. Ok.

So maybe you can experiment with that nr_devices setting to avoid creating the default one? Otherwise, renaming it out of the way might be “good enough”.

So changing nr_devices was not doing anything visible… but I managed to change the udev rules to make it work!

  services.udev.extraRules = ''
    # If the system is not a video device, we skip these rules by jumping to the end
    SUBSYSTEM!="video4linux", GOTO="hide_cam_end"
    #ATTR{name}=="Intel MIPI Camera", GOTO="hide_cam_end" # This line cannot be used as it would move too much stuff and then the camera would not work. Instead, we just move the dummy camera,
    # I found its name with udevadm info -q all -a /dev/video0
    # If this is not the dummy video, we also skip these rules.
    ATTR{name}!="Dummy video device (0x0000)", GOTO="hide_cam_end"
    ACTION=="add", RUN+="${pkgs.coreutils}/bin/mkdir -p /dev/not-for-user"
    ACTION=="add", RUN+="${pkgs.coreutils}/bin/mv -f $env{DEVNAME} /dev/not-for-user/"

    ACTION=="remove", RUN+="${pkgs.coreutils}/bin/rm -f /dev/not-for-user/$name"
    ACTION=="remove", RUN+="${pkgs.coreutils}/bin/rm -f /dev/not-for-user/$env{ID_SERIAL}"

    LABEL="hide_cam_end"
  '';

Thanks a lot!

1 Like