From f8e85512ed6b9647ac11cb6fa20c6cdf2c63ecd2 Mon Sep 17 00:00:00 2001 From: Max Niederman Date: Mon, 5 Feb 2024 23:21:34 -0800 Subject: [PATCH 1/3] photonvision: init at 2024.2.3 --- pkgs/by-name/ph/photonvision/package.nix | 50 ++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 pkgs/by-name/ph/photonvision/package.nix diff --git a/pkgs/by-name/ph/photonvision/package.nix b/pkgs/by-name/ph/photonvision/package.nix new file mode 100644 index 000000000000..6a6f4cc14b18 --- /dev/null +++ b/pkgs/by-name/ph/photonvision/package.nix @@ -0,0 +1,50 @@ +{ lib +, stdenv +, fetchurl +, makeWrapper +, temurin-jre-bin-11 +, bash +, suitesparse +}: + +stdenv.mkDerivation rec { + pname = "photonvision"; + version = "2024.2.3"; + + src = { + "x86_64-linux" = fetchurl { + url = "https://github.com/PhotonVision/photonvision/releases/download/v${version}/photonvision-v${version}-linuxx64.jar"; + hash = "sha256-45ae9sElAmN6++F9OGAvY/nUl/9UxvHtFxhetKVKfDc="; + }; + "aarch64-linux" = fetchurl { + url = "https://github.com/PhotonVision/photonvision/releases/download/v${version}/photonvision-v${version}-linuxarm64.jar"; + hash = "sha256-i/osKO+RAg2nFUPjBdkn3q0Id+uCSTiucfKFVVlEqgs="; + }; + }.${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}"); + + dontUnpack = true; + + nativeBuildInputs = [ makeWrapper ]; + + installPhase = '' + runHook preInstall + + install -D $src $out/lib/photonvision.jar + + makeWrapper ${temurin-jre-bin-11}/bin/java $out/bin/photonvision \ + --prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath [ stdenv.cc.cc.lib suitesparse ]} \ + --prefix PATH : ${lib.makeBinPath [ temurin-jre-bin-11 bash.out ]} \ + --add-flags "-jar $out/lib/photonvision.jar" + + runHook postInstall + ''; + + meta = with lib; { + description = "The free, fast, and easy-to-use computer vision solution for the FIRST Robotics Competition"; + homepage = "https://photonvision.org/"; + license = licenses.gpl3; + maintainers = with maintainers; [ max-niederman ]; + mainProgram = "photonvision"; + platforms = [ "x86_64-linux" "aarch64-linux" ]; + }; +} From 3609e216a438192a6caf27f20f4c5124c91d83da Mon Sep 17 00:00:00 2001 From: Max Niederman Date: Mon, 5 Feb 2024 23:43:41 -0800 Subject: [PATCH 2/3] nixos/photonvision: init module --- .../manual/release-notes/rl-2405.section.md | 2 + nixos/modules/module-list.nix | 1 + nixos/modules/services/video/photonvision.nix | 64 +++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 nixos/modules/services/video/photonvision.nix diff --git a/nixos/doc/manual/release-notes/rl-2405.section.md b/nixos/doc/manual/release-notes/rl-2405.section.md index bad1fd449bbb..e838edea228a 100644 --- a/nixos/doc/manual/release-notes/rl-2405.section.md +++ b/nixos/doc/manual/release-notes/rl-2405.section.md @@ -42,6 +42,8 @@ In addition to numerous new and upgraded packages, this release has the followin - [Guix](https://guix.gnu.org), a functional package manager inspired by Nix. Available as [services.guix](#opt-services.guix.enable). +- [PhotonVision](https://photonvision.org/), a free, fast, and easy-to-use computer vision solution for the FIRSTĀ® Robotics Competition. + - [pyLoad](https://pyload.net/), a FOSS download manager written in Python. Available as [services.pyload](#opt-services.pyload.enable) - [maubot](https://github.com/maubot/maubot), a plugin-based Matrix bot framework. Available as [services.maubot](#opt-services.maubot.enable). diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index b64a3360701a..3ee4fb2be195 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -1259,6 +1259,7 @@ ./services/video/go2rtc/default.nix ./services/video/frigate.nix ./services/video/mirakurun.nix + ./services/video/photonvision.nix ./services/video/replay-sorcery.nix ./services/video/mediamtx.nix ./services/video/unifi-video.nix diff --git a/nixos/modules/services/video/photonvision.nix b/nixos/modules/services/video/photonvision.nix new file mode 100644 index 000000000000..fdbe9da3999d --- /dev/null +++ b/nixos/modules/services/video/photonvision.nix @@ -0,0 +1,64 @@ +{ config, pkgs, lib, ... }: + +let + cfg = config.services.photonvision; +in +{ + options = { + services.photonvision = { + enable = lib.mkEnableOption (lib.mdDoc "Enable PhotonVision"); + + package = lib.mkPackageOption pkgs "photonvision" {}; + + openFirewall = lib.mkOption { + description = lib.mdDoc '' + Whether to open the required ports in the firewall. + ''; + default = false; + type = lib.types.bool; + }; + }; + }; + + config = lib.mkIf cfg.enable { + systemd.services.photonvision = { + description = "PhotonVision, the free, fast, and easy-to-use computer vision solution for the FIRST Robotics Competition"; + + wantedBy = [ "multi-user.target" ]; + after = [ "network.target" ]; + + serviceConfig = { + ExecStart = lib.getExe cfg.package; + + # ephemeral root directory + RuntimeDirectory = "photonvision"; + RootDirectory = "/run/photonvision"; + + # setup persistent state and logs directories + StateDirectory = "photonvision"; + LogsDirectory = "photonvision"; + + BindReadOnlyPaths = [ + # mount the nix store read-only + "/nix/store" + + # the JRE reads the user.home property from /etc/passwd + "/etc/passwd" + ]; + BindPaths = [ + # mount the configuration and logs directories to the host + "/var/lib/photonvision:/photonvision_config" + "/var/log/photonvision:/photonvision_config/logs" + ]; + + # for PhotonVision's dynamic libraries, which it writes to /tmp + PrivateTmp = true; + }; + }; + + networking.firewall = lib.mkIf cfg.openFirewall { + allowedTCPPorts = [ 5800 ]; + allowedTCPPortRanges = [{ from = 1180; to = 1190; }]; + }; + }; +} From ea7101783c474ba072fa565e3ecc0e5c530ef61b Mon Sep 17 00:00:00 2001 From: Max Niederman Date: Mon, 5 Feb 2024 23:51:17 -0800 Subject: [PATCH 3/3] nixos/tests/photonvision: init --- nixos/tests/all-tests.nix | 1 + nixos/tests/photonvision.nix | 21 +++++++++++++++++++++ pkgs/by-name/ph/photonvision/package.nix | 5 +++++ 3 files changed, 27 insertions(+) create mode 100644 nixos/tests/photonvision.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index c2114098fe05..94d4e95bc031 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -679,6 +679,7 @@ in { pgjwt = handleTest ./pgjwt.nix {}; pgmanage = handleTest ./pgmanage.nix {}; phosh = handleTest ./phosh.nix {}; + photonvision = handleTest ./photonvision.nix {}; photoprism = handleTest ./photoprism.nix {}; php = handleTest ./php {}; php81 = handleTest ./php { php = pkgs.php81; }; diff --git a/nixos/tests/photonvision.nix b/nixos/tests/photonvision.nix new file mode 100644 index 000000000000..2cadaa4bc02e --- /dev/null +++ b/nixos/tests/photonvision.nix @@ -0,0 +1,21 @@ +import ./make-test-python.nix ({ pkgs, lib, ... }: +{ + name = "photonvision"; + + nodes = { + machine = { pkgs, ... }: { + services.photonvision = { + enable = true; + }; + }; + }; + + testScript = '' + start_all() + machine.wait_for_unit("photonvision.service") + machine.wait_for_open_port(5800) + ''; + + meta.maintainers = with lib.maintainers; [ max-niederman ]; +}) + diff --git a/pkgs/by-name/ph/photonvision/package.nix b/pkgs/by-name/ph/photonvision/package.nix index 6a6f4cc14b18..e36f5393bbbf 100644 --- a/pkgs/by-name/ph/photonvision/package.nix +++ b/pkgs/by-name/ph/photonvision/package.nix @@ -5,6 +5,7 @@ , temurin-jre-bin-11 , bash , suitesparse +, nixosTests }: stdenv.mkDerivation rec { @@ -39,6 +40,10 @@ stdenv.mkDerivation rec { runHook postInstall ''; + passthru.tests = { + starts-web-server = nixosTests.photonvision; + }; + meta = with lib; { description = "The free, fast, and easy-to-use computer vision solution for the FIRST Robotics Competition"; homepage = "https://photonvision.org/";