From 12a0f0409950c99bc611491f0635f8d0429fa56c Mon Sep 17 00:00:00 2001 From: matthewcroughan Date: Tue, 21 Apr 2026 16:13:20 +0100 Subject: [PATCH] klipper: fix cross runtime behavior --- pkgs/servers/klipper/default.nix | 37 +++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/pkgs/servers/klipper/default.nix b/pkgs/servers/klipper/default.nix index 2ac50f350bc8..559eb44f74f3 100644 --- a/pkgs/servers/klipper/default.nix +++ b/pkgs/servers/klipper/default.nix @@ -9,7 +9,9 @@ makeWrapper, writeShellScript, }: - +let + isCross = (stdenv.hostPlatform != stdenv.buildPlatform); +in stdenv.mkDerivation rec { pname = "klipper"; version = "0.13.0-unstable-2026-03-21"; @@ -46,11 +48,31 @@ stdenv.mkDerivation rec { )) ]; - # we need to run this to prebuild the chelper. - postBuild = '' - python ./chelper/__init__.py + # we need to run this to prebuild the chelper .so. However when cross + # compiling, a patch is temporarily required during the build process to + # prevent the build process from using dlopen() on this .so which has been + # built for a foreign architecture. We then place the unpatched __init__.py + # back, as this dlopen() call is required at runtime + postBuild = + if isCross then + '' + python ./chelper/__init__.py + mv ./chelper/__init__unpatched.py ./chelper/__init__.py + '' + else + '' + python ./chelper/__init__.py + ''; + + prePatch = lib.optionalString isCross '' + cp ./chelper/__init__.py ./chelper/__init__unpatched.py ''; + patches = lib.optionals isCross [ + # https://github.com/Klipper3d/klipper/pull/7254 + ./cross-ffi.patch + ]; + # Python 3 is already supported but shebangs aren't updated yet postPatch = '' for file in klippy.py console.py parsedump.py; do @@ -59,15 +81,10 @@ stdenv.mkDerivation rec { done # needed for cross compilation - substituteInPlace ./chelper/__init__.py \ + substituteInPlace ./chelper/__init__*.py \ --replace 'GCC_CMD = "gcc"' 'GCC_CMD = "${stdenv.cc.targetPrefix}cc"' ''; - patches = lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ - # https://github.com/Klipper3d/klipper/pull/7254 - ./cross-ffi.patch - ]; - pythonInterpreter = (python3.withPackages ( p: with p; [