diff options
Diffstat (limited to 'package.nix')
| -rw-r--r-- | package.nix | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/package.nix b/package.nix new file mode 100644 index 0000000..7363fbb --- /dev/null +++ b/package.nix @@ -0,0 +1,113 @@ +{ + lib, + stdenv, + fetchFromGitHub, + cmake, + pkg-config, + openssl, + zlib, + curl, + # Which slicer this build targets. Determines the OBN_CLIENT_TYPE CMake + # passes through, which in turn determines the expected filename/version + # scheme for the built plugin. Currently "orca_slicer" is the only target + # exercised by this flake's home-manager module, but the upstream project + # also builds for e.g. "bambu_studio" - see its CMakeLists.txt/Clients.cmake + # for the full list. + clientType ? "orca_slicer", + # The plugin ABI is versioned into the .so filename the slicer expects + # (libbambu_networking_<version>.so). Check yours with: + # jq -r '.app.network_plugin_version // "not set"' ~/.config/OrcaSlicer/OrcaSlicer.conf + # and pass that here (with .99 as the 4th component - see README) if it differs. + obnVersion ? "02.03.00.99", +}: + +let + # Vendored deps the upstream CMakeLists normally fetches over the network + # at configure time via FetchContent. We pre-fetch them as normal Nix + # sources and hand CMake writable copies instead (see preConfigure), + # so the build stays sandboxed. + mosquittoSrc = fetchFromGitHub { + owner = "eclipse"; + repo = "mosquitto"; + rev = "v2.1.2"; # must match OBN_MOSQUITTO_GIT_TAG in CMakeLists.txt + hash = "sha256-Zl55yjuzQY2fyaKs/zLaJ7a3OONKTDQPaT+DpPURdZI="; + }; + + cjsonSrc = fetchFromGitHub { + owner = "DaveGamble"; + repo = "cJSON"; + rev = "v1.7.18"; # must match OBN_CJSON_GIT_TAG in CMakeLists.txt + hash = "sha256-UgUWc/+Zie2QNijxKK5GFe4Ypk97EidG8nTiiHhn5Ys="; + }; +in +stdenv.mkDerivation { + pname = "open-bamboo-networking-${clientType}"; + version = "1.1.0"; + + src = fetchFromGitHub { + owner = "ClusterM"; + repo = "open-bamboo-networking"; + rev = "v1.1.0"; + hash = "sha256-bxkOwCnlKu2fA3cEiTZq15anSwLkuJIyko19wqul6Fw="; + }; + + nativeBuildInputs = [ + cmake + pkg-config + ]; + buildInputs = [ + openssl + zlib + curl + ]; + + cmakeFlags = [ + "-DOBN_CLIENT_TYPE=${clientType}" + "-DOBN_VERSION=${obnVersion}" + "-DOBN_BUILD_TESTS=OFF" + # This build never touches $HOME - see README.md for install steps. + "-DOBN_PATCH_CLIENT_CONF=OFF" + "-DFETCHCONTENT_FULLY_DISCONNECTED=ON" + ]; + + # The build patches the vendored mosquitto/cJSON sources in place + # (VendorMosquittoEmbedPatch.cmake writes into libcommon/CMakeLists.txt + # etc.), so FETCHCONTENT_SOURCE_DIR_* can't point directly at the + # read-only fetchFromGitHub store paths. Copy them into a writable + # scratch dir first and point CMake there instead. + preConfigure = '' + mkdir -p _vendor/mosquitto _vendor/cjson + cp -r --no-preserve=mode,ownership ${mosquittoSrc}/. _vendor/mosquitto + cp -r --no-preserve=mode,ownership ${cjsonSrc}/. _vendor/cjson + chmod -R u+w _vendor + cmakeFlagsArray+=( + "-DFETCHCONTENT_SOURCE_DIR_ECLIPSE_MOSQUITTO=$(pwd)/_vendor/mosquitto" + "-DFETCHCONTENT_SOURCE_DIR_CJSON=$(pwd)/_vendor/cjson" + ) + ''; + + # `cmake --install` (run automatically by the stdenv cmake hook) produces, + # under $out/plugins/: + # libbambu_networking_<obnVersion>.so - LAN discovery/print/MQTT + # libBambuSource.so - camera/live-view tunnel + # liblive555.so - OTA-banner-check stub only, + # see README before installing + postInstall = '' + mkdir -p $out/lib + ln -s $out/plugins/libbambu_networking_${obnVersion}.so \ + $out/lib/libbambu_networking_${obnVersion}.so + ''; + + # Read this back from downstream (README examples, activation scripts) + # instead of repeating the version string everywhere. + passthru = { + inherit obnVersion clientType; + }; + + meta = with lib; { + description = "Open-source drop-in replacement for Bambu Lab slicers' proprietary bambu_networking plugin (client: ${clientType})"; + homepage = "https://github.com/ClusterM/open-bamboo-networking"; + license = licenses.agpl3Plus; + platforms = platforms.linux; + }; +} |
