working flake biuld

This commit is contained in:
Sebastian Wendel 2022-09-27 00:51:48 +02:00
commit cfa54fac5d
No known key found for this signature in database
GPG key ID: 1422B7DF78144640
7 changed files with 578 additions and 0 deletions

2
.envrc Normal file
View file

@ -0,0 +1,2 @@
use flake
eval "$shellHook"

7
.gitignore vendored Normal file
View file

@ -0,0 +1,7 @@
.*/
**/__pycache__/
result
*.egg-info
build/
.direnv
jupyterlab

0
README.md Normal file
View file

361
flake.lock Normal file
View file

@ -0,0 +1,361 @@
{
"nodes": {
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1631705391,
"narHash": "sha256-PzP6vikNJZiS7yANC6sZWQlIDf4E2MTckvAsJxwV0DQ=",
"owner": "teto",
"repo": "flake-compat",
"rev": "8e15c6e3c0f15d0687a2ab6ae92cc7fab896bfed",
"type": "github"
},
"original": {
"owner": "teto",
"ref": "support-packages",
"repo": "flake-compat",
"type": "github"
}
},
"flake-compat_2": {
"flake": false,
"locked": {
"lastModified": 1627913399,
"narHash": "sha256-hY8g6H2KFL8ownSiFeMOjwPC8P0ueXpCVEbxgda3pko=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "12c64ca55c1014cdc1b16ed5a804aa8576601ff2",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-compat_3": {
"flake": false,
"locked": {
"lastModified": 1627913399,
"narHash": "sha256-hY8g6H2KFL8ownSiFeMOjwPC8P0ueXpCVEbxgda3pko=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "12c64ca55c1014cdc1b16ed5a804aa8576601ff2",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-utils": {
"locked": {
"lastModified": 1659877975,
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_2": {
"locked": {
"lastModified": 1659877975,
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_3": {
"locked": {
"lastModified": 1631561581,
"narHash": "sha256-3VQMV5zvxaVLvqqUrNz3iJelLw30mIVSfZmAaauM3dA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "7e5bf3925f6fbdfaf50a2a7ca0be2879c4261d19",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_4": {
"locked": {
"lastModified": 1629481132,
"narHash": "sha256-JHgasjPR0/J1J3DRm4KxM4zTyAj4IOJY8vIl75v/kPI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "997f7efcb746a9c140ce1f13c72263189225f482",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_5": {
"locked": {
"lastModified": 1642700792,
"narHash": "sha256-XqHrk7hFb+zBvRg6Ghl+AZDq03ov6OshJLiSWOoX5es=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "846b2ae0fc4cc943637d3d1def4454213e203cba",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"gitignore": {
"flake": false,
"locked": {
"lastModified": 1611672876,
"narHash": "sha256-qHu3uZ/o9jBHiA3MEKHJ06k7w4heOhA+4HCSIvflRxo=",
"owner": "hercules-ci",
"repo": "gitignore.nix",
"rev": "211907489e9f198594c0eb0ca9256a1949c9d412",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "gitignore.nix",
"type": "github"
}
},
"hls": {
"inputs": {
"flake-compat": "flake-compat_3",
"flake-utils": "flake-utils_4",
"gitignore": "gitignore",
"nixpkgs": "nixpkgs",
"pre-commit-hooks": "pre-commit-hooks"
},
"locked": {
"lastModified": 1637213318,
"narHash": "sha256-ZgxPwV7t4DyGYP7aXoetq+JHtd73XlOV2fYSflQmOXw=",
"owner": "haskell",
"repo": "haskell-language-server",
"rev": "311107eabbf0537e0c192b2c377d282505b4eff1",
"type": "github"
},
"original": {
"owner": "haskell",
"repo": "haskell-language-server",
"type": "github"
}
},
"ihaskell": {
"inputs": {
"flake-compat": "flake-compat_2",
"flake-utils": "flake-utils_3",
"hls": "hls",
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1663329285,
"narHash": "sha256-X4GJE1Ao3cMSaSyxCqYMsUp3jYOeTavQCrgYxDsBark=",
"owner": "gibiansky",
"repo": "IHaskell",
"rev": "e1fc53a97f51293d8b24aa96c3280928596d414b",
"type": "github"
},
"original": {
"owner": "gibiansky",
"repo": "IHaskell",
"type": "github"
}
},
"jupyterWith": {
"inputs": {
"flake-compat": "flake-compat",
"flake-utils": "flake-utils_2",
"ihaskell": "ihaskell",
"nixpkgs": "nixpkgs_3"
},
"locked": {
"lastModified": 1663881891,
"narHash": "sha256-280tlQA0ZwIMsyqJ4OFhfMNBzDLTBPK9mBQNZ6LxrhY=",
"owner": "tweag",
"repo": "jupyterWith",
"rev": "2f89c4f64586565d8d591cfd428f5c201eb8467c",
"type": "github"
},
"original": {
"owner": "tweag",
"repo": "jupyterWith",
"type": "github"
}
},
"mach-nix": {
"inputs": {
"flake-utils": "flake-utils_5",
"nixpkgs": "nixpkgs_4",
"pypi-deps-db": "pypi-deps-db"
},
"locked": {
"lastModified": 1654084003,
"narHash": "sha256-j/XrVVistvM+Ua+0tNFvO5z83isL+LBgmBi9XppxuKA=",
"owner": "DavHau",
"repo": "mach-nix",
"rev": "7e14360bde07dcae32e5e24f366c83272f52923f",
"type": "github"
},
"original": {
"id": "mach-nix",
"ref": "3.5.0",
"type": "indirect"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1630887066,
"narHash": "sha256-0ecIlrLsNIIa+zrNmzXXmbMBLZlmHU/aWFsa4bq99Hk=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "5e47a07e9f2d7ed999f2c7943b0896f5f7321ca3",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1634515797,
"narHash": "sha256-elgCUC2khtBkOSpE4gDymNvthTZAI4hGI2iNu3YEUkA=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "5f0194220f2402b06f7f79bba6351895facb5acb",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_3": {
"locked": {
"lastModified": 1659446231,
"narHash": "sha256-hekabNdTdgR/iLsgce5TGWmfIDZ86qjPhxDg/8TlzhE=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "eabc38219184cc3e04a974fe31857d8e0eac098d",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "release-21.11",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_4": {
"locked": {
"lastModified": 1643805626,
"narHash": "sha256-AXLDVMG+UaAGsGSpOtQHPIKB+IZ0KSd9WS77aanGzgc=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "554d2d8aa25b6e583575459c297ec23750adb6cb",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "nixos-unstable",
"type": "indirect"
}
},
"nixpkgs_5": {
"locked": {
"lastModified": 1664191034,
"narHash": "sha256-J8km863T/UmO0jsi58eqV/H+aua9fXMS8DjELdxwOYc=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "ef395e396b97462839e3f964fc8795f1c93ec904",
"type": "github"
},
"original": {
"owner": "NixOS",
"repo": "nixpkgs",
"type": "github"
}
},
"pre-commit-hooks": {
"inputs": {
"flake-utils": [
"jupyterWith",
"ihaskell",
"hls",
"flake-utils"
],
"nixpkgs": [
"jupyterWith",
"ihaskell",
"hls",
"nixpkgs"
]
},
"locked": {
"lastModified": 1624971177,
"narHash": "sha256-Amf/nBj1E77RmbSSmV+hg6YOpR+rddCbbVgo5C7BS0I=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "397f0713d007250a2c7a745e555fa16c5dc8cadb",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"type": "github"
}
},
"pypi-deps-db": {
"flake": false,
"locked": {
"lastModified": 1643877077,
"narHash": "sha256-jv8pIvRFTP919GybOxXE5TfOkrjTbdo9QiCO1TD3ZaY=",
"owner": "DavHau",
"repo": "pypi-deps-db",
"rev": "da53397f0b782b0b18deb72ef8e0fb5aa7c98aa3",
"type": "github"
},
"original": {
"owner": "DavHau",
"repo": "pypi-deps-db",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"jupyterWith": "jupyterWith",
"mach-nix": "mach-nix",
"nixpkgs": "nixpkgs_5"
}
}
},
"root": "root",
"version": 7
}

184
flake.nix Normal file
View file

@ -0,0 +1,184 @@
{
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 = ''
'';
};
});
}

12
requirements/dev.txt Normal file
View file

@ -0,0 +1,12 @@
autopep8
coverage
flake8
pep8
pycodestyle
pyflakes
pylint
pytest
pytest-cov
python-dateutil
PyYAML
toml

12
requirements/release.txt Normal file
View file

@ -0,0 +1,12 @@
matplotlib
numpy
pathlib
# PIL
pycocotools
# tensorflow
tflite
# tflite-model-maker
# tflite-support
# tflite-model-maker==0.3.2
# tkinter
jupyterlab