From 7e7898c0578d4628e61995dbe3c95590b028d402 Mon Sep 17 00:00:00 2001 From: Jasper Chan Date: Wed, 20 May 2026 18:04:45 -0700 Subject: [PATCH] preflight: init at 1.1.0 --- pkgs/by-name/pr/preflight/package.nix | 269 ++++++++++++++++++ ...-CMakeLists-Link-against-webkit2gtk-.patch | 29 ++ .../pr/preflight/patches/allow_wayland.patch | 60 ++++ 3 files changed, 358 insertions(+) create mode 100644 pkgs/by-name/pr/preflight/package.nix create mode 100644 pkgs/by-name/pr/preflight/patches/0001-not-for-upstream-CMakeLists-Link-against-webkit2gtk-.patch create mode 100644 pkgs/by-name/pr/preflight/patches/allow_wayland.patch diff --git a/pkgs/by-name/pr/preflight/package.nix b/pkgs/by-name/pr/preflight/package.nix new file mode 100644 index 0000000000000..83329d1ef7ec0 --- /dev/null +++ b/pkgs/by-name/pr/preflight/package.nix @@ -0,0 +1,269 @@ +{ + stdenv, + lib, + binutils, + fetchFromGitHub, + cmake, + pkg-config, + wrapGAppsHook3, + boost187, + c-blosc, + cereal, + cgal, + curl, + dbus, + eigen, + expat, + glew, + glib, + glib-networking, + gmp, + gtk3, + hicolor-icon-theme, + imath, + libjpeg_turbo, + libpng, + mpfr, + nanosvg, + nlohmann_json, + nlopt, + onetbb, + opencascade-occt, + openvdb, + pcre2, + python3, + python3Packages, # pybind11 + qhull, + wxwidgets_3_2, + libx11, + libbgcode, + heatshrink, + catch2_3, + webkitgtk_4_1, + ctestCheckHook, + withSystemd ? lib.meta.availableOn stdenv.hostPlatform systemd, + systemd, + udevCheckHook, + z3, + nix-update-script, + wxGTK-override ? null, + opencascade-override ? null, + +}: +let + nanosvg-fltk = nanosvg.overrideAttrs (old: { + pname = "nanosvg-fltk"; + version = "unstable-2022-12-22"; + + src = fetchFromGitHub { + owner = "fltk"; + repo = "nanosvg"; + rev = "abcd277ea45e9098bed752cf9c6875b533c0892f"; + hash = "sha256-WNdAYu66ggpSYJ8Kt57yEA4mSTv+Rvzj9Rm1q765HpY="; + }; + }); + wxGTK-override' = if wxGTK-override == null then wxwidgets_3_2 else wxGTK-override; + opencascade-override' = + if opencascade-override == null then opencascade-occt else opencascade-override; + +in +stdenv.mkDerivation (finalAttrs: { + __structuredAttrs = true; + pname = "preflight"; + version = "1.1.0"; + src = fetchFromGitHub { + owner = "oozebot"; + repo = "preFlight"; + hash = "sha256-3m/mz0DwuhIo7E/9V8kL68TO0WjNGIHyFlG9EYtDeMs="; + tag = "v${finalAttrs.version}"; + }; + + patches = [ + # Fix for webkitgtk linking + ./patches/0001-not-for-upstream-CMakeLists-Link-against-webkit2gtk-.patch + # https://github.com/NixOS/nixpkgs/issues/415703 + # https://gitlab.archlinux.org/archlinux/packaging/packages/prusa-slicer/-/merge_requests/5 + ./patches/allow_wayland.patch + ]; + + postPatch = ( + # Make Gcode viewer open newer bgcode files. + '' + substituteInPlace src/platform/unix/preFlightGcodeviewer.desktop \ + --replace-fail 'MimeType=text/x.gcode;' 'MimeType=application/x-bgcode;text/x.gcode;' + '' + # Make preFlight handle the url "prusaslicer://" + + '' + substituteInPlace src/platform/unix/preFlight.desktop \ + --replace-fail \ + 'Exec=preflight %F' \ + 'Exec=preflight %U' + + substituteInPlace src/platform/unix/preFlight.desktop \ + --replace-fail \ + 'MimeType=model/stl;application/vnd.ms-3mfdocument;application/prs.wavefront-obj;application/x-amf;' \ + 'MimeType=model/stl;application/vnd.ms-3mfdocument;application/prs.wavefront-obj;application/x-amf;x-scheme-handler/prusaslicer;' + '' + ); + + nativeBuildInputs = [ + cmake + pkg-config + python3 + wrapGAppsHook3 + wxGTK-override' + udevCheckHook + ]; + + buildInputs = [ + binutils + boost187 + c-blosc + cereal + cgal + curl + dbus + eigen + expat + glew + glib + glib-networking + gmp + gtk3 + hicolor-icon-theme + imath + libjpeg_turbo + libpng + mpfr + nanosvg-fltk + nlopt + onetbb + opencascade-override' + openvdb + pcre2 + python3 + python3Packages.pybind11 + qhull + wxGTK-override' + libx11 + libbgcode + heatshrink + catch2_3 + webkitgtk_4_1 + z3 + nlohmann_json + + ] + ++ lib.optionals withSystemd [ + systemd + ]; + + strictDeps = true; + + # Causes wrapGAppsHook3 to only wrap the debug output + separateDebugInfo = false; + + doInstallCheck = true; + + env = { + # The build system uses custom logic - defined in + # cmake/modules/FindNLopt.cmake in the package source - for finding the nlopt + # library, which doesn't pick up the package in the nix store. We + # additionally need to set the path via the NLOPT environment variable. + NLOPT = nlopt; + } + // lib.optionalAttrs withSystemd { + # prusa-slicer uses dlopen on `libudev.so` at runtime + NIX_LDFLAGS = "-ludev"; + }; + + prePatch = '' + # Since version 2.5.0 of nlopt we need to link to libnlopt, as libnlopt_cxx + # now seems to be integrated into the main lib. + sed -i 's|nlopt_cxx|nlopt|g' cmake/modules/FindNLopt.cmake + + # https://github.com/prusa3d/PrusaSlicer/issues/9581 + if [ -f "cmake/modules/FindEXPAT.cmake" ]; then + rm cmake/modules/FindEXPAT.cmake + fi + + # Fix resources folder location on macOS + substituteInPlace src/${ + if finalAttrs.pname == "preflight" then "CLI/Setup.cpp" else "preFlight.cpp" + } \ + --replace-fail "#ifdef __APPLE__" "#if 0" + + substituteInPlace src/libslic3r/CMakeLists.txt \ + --replace-fail "libjpeg-turbo::jpeg-static" "libjpeg-turbo::jpeg" + + substituteInPlace \ + src/libslic3r/GCode/PostProcessor.cpp \ + src/slic3r/GUI/RemovableDriveManager.cpp \ + src/slic3r/Utils/Process.cpp \ + --replace-fail "" "" + ''; + + cmakeFlags = [ + "-DSLIC3R_STATIC=0" + "-DSLIC3R_FHS=1" + "-DSLIC3R_GTK=3" + "-DCMAKE_CXX_FLAGS=-DBOOST_LOG_DYN_LINK" + # there is many different min versions set accross different + # Find*.cmake files, substituting them all is not viable + "-DCMAKE_POLICY_VERSION_MINIMUM=3.10" + "-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=OFF" + "-Wno-dev" + ]; + NIX_CFLAGS_COMPILE = "-fno-lto"; + NIX_CXXFLAGS_COMPILE = "-fno-lto"; + + postInstall = '' + ln -s "$out/bin/preflight" "$out/bin/preflight-gcodeviewer" + + mkdir -p "$out"/share/mime/packages + cat << EOF > "$out"/share/mime/packages/preflight-gcode-viewer.xml + + + + Binary G-code file + + + + EOF + ''; + + preFixup = '' + gappsWrapperArgs+=( + --prefix LD_LIBRARY_PATH : "$out/lib" + ) + ''; + + doCheck = true; + nativeCheckInputs = [ ctestCheckHook ]; + checkFlags = [ + "--force-new-ctest-process" + "-E" + "libslic3r_tests|sla_print_tests" + ]; + + passthru.updateScript = nix-update-script { + extraArgs = [ + "--version-regex" + "^v(.+)$" + ]; + }; + + meta = { + description = "G-code generator for 3D printer"; + homepage = "preflight3d.com"; + changelog = "https://github.com/oozebot/preFlight/releases/tag/${finalAttrs.src.tag}"; + license = lib.licenses.agpl3Plus; + maintainers = with lib.maintainers; [ + gigahawk + ]; + platforms = lib.platforms.unix; + } + // lib.optionalAttrs (stdenv.hostPlatform.isDarwin) { + mainProgram = "preFlight"; + }; +}) diff --git a/pkgs/by-name/pr/preflight/patches/0001-not-for-upstream-CMakeLists-Link-against-webkit2gtk-.patch b/pkgs/by-name/pr/preflight/patches/0001-not-for-upstream-CMakeLists-Link-against-webkit2gtk-.patch new file mode 100644 index 0000000000000..c13f68ffe26f6 --- /dev/null +++ b/pkgs/by-name/pr/preflight/patches/0001-not-for-upstream-CMakeLists-Link-against-webkit2gtk-.patch @@ -0,0 +1,29 @@ +From ddbcc5d287641ff35ccf17f069cb1fb929948118 Mon Sep 17 00:00:00 2001 +From: Jasper Chan +Date: Wed, 20 May 2026 15:19:27 -0700 +Subject: [PATCH] [not for upstream] CMakeLists: Link against webkit2gtk in + libslic3r_gui + +--- + src/CMakeLists.txt | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt +index 9e16369..dd156e8 100644 +--- a/src/CMakeLists.txt ++++ b/src/CMakeLists.txt +@@ -260,6 +260,11 @@ if (WIN32) + endif () + endif () + ++# We link against webkit2gtk symbols in src/slic3r/GUI/Widgets/WebView.cpp ++if (CMAKE_SYSTEM_NAME STREQUAL "Linux") ++ target_link_libraries(libslic3r_gui PRIVATE webkit2gtk-4.1) ++endif () ++ + # Link the resources dir to where Slic3r GUI expects it + if (WIN32) + if (CMAKE_CONFIGURATION_TYPES) +-- +2.53.0 + diff --git a/pkgs/by-name/pr/preflight/patches/allow_wayland.patch b/pkgs/by-name/pr/preflight/patches/allow_wayland.patch new file mode 100644 index 0000000000000..128dc5bd13902 --- /dev/null +++ b/pkgs/by-name/pr/preflight/patches/allow_wayland.patch @@ -0,0 +1,60 @@ +From 618c5fbb9e3b30ab30b1c7afb257248d1dfb1212 Mon Sep 17 00:00:00 2001 +From: Jasper Chan +Date: Mon, 8 Jun 2026 11:23:26 -0700 +Subject: [PATCH] remove forcing GDK_BACKEND to x11 + +It seems the problems on Wayland from the past are removed meanwhile. +--- + src/CLI/GuiParams.cpp | 7 +++---- + src/CLI/Setup.cpp | 7 +------ + 2 files changed, 4 insertions(+), 10 deletions(-) + +diff --git a/src/CLI/GuiParams.cpp b/src/CLI/GuiParams.cpp +index 2589354..4a9fc67 100644 +--- a/src/CLI/GuiParams.cpp ++++ b/src/CLI/GuiParams.cpp +@@ -130,9 +130,8 @@ int start_gui_with_params(GUI::GUI_InitParams ¶ms) + #if !defined(_WIN32) && !defined(__APPLE__) + // likely some linux / unix system + const char *display = boost::nowide::getenv("DISPLAY"); +- // const char *wayland_display = boost::nowide::getenv("WAYLAND_DISPLAY"); +- //if (! ((display && *display) || (wayland_display && *wayland_display))) { +- if (!(display && *display)) ++ const char *wayland_display = boost::nowide::getenv("WAYLAND_DISPLAY"); ++ if (! ((display && *display) || (wayland_display && *wayland_display))) + { + // DISPLAY not set. + boost::nowide::cerr << "DISPLAY not set, GUI mode not available." << std::endl << std::endl; +@@ -169,4 +168,4 @@ int start_as_gcode_viewer(GUI::GUI_InitParams &gui_params) + } // namespace Slic3r::CLI + #else // SLIC3R_GUI + // If there is no GUI, we shall ignore the parameters. Remove them from the list. +-#endif // SLIC3R_GUI +\ No newline at end of file ++#endif // SLIC3R_GUI +diff --git a/src/CLI/Setup.cpp b/src/CLI/Setup.cpp +index 5c03b67..5552cfd 100644 +--- a/src/CLI/Setup.cpp ++++ b/src/CLI/Setup.cpp +@@ -234,11 +234,6 @@ static bool setup_common() + save_main_thread_id(); + + #ifdef __WXGTK__ +- // On Linux, wxGTK has no support for Wayland, and the app crashes on +- // startup if gtk3 is used. This env var has to be set explicitly to +- // instruct the window manager to fall back to X server mode. +- ::setenv("GDK_BACKEND", "x11", /* replace */ true); +- + // WebKit2GTK's DMA-BUF renderer uses GBM EGL for compositing. + // Disable it when it will fail: + // 1. No GPU at all (VMs, RDP, headless) - no DRI render nodes +@@ -415,4 +410,4 @@ bool setup(Data &cli, int argc, char **argv) + return true; + } + +-} // namespace Slic3r::CLI +\ No newline at end of file ++} // namespace Slic3r::CLI +-- +2.53.0 +