diff --git a/objectifier-module.nix b/objectifier-module.nix index ec739fc..685f3e9 100644 --- a/objectifier-module.nix +++ b/objectifier-module.nix @@ -57,15 +57,6 @@ in { after = [ "network-online.target" ]; wantedBy = [ "multi-user.target" ]; reloadIfChanged = true; - path = with pkgs.python310Packages; [ - pkgs.python310 - gunicorn - fastapi - gunicorn - opencv4 - python-multipart - uvicorn - ]; environment = { OBJECTIFIER_YOLOV3_CONFIG = "${pkgs.yolov3-data}/yolov3.cfg"; OBJECTIFIER_YOLOV3_WEIGHTS = "${pkgs.yolov3-data}/yolov3.weights"; @@ -74,6 +65,7 @@ in { OBJECTIFIER_CLEANUP_MAX_AGE = toString cfg.cleanup.max_file_age; OBJECTIFIER_CLEANUP_DELAY = toString cfg.cleanup.delay; }; + path = [ pkgs.objectifier ]; serviceConfig = { # PrivateUsers = true; # PrivateDevices = true; @@ -103,12 +95,10 @@ in { (map (addr: "--bind ${addr}:${toString cfg.port}") cfg.listen-addresses); in (concatStringsSep " " [ - "gunicorn" + "objectifier" bindClause "--workers ${toString cfg.workers}" - "-k uvicorn.workers.UvicornWorker" "--pid /run/objectifier.pid" - "objectifier:app" ]); }; }; diff --git a/objectifier.nix b/objectifier.nix index 2004d74..c26d8ed 100644 --- a/objectifier.nix +++ b/objectifier.nix @@ -1,12 +1,33 @@ { pkgs, lib, ... }: -pkgs.stdenv.mkDerivation { +let + objectifier-src = pkgs.stdenv.mkDerivation { + name = "objectifier"; + src = ./src; + phases = [ "installPhase" ]; + installPhase = '' + mkdir -p $out + cp $src/detector.py $out/detector.py + cp $src/yolo-cli.py $out/objectifier.py + ''; + }; + + pythonYolo = pkgs.python3.withPackages (pyPkgs: + with pyPkgs; [ + gunicorn + fastapi + gunicorn + opencv4 + python-multipart + uvicorn + ]); +in pkgs.writeShellApplication { name = "objectifier"; - src = ./src; - phases = [ "installPhase" ]; - installPhase = '' - mkdir -p $out - cp $src/detector.py $out/detector.py - cp $src/yolo-cli.py $out/objectifier.py - ''; + runtimeInputs = [ pythonYolo ]; + text = pkgs.lib.concatStringsSep " " [ + "gunicorn" + "objectifier:app" + "-k uvicorn.workers.UvicornWorker" + ''"$@"'' + ]; }