Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jaredcrean/7a63a06ea62b06895fd689fe5fb5b563 to your computer and use it in GitHub Desktop.
Save jaredcrean/7a63a06ea62b06895fd689fe5fb5b563 to your computer and use it in GitHub Desktop.
{ lib
, stdenv
, fetchurl
, buildFHSEnv
, makeDesktopItem
, copyDesktopItems
, writeScript
, bash
}:
let
pname = "crealityprint";
version = "6.0.5-x86-beta1";
# The underlying derivation that provides the AppImage
crealityprint-unwrapped = stdenv.mkDerivation {
inherit pname version;
src = fetchurl {
url = "https://github.com/jamincollins/CrealityPrint/releases/download/v6.0.5-beta1/CrealityPrint-V6.0.5-x86_64-beta1.AppImage";
sha256 = "sha256-IRFiw27Pd8yTwSz6kXmJUCUjObc8EiBbVmwV/b91hMc=";
};
nativeBuildInputs = [
copyDesktopItems
];
desktopItems = [
(makeDesktopItem {
name = pname;
exec = pname;
desktopName = "CrealityPrint";
comment = "3D Printer Slicer by Creality";
categories = [ "Graphics" "3DGraphics" "Engineering" ];
})
];
dontUnpack = true;
dontBuild = true;
installPhase = ''
runHook preInstall
# Create directories
mkdir -p $out/bin $out/opt/${pname}
# Copy the AppImage file
cp $src $out/opt/${pname}/${pname}.AppImage
chmod +x $out/opt/${pname}/${pname}.AppImage
runHook postInstall
'';
meta = with lib; {
description = "Creality Print 3D Slicer";
homepage = "https://github.com/jamincollins/CrealityPrint";
license = licenses.unfree;
maintainers = with maintainers; [ ];
platforms = [ "x86_64-linux" ];
mainProgram = pname;
};
};
# Create a script that extracts the AppImage at runtime
extractAndRunScript = writeScript "${pname}-wrapper" ''
#!/usr/bin/env bash
APP_DIR="$HOME/.cache/${pname}"
APPIMAGE="${crealityprint-unwrapped}/opt/${pname}/${pname}.AppImage"
# Check if already extracted
if [ ! -d "$APP_DIR" ]; then
echo "Extracting AppImage to $APP_DIR..."
mkdir -p "$APP_DIR"
cd "$APP_DIR"
"$APPIMAGE" --appimage-extract
if [ ! -d "$APP_DIR/squashfs-root" ]; then
echo "Failed to extract AppImage contents"
exit 1
fi
fi
# Debug info
echo "Starting CrealityPrint from $APP_DIR/squashfs-root..."
# Run the application with environment variables to disable problematic plugins
cd "$APP_DIR/squashfs-root"
# List missing libraries for debugging
echo "Checking for missing libraries..."
ldd bin/CrealityPrint 2>&1 | grep "not found" || echo "All libraries found!"
# Make sure the FHS environment's libraries are in the path
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/lib:/usr/lib64"
# GTK environment variables to help with widget sizing and display issues
export GTK_CSD=0 # Disable client-side decorations
export GTK_THEME=Adwaita:light # Use a simple, stable theme
export GDK_SCALE=1 # Force scaling factor to 1
export GDK_DPI_SCALE=1 # Force DPI scaling to 1
export GTK_OVERLAY_SCROLLING=0 # Disable overlay scrolling which can cause sizing issues
# Font configuration workaround for segfault with certain fonts
export FONTCONFIG_PATH="/etc/fonts"
# Run with no-sandbox flag for Electron-based apps
echo "Running with no-sandbox..."
exec ./AppRun "$@"
'';
in buildFHSEnv {
name = pname;
targetPkgs = pkgs: with pkgs; [
# Basic system dependencies
bash
# The base app
crealityprint-unwrapped
# Common dependencies that AppImages typically need
zlib
glib
dejavu_fonts
liberation_ttf
freetype
fontconfig
wayland
wayland-protocols
libxkbcommon
# GStreamer dependencies - COMPREHENSIVE LIST
gst_all_1.gstreamer
gst_all_1.gst-plugins-base
gst_all_1.gst-plugins-good
gst_all_1.gst-plugins-bad
gst_all_1.gst-plugins-ugly
gst_all_1.gst-libav
# Make sure we have all individual GStreamer components
#gst-plugins-base.out # Core functionality
#gst-plugins-base.dev # Development files including headers
# All sub-packages that provide specific libraries
(pkgs.lib.getLib gst_all_1.gst-plugins-base)
# GTK dependencies
gtk3
gdk-pixbuf
pango
atk
cairo
adwaita-icon-theme
shared-mime-info
gsettings-desktop-schemas
# X11 libraries
xorg.libX11
xorg.libXcomposite
xorg.libXcursor
xorg.libXdamage
xorg.libXext
xorg.libXfixes
xorg.libXi
xorg.libXrandr
xorg.libXrender
xorg.libXtst
xorg.libxcb
alsa-lib
cups
dbus
expat
nspr
nss
libsecret
mesa
openssl
webkitgtk
corefonts
];
#extraBuildCommands = ''
# # Create symlinks for common GStreamer libraries
# mkdir -p $out/usr/lib
# ln -sf ${pkgs.gst-plugins-base}/lib/libgstvideo-1.0.so.0 $out/usr/lib/
# ln -sf ${pkgs.gst-plugins-base}/lib/libgstaudio-1.0.so.0 $out/usr/lib/
# ln -sf ${pkgs.gst-plugins-base}/lib/libgstapp-1.0.so.0 $out/usr/lib/
# ln -sf ${pkgs.gst-plugins-base}/lib/libgstpbutils-1.0.so.0 $out/usr/lib/
# ln -sf ${pkgs.gst-plugins-base}/lib/libgsttag-1.0.so.0 $out/usr/lib/
# ln -sf ${pkgs.gst-plugins-base}/lib/libgstfft-1.0.so.0 $out/usr/lib/
# ln -sf ${pkgs.gst-plugins-base}/lib/libgstrtp-1.0.so.0 $out/usr/lib/
# ln -sf ${pkgs.gst-plugins-base}/lib/libgstrtsp-1.0.so.0 $out/usr/lib/
# ln -sf ${pkgs.gst-plugins-base}/lib/libgstsdp-1.0.so.0 $out/usr/lib/
# ln -sf ${pkgs.gst-plugins-base}/lib/libgstgl-1.0.so.0 $out/usr/lib/
# ln -sf ${pkgs.gstreamer}/lib/libgstreamer-1.0.so.0 $out/usr/lib/
# ln -sf ${pkgs.gst-plugins-base}/lib/libgstallocators-1.0.so.0 $out/usr/lib/
#'';
runScript = extractAndRunScript;
meta = crealityprint-unwrapped.meta;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment