From b96c4a67b9b8438039bb109b88cf03e7429dc27d Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Thu, 21 Nov 2024 15:04:40 +0100 Subject: [PATCH] nixos/frigate: add support for Coral devices --- nixos/modules/services/video/frigate.nix | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/nixos/modules/services/video/frigate.nix b/nixos/modules/services/video/frigate.nix index 72e96df5442e..754c2b00f2c6 100644 --- a/nixos/modules/services/video/frigate.nix +++ b/nixos/modules/services/video/frigate.nix @@ -6,12 +6,17 @@ let inherit (lib) - literalExpression + any + attrValues + hasPrefix + makeLibraryPath mkDefault mkEnableOption mkPackageOption mkIf mkOption + optionalAttrs + optionals types; cfg = config.services.frigate; @@ -94,6 +99,11 @@ let proxy_connect_timeout 360; ''; + # Discover configured detectors for acceleration support + detectors = attrValues cfg.settings.detectors or {}; + withCoralUSB = any (d: d.type == "edgetpu" && hasPrefix "usb" d.device or "") detectors; + withCoralPCI = any (d: d.type == "edgetpu" && hasPrefix "pci" d.device or "") detectors; + withCoral = withCoralPCI || withCoralUSB; in { @@ -492,6 +502,11 @@ in "frigate" ]; + hardware.coral = { + usb.enable = mkDefault withCoralUSB; + pcie.enable = mkDefault withCoralPCI; + }; + users.users.frigate = { isSystemUser = true; group = "frigate"; @@ -510,6 +525,8 @@ in CONFIG_FILE = format.generate "frigate.yml" filteredConfig; HOME = "/var/lib/frigate"; PYTHONPATH = cfg.package.pythonPath; + } // optionalAttrs withCoral { + LD_LIBRARY_PATH = makeLibraryPath (with pkgs; [ libedgetpu ]); }; path = with pkgs; [ # unfree: @@ -530,6 +547,7 @@ in User = "frigate"; Group = "frigate"; + SupplementaryGroups = optionals withCoral [ "coral" ]; UMask = "0027";