nix-cyanovision/flake.nix

185 lines
5.9 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";
src = pkgs.fetchFromGitHub {
owner = "IoannouPanayiotis";
repo = "Sensor-CDT-Team-Challenge-2021-2022";
rev = "fd7e538b8afc2227a1100bdd42903b282fcf46bb";
sha256 = "sha256-e4kEuvH3my4gzOhP9zWCWSUOYokJJ7JBRXSpeMQkkp0=";
};
requirements = {
release = builtins.readFile ./requirements/release.txt;
dev = builtins.readFile ./requirements/dev.txt;
all = cyanovision.requirements.release + cyanovision.requirements.dev;
};
packagesExtra = with pkgs; [
libusb1
libsndfile
];
pythonPackages = with pkgs.python310Packages; [
matplotlib
numpy
pathlib2
pillow
pycocotools
tensorflow
tkinter
];
packages = {
# cyanovision-deps = machNix.mkPython {
# packagesExtra = cyanovision.packagesExtra;
# requirements = cyanovision.requirements.release;
# providers.tensorflow = "nixpkgs";
# };
cyanovision-ui = pkgs.python3Packages.buildPythonApplication rec {
pname = "${cyanovision.name}-ui";
version = "2022";
src = cyanovision.src;
propagatedBuildInputs = cyanovision.packagesExtra;
pythonPath = with pkgs.python310Packages; [
matplotlib
numpy
pathlib2
pillow
pycocotools
tensorflow
tkinter
];
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;
};
};
};
venv = machNix.mkPython {
packagesExtra = cyanovision.packagesExtra;
requirements = cyanovision.requirements.release;
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-deps = cyanovision.packages.cyanovision-deps;
packages.cyanovision-ui = cyanovision.packages.cyanovision-ui;
packages.cyanovision-model = cyanovision.packages.cyanovision-model;
packages.cyanovision-dataset = cyanovision.packages.cyanovision-dataset;
packages.venv = venv;
packages.docker =
(machNix.mkDockerImage {
packagesExtra = with pkgs; [bash libusb1 libsndfile];
requirements = builtins.readFile ./requirements/release.txt;
_.pytest-cov.propagatedBuildInputs.mod = pySelf: self: oldVal: oldVal ++ [pySelf.tomli];
})
.override
(oldAttrs: {
name = "cyanovision";
config.Cmd = ["jupyter" "lab" "--notebook-dir=/mnt" "--allow-root" "--ip=0.0.0.0"];
});
defaultPackage = packages.cyanovision-ui;
# devShell = jupyterEnvironment.env;
devShell = pkgs.mkShell {
name = "nix-cyanovision";
buildInputs = [
# cyanovision-dataset
# cyanovision-model
# cyanovision-ui
venv
pkgs.git
pkgs.libusb1
];
shellHook = ''
'';
};
});
}