Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
269 changes: 269 additions & 0 deletions pkgs/by-name/pr/preflight/package.nix
Original file line number Diff line number Diff line change
@@ -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 "<boost/process.hpp>" "<boost/process/v2.hpp>"
'';

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
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="application/x-bgcode">
<comment xml:lang="en">Binary G-code file</comment>
<glob pattern="*.bgcode"/>
</mime-type>
</mime-info>
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";
};
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
From ddbcc5d287641ff35ccf17f069cb1fb929948118 Mon Sep 17 00:00:00 2001
From: Jasper Chan <jasperchan515@gmail.com>
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

60 changes: 60 additions & 0 deletions pkgs/by-name/pr/preflight/patches/allow_wayland.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
From 618c5fbb9e3b30ab30b1c7afb257248d1dfb1212 Mon Sep 17 00:00:00 2001
From: Jasper Chan <jasperchan515@gmail.com>
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 &params)
#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

Loading