From afcf5facb091b92829d041c95b597929588cb15e Mon Sep 17 00:00:00 2001 From: ErrorNoInternet Date: Fri, 8 May 2026 12:35:51 -0400 Subject: [PATCH] treewide: add complete nix package --- .gitignore | 1 + flake.nix | 17 ++-- nix/dave_py.nix | 138 ++++++++++++++++++++++++++++++ {npins => nix/npins}/default.nix | 0 {npins => nix/npins}/sources.json | 26 ++++++ default.nix => nix/package.nix | 24 +++++- 6 files changed, 190 insertions(+), 16 deletions(-) create mode 100644 nix/dave_py.nix rename {npins => nix/npins}/default.nix (100%) rename {npins => nix/npins}/sources.json (52%) rename default.nix => nix/package.nix (73%) diff --git a/.gitignore b/.gitignore index 26bb4b4..9aef414 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ .env .venv __pycache__ +result diff --git a/flake.nix b/flake.nix index b2430e0..6282358 100644 --- a/flake.nix +++ b/flake.nix @@ -6,11 +6,7 @@ }; outputs = - { - flake-parts, - self, - ... - }@inputs: + { flake-parts, self, ... }@inputs: flake-parts.lib.mkFlake { inherit inputs; } { systems = [ "aarch64-linux" @@ -22,20 +18,17 @@ { devShells.default = pkgs.mkShell { name = "errornocord"; - - buildInputs = with pkgs; [ - ffmpeg - self'.packages.default - ]; + buildInputs = [ self'.packages.default ]; + inputsFrom = [ self'.packages.default ]; }; packages = rec { - errornocord = pkgs.callPackage ./. { inherit self; }; + errornocord = pkgs.callPackage ./nix/package.nix { inherit self; }; default = errornocord; }; }; - flake.pins = import ./npins; + flake.pins = import ./nix/npins; }; description = "Hot-reloadable Discord music bot"; diff --git a/nix/dave_py.nix b/nix/dave_py.nix new file mode 100644 index 0000000..7d5b761 --- /dev/null +++ b/nix/dave_py.nix @@ -0,0 +1,138 @@ +{ + cmake, + lib, + ninja, + nlohmann_json, + openssl, + python3Packages, + self, + stdenv, +}: +let + mlspp = stdenv.mkDerivation { + pname = "mlspp"; + version = self.pins.mlspp.revision; + + src = self.pins.mlspp; + + nativeBuildInputs = [ + cmake + ninja + ]; + + buildInputs = [ + openssl + nlohmann_json + ]; + + postPatch = '' + substituteInPlace CMakeLists.txt \ + --replace-fail "-Wextra -Werror -Wmissing-declarations" "-Wextra -Wmissing-declarations" + ''; + + cmakeFlags = [ + "-DDISABLE_GREASE=ON" + "-DMLS_CXX_NAMESPACE=mlspp" + "-DBUILD_TESTING=OFF" + ]; + + meta = { + description = "Cisco MLS C++ library"; + homepage = "https://github.com/cisco/mlspp"; + license = lib.licenses.bsd2; + platforms = lib.platforms.unix; + }; + }; +in +python3Packages.buildPythonPackage { + pname = "dave.py"; + version = self.pins."dave.py".revision; + pyproject = true; + + src = self.pins."dave.py"; + + build-system = with python3Packages; [ + nanobind + scikit-build-core + ]; + + postPatch = '' + substituteInPlace pyproject.toml \ + --replace-fail "nanobind~=2.10.2" "nanobind>=2.10.2" + + substituteInPlace CMakeLists.txt \ + --replace-fail \ + 'set(VCPKG_MANIFEST_DIR "''${LIBDAVE_SRC_PATH}/vcpkg-alts/''${LIBDAVE_CRYPTO}" CACHE STRING "")' \ + 'set(VCPKG_MANIFEST_DIR "''${LIBDAVE_SRC_PATH}/vcpkg-alts/''${LIBDAVE_CRYPTO}" CACHE STRING "") + option(DAVE_USE_SYSTEM_DEPS "Use system CMake packages instead of the bundled vcpkg toolchain" OFF)' \ + --replace-fail \ + 'set(_VCPKG_TOOLCHAIN "''${LIBDAVE_SRC_PATH}/vcpkg/scripts/buildsystems/vcpkg.cmake")' \ + 'if (NOT DAVE_USE_SYSTEM_DEPS) + set(_VCPKG_TOOLCHAIN "''${LIBDAVE_SRC_PATH}/vcpkg/scripts/buildsystems/vcpkg.cmake")' \ + --replace-fail \ + 'message(STATUS "Using vcpkg toolchain ''${CMAKE_TOOLCHAIN_FILE}")' \ + 'message(STATUS "Using vcpkg toolchain ''${CMAKE_TOOLCHAIN_FILE}") + else() + message(STATUS "Using system dependencies") + endif()' + + substituteInPlace scripts/collect_licenses.py \ + --replace-fail \ + 'parser.add_argument("vcpkg_installed_dir", type=Path)' \ + 'parser.add_argument("--skip-vcpkg-deps", action="store_true") + parser.add_argument("vcpkg_installed_dir", type=Path)' \ + --replace-fail \ + 'vcpkg_deps = [ + "mlspp", + "nlohmann-json", + "boringssl" if args.crypto == "boringssl" else "openssl", + ] + LICENSE_PATHS.update( + {dep: (args.vcpkg_installed_dir / "share" / dep / "copyright") for dep in vcpkg_deps} + )' \ + 'if not args.skip_vcpkg_deps: + vcpkg_deps = [ + "mlspp", + "nlohmann-json", + "boringssl" if args.crypto == "boringssl" else "openssl", + ] + LICENSE_PATHS.update( + {dep: (args.vcpkg_installed_dir / "share" / dep / "copyright") for dep in vcpkg_deps} + )' + + substituteInPlace CMakeLists.txt \ + --replace-fail \ + 'COMMAND "''${Python_EXECUTABLE}" "scripts/collect_licenses.py"' \ + 'COMMAND "''${Python_EXECUTABLE}" "scripts/collect_licenses.py" --skip-vcpkg-deps' + ''; + + nativeBuildInputs = [ + cmake + ninja + ]; + + dontUseCmakeConfigure = true; + + buildInputs = [ + openssl + nlohmann_json + mlspp + ]; + + dependencies = [ ]; + + nativeCheckInputs = with python3Packages; [ + pytestCheckHook + ]; + + SKBUILD_CMAKE_ARGS = "-DDAVE_USE_SYSTEM_DEPS=ON"; + + pythonImportsCheck = [ "dave" ]; + + meta = { + description = "Python bindings for libdave, Discord's audio & video end-to-end encryption"; + homepage = "https://github.com/DisnakeDev/dave.py"; + changelog = "https://github.com/DisnakeDev/dave.py/blob/main/docs/CHANGELOG.md"; + license = lib.licenses.mit; + }; +} diff --git a/npins/default.nix b/nix/npins/default.nix similarity index 100% rename from npins/default.nix rename to nix/npins/default.nix diff --git a/npins/sources.json b/nix/npins/sources.json similarity index 52% rename from npins/sources.json rename to nix/npins/sources.json index ce5f316..d36e5f0 100644 --- a/npins/sources.json +++ b/nix/npins/sources.json @@ -1,5 +1,18 @@ { "pins": { + "dave.py": { + "type": "Git", + "repository": { + "type": "GitHub", + "owner": "DisnakeDev", + "repo": "dave.py" + }, + "branch": "main", + "submodules": true, + "revision": "6653dd0f53553ab8af1593eae32f6128f969c8ff", + "url": null, + "hash": "sha256-bfHVl+KHeMEQNBYcmmEcdw8ZNtP2Apxhjix85yqJ+3M=" + }, "disnake": { "type": "Git", "repository": { @@ -20,6 +33,19 @@ "version": "1.0.8", "url": "https://files.pythonhosted.org/packages/8c/db/3a86b247c7653a3f1676d16a316daf400edcf76295098ab60544f2a8f8b7/disnake_paginator-1.0.8.tar.gz", "hash": "sha256-Sn0qbKNkJIdX8GCRRRPxwWutBtG9c1Zt7JnQAsl5I4s=" + }, + "mlspp": { + "type": "Git", + "repository": { + "type": "GitHub", + "owner": "cisco", + "repo": "mlspp" + }, + "branch": "main", + "submodules": false, + "revision": "92aaa4134fa45ec39957a7c81a342401fba7feb2", + "url": "https://github.com/cisco/mlspp/archive/92aaa4134fa45ec39957a7c81a342401fba7feb2.tar.gz", + "hash": "sha256-HElw0fvL7ClDSXBDYRw1qcPw73oWvbMfi7skQokyftY=" } }, "version": 7 diff --git a/default.nix b/nix/package.nix similarity index 73% rename from default.nix rename to nix/package.nix index a870f84..301ebe4 100644 --- a/default.nix +++ b/nix/package.nix @@ -1,10 +1,14 @@ { + callPackage, + ffmpeg, lib, + libopus, python3Packages, self, - ... }: let + dave_py = callPackage ./dave_py.nix { inherit self; }; + disnake = python3Packages.disnake.overrideAttrs (old: { src = self.pins.disnake; @@ -12,6 +16,7 @@ let with python3Packages; old.propagatedBuildInputs ++ [ + dave_py typing-extensions versioningit ]; @@ -39,7 +44,7 @@ python3Packages.buildPythonApplication { pname = "errornocord"; version = "0.1.0"; - src = lib.cleanSource ./.; + src = lib.cleanSource ../.; pyproject = true; build-system = [ python3Packages.setuptools ]; @@ -47,13 +52,24 @@ python3Packages.buildPythonApplication { propagatedBuildInputs = with python3Packages; [ aiohttp audioop-lts - disnake - disnake_paginator psutil typing-extensions youtube-transcript-api yt-dlp + + disnake + disnake_paginator + + ffmpeg + libopus ]; doCheck = false; + + meta = { + description = "Hot-reloadable Discord music bot"; + homepage = "https://github.com/ErrorNoInternet/ErrorNoCord"; + license = lib.licenses.gpl3Only; + mainProgram = "errornocord"; + }; }