summaryrefslogtreecommitdiffstats
path: root/nixos/modules/services/video
diff options
context:
space:
mode:
authorMax Niederman <max@maxniederman.com>2024-02-05 23:43:41 -0800
committerMax Niederman <max@maxniederman.com>2024-03-07 14:59:20 -0800
commit3609e216a438192a6caf27f20f4c5124c91d83da (patch)
tree2ebd431222a9d07941eb07be179936384b6defc4 /nixos/modules/services/video
parentf8e85512ed6b9647ac11cb6fa20c6cdf2c63ecd2 (diff)
nixos/photonvision: init module
Diffstat (limited to 'nixos/modules/services/video')
-rw-r--r--nixos/modules/services/video/photonvision.nix64
1 files changed, 64 insertions, 0 deletions
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; }];
+ };
+ };
+}