9 stdenv.mkDerivation rec {
11 version = "0.12.0-unstable-2024-07-05";
13 src = fetchFromGitHub {
14 owner = "KevinOConnor";
16 rev = "00cb683def53be4b437bfb3e3a637d2d5879946c";
17 sha256 = "sha256-OtFUEhCZ8DrDfxKXYnLE/6/d2/4oyJYwSfKvsvbn/II=";
20 sourceRoot = "${src.name}/klippy";
22 # NB: This is needed for the postBuild step
24 (python3.withPackages ( p: with p; [ cffi ] ))
28 buildInputs = [ (python3.withPackages (p: with p; [ can cffi pyserial greenlet jinja2 markupsafe numpy ])) ];
30 # we need to run this to prebuild the chelper.
32 python ./chelper/__init__.py
35 # Python 3 is already supported but shebangs aren't updated yet
37 for file in klippy.py console.py parsedump.py; do
38 substituteInPlace $file \
39 --replace '/usr/bin/env python2' '/usr/bin/env python'
42 # needed for cross compilation
43 substituteInPlace ./chelper/__init__.py \
44 --replace 'GCC_CMD = "gcc"' 'GCC_CMD = "${stdenv.cc.targetPrefix}cc"'
47 # NB: We don't move the main entry point into `/bin`, or even symlink it,
48 # because it uses relative paths to find necessary modules. We could wrap but
49 # this is used 99% of the time as a service, so it's not worth the effort.
52 mkdir -p $out/lib/klipper
53 cp -r ./* $out/lib/klipper
55 # Moonraker expects `config_examples` and `docs` to be available
56 # under `klipper_path`
57 cp -r $src/docs $out/lib/docs
58 cp -r $src/config $out/lib/config
60 # Add version information. For the normal procedure see https://www.klipper3d.org/Packaging.html#versioning
61 # This is done like this because scripts/make_version.py is not available when sourceRoot is set to "${src.name}/klippy"
62 echo "${version}-NixOS" > $out/lib/klipper/.version
65 chmod 755 $out/lib/klipper/klippy.py
66 makeWrapper $out/lib/klipper/klippy.py $out/bin/klippy --chdir $out/lib/klipper
70 passthru.updateScript = unstableGitUpdater {
76 description = "Klipper 3D printer firmware";
77 mainProgram = "klippy";
78 homepage = "https://github.com/KevinOConnor/klipper";
79 maintainers = with maintainers; [ lovesegfault zhaofengli cab404 ];
80 platforms = platforms.linux;
81 license = licenses.gpl3Only;