From 31c89a680889eb13117f5bd4378d4f5973e223d5 Mon Sep 17 00:00:00 2001 From: Ashhhleyyy Date: Sun, 31 Mar 2024 23:16:34 +0100 Subject: [PATCH] feat: initial flake with running server --- .envrc | 1 + .gitignore | 5 ++- flake.lock | 61 ++++++++++++++++++++++++++++++++++ flake.nix | 61 ++++++++++++++++++++++++++++++++++ patches/0-setup.py-fixes.patch | 53 +++++++++++++++++++++++++++++ sanic-cors.nix | 36 ++++++++++++++++++++ 6 files changed, 216 insertions(+), 1 deletion(-) create mode 100644 .envrc create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 patches/0-setup.py-fixes.patch create mode 100644 sanic-cors.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore index 772a7f1..393bfcd 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,7 @@ music-tmp/ presenter-build -node_modules/ \ No newline at end of file +node_modules/ + +.direnv/ +result diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..40a5b6b --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1711715736, + "narHash": "sha256-9slQ609YqT9bT/MNX9+5k5jltL9zgpn36DpFB7TkttM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "807c549feabce7eddbf259dbdcec9e0600a0660d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..b67709f --- /dev/null +++ b/flake.nix @@ -0,0 +1,61 @@ +{ + inputs = { + nixpkgs.url = github:NixOS/nixpkgs/nixpkgs-unstable; + flake-utils.url = github:numtide/flake-utils; + }; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + }; + sanic-cors = import ./sanic-cors.nix { + inherit (pkgs) lib; + inherit (pkgs.python311Packages) setuptools packaging sanic buildPythonPackage fetchPypi; + }; + dependencies = ps: with ps; [ + setuptools + wheel + sanic + sanic-cors + pygame + syncer + aiohttp + mutagen + sounddevice + setproctitle + pyttsx3 + websockets + pyserial + requests + jinja2 + pydub + psutil + ]; + version = self.shortRev or self.dirtyShortRev or "dirty-inputs"; + in + { + packages = { + default = pkgs.python311Packages.buildPythonApplication { + pname = "bapsicle"; + inherit version; + doCheck = false; + propagatedBuildInputs = dependencies pkgs.python311Packages; + src = ./.; + patches = [ + ./patches/0-setup.py-fixes.patch + ]; + }; + }; + + devShells.default = pkgs.mkShell { + nativeBuildInputs = with pkgs; [ + (python311.withPackages dependencies) + nodejs_20 + yarn + ffmpeg_6-full + ]; + }; + }); +} diff --git a/patches/0-setup.py-fixes.patch b/patches/0-setup.py-fixes.patch new file mode 100644 index 0000000..96b928f --- /dev/null +++ b/patches/0-setup.py-fixes.patch @@ -0,0 +1,53 @@ +diff --git a/launch.py b/launch.py +index 712bb6a..6210095 100755 +--- a/launch.py ++++ b/launch.py +@@ -54,14 +54,7 @@ def notif(msg: str): + print("NOTIFICATION:{}".format(msg)) + + +-if __name__ == "__main__": +- # On Windows, calling this function is necessary. +- # Causes all kinds of loops if not present. +- # IT HAS TO BE RIGHT HERE, AT THE TOP OF __MAIN__ +- # NOT INSIDE AN IF STATEMENT. RIGHT. HERE. +- # If it's not here, multiprocessing just doesn't run in the package. +- # Freeze support refers to being packaged with Pyinstaller. +- multiprocessing.freeze_support() ++def main(): + setproctitle("BAPSicle - Launcher") + if len(sys.argv) > 1: + # We got an argument! It's probably Platypus's UI. +@@ -86,3 +79,13 @@ if __name__ == "__main__": + else: + startServer() + sys.exit(0) ++ ++if __name__ == "__main__": ++ # On Windows, calling this function is necessary. ++ # Causes all kinds of loops if not present. ++ # IT HAS TO BE RIGHT HERE, AT THE TOP OF __MAIN__ ++ # NOT INSIDE AN IF STATEMENT. RIGHT. HERE. ++ # If it's not here, multiprocessing just doesn't run in the package. ++ # Freeze support refers to being packaged with Pyinstaller. ++ multiprocessing.freeze_support() ++ main() +diff --git a/setup.py b/setup.py +index 9af4e1d..3a6db65 100644 +--- a/setup.py ++++ b/setup.py +@@ -7,5 +7,13 @@ setup( + description=package.DESCRIPTION, + author=package.AUTHOR, + license=package.LICENSE, +- packages=find_packages(), ++ packages=find_packages() + [ ++ '.', ++ 'alerts', ++ ], ++ entry_points={ ++ 'console_scripts': [ ++ 'bapsicle = launch:main' ++ ], ++ }, + ) diff --git a/sanic-cors.nix b/sanic-cors.nix new file mode 100644 index 0000000..20bc198 --- /dev/null +++ b/sanic-cors.nix @@ -0,0 +1,36 @@ +{ lib +, buildPythonPackage +, fetchPypi + +, setuptools +, packaging +, sanic + }: + +buildPythonPackage rec { + pname = "Sanic-Cors"; + version = "2.2.0"; + pyproject= true; + + src = fetchPypi { + inherit pname version; + hash = "sha256-+NdRXaTIuDeHHUIsZjFMS1cEOWp4iUtZxQ4mqnKpWHM="; + }; + + nativeBuildInputs = [ + setuptools + ]; + + propagatedBuildInputs = [ + sanic + packaging + ]; + + meta = with lib; { + changelog = "https://github.com/ashleysommer/sanic-cors/releases/tag/${version}"; + description = "A Sanic extension for handling Cross Origin Resource Sharing (CORS), making cross-origin AJAX possible."; + homepage = "https://github.com/ashleysommer/sanic-cors"; + license = licenses.mit; + maintainers = with maintainers; []; + }; +}