From 164ac293da8997589738b8c2a653a2a0edd80639 Mon Sep 17 00:00:00 2001 From: File Magic Date: Tue, 28 Jul 2026 18:07:23 -0400 Subject: [PATCH] modules/fujifilm-webcam.nix: add gphoto2 + v4l2loopback + ffmpeg camera-as-webcam module --- modules/fujifilm-webcam.nix | 45 +++++++++++++++++++++++++++++++++++++ modules/hardened.nix | 1 + 2 files changed, 46 insertions(+) create mode 100644 modules/fujifilm-webcam.nix diff --git a/modules/fujifilm-webcam.nix b/modules/fujifilm-webcam.nix new file mode 100644 index 0000000..d052362 --- /dev/null +++ b/modules/fujifilm-webcam.nix @@ -0,0 +1,45 @@ +{ + lib, + pkgs, + config, + ... +}: let + cfg = config.hardened.fujifilm-webcam; +in { + options.hardened.fujifilm-webcam = { + enable = lib.mkEnableOption "Fujifilm camera as webcam (gphoto2 + v4l2loopback + ffmpeg)"; + + videoDevice = lib.mkOption { + type = lib.types.str; + default = "/dev/video2"; + description = "Virtual video device to write the camera feed to"; + }; + }; + + config = lib.mkIf cfg.enable { + boot.kernelModules = ["v4l2loopback"]; + boot.extraModulePackages = [pkgs.v4l2loopback]; + boot.extraModprobeConfig = '' + options v4l2loopback exclusive_caps=1 max_buffers=2 + ''; + + environment.systemPackages = with pkgs; [ + gphoto2 + ffmpeg + v4l2loopback + ]; + + systemd.services.fujifilm-webcam = { + description = "Fujifilm camera as webcam via gphoto2 + ffmpeg"; + wantedBy = ["multi-user.target"]; + after = ["dev-video2.device" "systemd-modules-load.service"]; + wants = ["dev-video2.device"]; + serviceConfig = { + ExecStart = "${pkgs.bash}/bin/bash -c '${pkgs.gphoto2}/bin/gphoto2 --stdout --capture-movie | ${pkgs.ffmpeg}/bin/ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 ${cfg.videoDevice}'"; + User = "root"; + Restart = "on-failure"; + RestartSec = "5s"; + }; + }; + }; +} diff --git a/modules/hardened.nix b/modules/hardened.nix index 8cb31a6..62fa8bd 100644 --- a/modules/hardened.nix +++ b/modules/hardened.nix @@ -23,5 +23,6 @@ in { ./apparmor.nix ./agenix.nix ./user.nix + ./fujifilm-webcam.nix ]; } -- 2.51.2