10 stdenv.mkDerivation rec {
12 version = "0.12.0-unstable-2024-10-01";
14 src = fetchFromGitHub {
15 owner = "KevinOConnor";
17 rev = "96cceed23efc7a3759ecfba0a228cdcb4d5244d3";
18 sha256 = "sha256-rnbCtOlODPnpb5o6hG8QBdZnsmO8H5NhUeHkYIVYKoA=";
21 sourceRoot = "${src.name}/klippy";
23 # NB: This is needed for the postBuild step
25 (python3.withPackages ( p: with p; [ cffi ] ))
29 buildInputs = [ (python3.withPackages (p: with p; [ python-can cffi pyserial greenlet jinja2 markupsafe numpy ])) ];
31 # we need to run this to prebuild the chelper.
33 python ./chelper/__init__.py
36 # Python 3 is already supported but shebangs aren't updated yet
38 for file in klippy.py console.py parsedump.py; do
39 substituteInPlace $file \
40 --replace '/usr/bin/env python2' '/usr/bin/env python'
43 # needed for cross compilation
44 substituteInPlace ./chelper/__init__.py \
45 --replace 'GCC_CMD = "gcc"' 'GCC_CMD = "${stdenv.cc.targetPrefix}cc"'
49 (python3.withPackages (
56 pythonScriptWrapper = writeShellScript pname ''
57 ${pythonInterpreter} "@out@/lib/scripts/@script@" "$@"
60 # NB: We don't move the main entry point into `/bin`, or even symlink it,
61 # because it uses relative paths to find necessary modules. We could wrap but
62 # this is used 99% of the time as a service, so it's not worth the effort.
65 mkdir -p $out/lib/klipper
66 cp -r ./* $out/lib/klipper
68 # Moonraker expects `config_examples` and `docs` to be available
69 # under `klipper_path`
70 cp -r $src/docs $out/lib/docs
71 cp -r $src/config $out/lib/config
72 cp -r $src/scripts $out/lib/scripts
73 cp -r $src/klippy $out/lib/klippy
75 # Add version information. For the normal procedure see https://www.klipper3d.org/Packaging.html#versioning
76 # This is done like this because scripts/make_version.py is not available when sourceRoot is set to "${src.name}/klippy"
77 echo "${version}-NixOS" > $out/lib/klipper/.version
80 chmod 755 $out/lib/klipper/klippy.py
81 makeWrapper $out/lib/klipper/klippy.py $out/bin/klippy --chdir $out/lib/klipper
83 substitute "$pythonScriptWrapper" "$out/bin/klipper-calibrate-shaper" \
85 --subst-var-by "script" "calibrate_shaper.py"
86 chmod 755 "$out/bin/klipper-calibrate-shaper"
91 passthru.updateScript = unstableGitUpdater {
97 description = "Klipper 3D printer firmware";
98 mainProgram = "klippy";
99 homepage = "https://github.com/KevinOConnor/klipper";
100 maintainers = with maintainers; [ lovesegfault zhaofengli cab404 ];
101 platforms = platforms.linux;
102 license = licenses.gpl3Only;