nix-cyanovision/flake.nix

179 lines
5.6 KiB
Nix
Raw Normal View History

2022-09-27 00:51:48 +02:00
{
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";
2022-09-27 19:40:00 +02:00
2022-09-27 00:51:48 +02:00
src = pkgs.fetchFromGitHub {
owner = "IoannouPanayiotis";
repo = "Sensor-CDT-Team-Challenge-2021-2022";
rev = "fd7e538b8afc2227a1100bdd42903b282fcf46bb";
sha256 = "sha256-e4kEuvH3my4gzOhP9zWCWSUOYokJJ7JBRXSpeMQkkp0=";
};
2022-09-27 19:40:00 +02:00
2022-09-27 00:51:48 +02:00
packagesExtra = with pkgs; [
2022-09-27 19:40:00 +02:00
bash
2022-09-27 00:51:48 +02:00
libusb1
libsndfile
];
2022-09-27 19:40:00 +02:00
2022-09-27 00:51:48 +02:00
pythonPackages = with pkgs.python310Packages; [
matplotlib
numpy
pathlib2
pillow
pycocotools
tensorflow
tkinter
];
2022-09-27 19:40:00 +02:00
2022-09-27 00:51:48 +02:00
packages = {
2022-09-27 19:40:00 +02:00
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"];
};
2022-09-27 00:51:48 +02:00
cyanovision-ui = pkgs.python3Packages.buildPythonApplication rec {
pname = "${cyanovision.name}-ui";
version = "2022";
src = cyanovision.src;
propagatedBuildInputs = cyanovision.packagesExtra;
2022-09-27 19:40:00 +02:00
pythonPath = cyanovision.pythonPackages;
2022-09-27 00:51:48 +02:00
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}
'';
};
2022-09-27 19:40:00 +02:00
2022-09-27 00:51:48 +02:00
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;
};
2022-09-27 19:40:00 +02:00
2022-09-27 00:51:48 +02:00
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;
};
};
};
2022-09-27 19:40:00 +02:00
python-venv = machNix.mkPython {
2022-09-27 00:51:48 +02:00
packagesExtra = cyanovision.packagesExtra;
2022-09-27 19:40:00 +02:00
requirements = ''
tensorflow
# tflite-model-maker==0.3.2
'';
2022-09-27 00:51:48 +02:00
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;
2022-09-27 19:40:00 +02:00
packages.tflite-model-maker = cyanovision.packages.tflite-model-maker;
packages.python-venv = python-venv;
2022-09-27 00:51:48 +02:00
packages.docker =
(machNix.mkDockerImage {
2022-09-27 19:40:00 +02:00
packagesExtra = cyanovision.packagesExtra;
requirements = cyanovision.pythonPackages;
2022-09-27 00:51:48 +02:00
_.pytest-cov.propagatedBuildInputs.mod = pySelf: self: oldVal: oldVal ++ [pySelf.tomli];
})
.override
(oldAttrs: {
2022-09-27 19:40:00 +02:00
name = cyanovision.name;
2022-09-27 00:51:48 +02:00
config.Cmd = ["jupyter" "lab" "--notebook-dir=/mnt" "--allow-root" "--ip=0.0.0.0"];
});
defaultPackage = packages.cyanovision-ui;
devShell = pkgs.mkShell {
2022-09-27 19:40:00 +02:00
name = "nix-${cyanovision.name}";
2022-09-27 00:51:48 +02:00
buildInputs = [
2022-09-27 19:40:00 +02:00
cyanovision.packagesExtra
cyanovision.pythonPackages
python-venv
2022-09-27 00:51:48 +02:00
pkgs.git
];
};
});
}