From 1c07d92099551535ed7f74d64c87aca4a6c6514b Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Fri, 22 Nov 2024 03:12:50 +0100 Subject: [PATCH] nixos/frigate: allow configuring a libva driver In my testing this helped steer VA-API towards the correct card and also made it show GPU statistics in performance monitoring. --- nixos/modules/services/video/frigate.nix | 25 ++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/nixos/modules/services/video/frigate.nix b/nixos/modules/services/video/frigate.nix index f04aed08f99a1..bc0f5d496afb8 100644 --- a/nixos/modules/services/video/frigate.nix +++ b/nixos/modules/services/video/frigate.nix @@ -132,6 +132,27 @@ in ''; }; + vaapiDriver = mkOption { + type = nullOr (enum [ "i965" "iHD" "nouveau" "vdpau" "nvidia" "radeonsi" ]); + default = null; + example = "radeonsi"; + description = '' + Force usage of a particular VA-API driver for video acceleration. Use together with `settings.ffmpeg.hwaccel_args`. + + Setting this *is not required* for VA-API to work, but it can help steer VA-API towards the correct card if you have multiple. + + :::{.note} + For VA-API to work you must enable {option}`hardware.graphics.enable` (sufficient for AMDGPU) and pass for example + `pkgs.intel-media-driver` (required for Intel 5th Gen. and newer) into {option}`hardware.graphics.extraPackages`. + ::: + + See also: + + - https://docs.frigate.video/configuration/hardware_acceleration + - https://docs.frigate.video/configuration/ffmpeg_presets#hwaccel-presets + ''; + }; + settings = mkOption { type = submodule { freeformType = format.type; @@ -542,6 +563,8 @@ in CONFIG_FILE = format.generate "frigate.yml" filteredConfig; HOME = "/var/lib/frigate"; PYTHONPATH = cfg.package.pythonPath; + } // optionalAttrs (cfg.vaapiDriver != null) { + LIBVA_DRIVER_NAME = cfg.vaapiDriver; } // optionalAttrs withCoral { LD_LIBRARY_PATH = makeLibraryPath (with pkgs; [ libedgetpu ]); }; @@ -568,6 +591,8 @@ in Group = "frigate"; SupplementaryGroups = [ "render" ] ++ optionals withCoral [ "coral" ]; + AmbientCapabilities = optionals (elem cfg.vaapiDriver [ "i965" "iHD" ]) [ "CAP_PERFMON" ]; # for intel_gpu_top + UMask = "0027"; StateDirectory = "frigate";