diff --git a/.gitignore b/.gitignore index d5c2f00..a2fee81 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ **/.DS_Store env *.pyc +result* diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..16c26a4 --- /dev/null +++ b/flake.lock @@ -0,0 +1,26 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1701189068, + "narHash": "sha256-Z84Km4ILllusI9IPI9qFRKN4Ss5893Ntbp1TcMCFIds=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "6fc4c1c40c98de86565acdb3fe43c6ba3efb3115", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..bcea78d --- /dev/null +++ b/flake.nix @@ -0,0 +1,23 @@ +{ + description = "An air quality monitoring service with a Raspberry Pi and a SDS011 sensor."; + inputs.nixpkgs.url = "github:NixOS/nixpkgs"; + + outputs = { + self, + nixpkgs, + }: let + systems = ["aarch64-linux"]; + forEachSystem = nixpkgs.lib.genAttrs systems; + pkgsForEach = nixpkgs.legacyPackages; + in rec { + packages = forEachSystem (system: { + default = pkgsForEach.${system}.callPackage ./nix {}; + }); + + devShells = forEachSystem (system: { + default = pkgsForEach.${system}.callPackage ./nix/shell.nix {}; + }); + + hydraJobs = packages; + }; +} diff --git a/nix/default.nix b/nix/default.nix new file mode 100644 index 0000000..e2677e9 --- /dev/null +++ b/nix/default.nix @@ -0,0 +1,62 @@ +{ + lib, + python3Packages, + makeWrapper, + python3, + ... +}: let + pname = "pi_air_quality_monitor"; + version = "0.0.1"; +in + python3Packages.buildPythonApplication { + inherit pname version; + format = "other"; + + src = ../src; + + pythonPath = with python3Packages; [ + pyserial + flask + redis + ipython + apscheduler + flask-cors + ( + buildPythonPackage rec { + pname = "python-aqi"; + version = "0.6.1"; + src = fetchPypi { + inherit pname version; + hash = "sha256-FBoDoP7UiIDchwbKV7A/MPqRq2DpMwR0v5yaj7m5YCA="; + }; + } + ) + ]; + + nativeBuildInputs = [makeWrapper]; + installFlags = ["prefix=$(out/bin)"]; + + postUnpack = '' + mkdir -p $out/bin + cp -rvf $src/* $out + ''; + + preFixup = '' + buildPythonPath "$pythonPath" + gappsWrapperArgs+=( + --prefix PYTHONPATH : "$program_PYTHONPATH" + ) + makeWrapper ${lib.getExe python3} $out/bin/${pname} \ + --add-flags $out/app.py \ + --prefix PYTHONPATH : "$program_PYTHONPATH" \ + --chdir $out/bin + ''; + + meta = { + description = "An air quality monitoring service with a Raspberry Pi and a SDS011 sensor. "; + homepage = "https://github.com/rydercalmdown/pi_air_quality_monitor"; + mainProgram = pname; + platforms = with lib.platforms; ["aarch64-linux"]; + maintainers = with lib.maintainers; [NotAShelf]; + }; + } diff --git a/nix/shell.nix b/nix/shell.nix new file mode 100644 index 0000000..9fa8a12 --- /dev/null +++ b/nix/shell.nix @@ -0,0 +1,13 @@ +{ + callPackage, + mkShellNoCC, + python3, + ... +}: let + defaultPackage = callPackage ./default.nix; +in + mkShellNoCC { + packages = [ + (python3.withPackages defaultPackage.propagatedBuildInputs) + ]; + }