{ description = "A Nix Flake for Cyanovision Project"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs"; flake-utils.url = "github:numtide/flake-utils"; jupyterWith.url = "github:tweag/jupyterWith"; mach-nix.url = "mach-nix/3.5.0"; }; outputs = { self, nixpkgs, jupyterWith, mach-nix, flake-utils, ... } @ inputs: flake-utils.lib.eachSystem ["x86_64-linux" "aarch64-linux"] (system: let pkgs = import nixpkgs { system = system; overlays = nixpkgs.lib.attrValues jupyterWith.overlays; }; machNix = mach-nix.lib."${system}"; iPython = pkgs.kernels.iPythonWith { name = cyanovision.name; packages = p: with p; [sympy numpy]; ignoreCollisions = true; }; jupyterEnvironment = pkgs.jupyterlabWith { kernels = [iPython]; }; cyanovision = { name = "cyanovision"; src = pkgs.fetchFromGitHub { owner = "IoannouPanayiotis"; repo = "Sensor-CDT-Team-Challenge-2021-2022"; rev = "fd7e538b8afc2227a1100bdd42903b282fcf46bb"; sha256 = "sha256-e4kEuvH3my4gzOhP9zWCWSUOYokJJ7JBRXSpeMQkkp0="; }; packagesExtra = with pkgs; [ bash libusb1 libsndfile ]; pythonPackages = with pkgs.python310Packages; [ matplotlib numpy pathlib2 pillow pycocotools tensorflow tkinter ]; packages = { tflite-model-maker = machNix.buildPythonPackage { src = builtins.fetchGit { url = "https://github.com/tensorflow/examples/tree/master/tensorflow_examples/lite/model_maker"; ref = "master"; rev = "32b080729d0a995fc06c3df4441d685ff1ca3e55"; }; extras = ["grpc" "libsndfile"]; }; cyanovision-ui = pkgs.python3Packages.buildPythonApplication rec { pname = "${cyanovision.name}-ui"; version = "2022"; src = cyanovision.src; propagatedBuildInputs = cyanovision.packagesExtra; pythonPath = cyanovision.pythonPackages; format = "other"; doCheck = false; postPatch = '' sed -i '1 i #!/bin/python3' Cyanovision\ UI/cyanovision_ui.py ''; installPhase = '' mkdir -p $out/bin \ $out/share/applications/${pname}/images \ $out/lib/${pkgs.python3.libPrefix}/site-packages cp Cyanovision\ UI/cyanovision_ui.py $out/bin/${pname} cp Cyanovision\ UI/*.png $out/share/applications/${pname}/images cp Cyanovision\ UI/object_detection_train.py \ $out/lib/${pkgs.python3.libPrefix}/site-packages ''; preFixup = '' substituteInPlace $out/bin/${pname} \ --replace "sensors_cdt_logo.png" "$out/share/applications/${pname}/images/sensors_cdt_logo.png" \ --replace "cyanovision_logo.png" "$out/share/applications/${pname}/images/cyanovision_logo.png" chmod +x $out/bin/${pname} patchShebangs --host $out/bin/${pname} ''; }; cyanovision-model = pkgs.stdenv.mkDerivation { name = cyanovision.name + "-model"; src = cyanovision.src; installPhase = '' mkdir -p $out/share/applications/${cyanovision.name}/model cp -R Trained\ Object\ Detection\ Model/*.tflite \ $out/share/applications/${cyanovision.name}/model ''; doCheck = false; }; cyanovision-dataset = pkgs.stdenv.mkDerivation { name = cyanovision.name + "-dataset"; src = cyanovision.src; installPhase = '' mkdir -p $out/share/applications/${cyanovision.name}/dataset cp -R Cyanovision\ UI/dataset \ $out/share/applications/${cyanovision.name}/dataset ''; doCheck = false; }; }; }; python-venv = machNix.mkPython { packagesExtra = cyanovision.packagesExtra; requirements = '' tensorflow # tflite-model-maker==0.3.2 ''; providers.tensorflow = "nixpkgs"; _.pytest-cov.propagatedBuildInputs.mod = pySelf: self: oldVal: oldVal ++ [pySelf.tomli]; }; in rec { apps.jupyterlab = { type = "app"; program = "${jupyterEnvironment}/bin/jupyter-lab"; }; defaultApp = apps.jupyterlab; packages.cyanovision-ui = cyanovision.packages.cyanovision-ui; packages.cyanovision-model = cyanovision.packages.cyanovision-model; packages.cyanovision-dataset = cyanovision.packages.cyanovision-dataset; packages.tflite-model-maker = cyanovision.packages.tflite-model-maker; packages.python-venv = python-venv; packages.docker = (machNix.mkDockerImage { packagesExtra = cyanovision.packagesExtra; requirements = cyanovision.pythonPackages; _.pytest-cov.propagatedBuildInputs.mod = pySelf: self: oldVal: oldVal ++ [pySelf.tomli]; }) .override (oldAttrs: { name = cyanovision.name; config.Cmd = ["jupyter" "lab" "--notebook-dir=/mnt" "--allow-root" "--ip=0.0.0.0"]; }); defaultPackage = packages.cyanovision-ui; devShell = pkgs.mkShell { name = "nix-${cyanovision.name}"; buildInputs = [ cyanovision.packagesExtra cyanovision.pythonPackages python-venv pkgs.git ]; }; }); }