push sheeet
Some checks failed
Periodic Merges (6h) / master → staging-nixos (push) Failing after 12m50s
Periodic Merges (6h) / master → staging-next (push) Failing after 12m54s
Periodic Merges (24h) / merge-base(master,staging) → haskell-updates (push) Failing after 11m54s
Periodic Merges (6h) / staging-next → staging (push) Failing after 12m13s
Periodic Merges (24h) / staging-next-25.05 → staging-25.05 (push) Failing after 13m24s
Periodic Merges (24h) / release-25.05 → staging-next-25.05 (push) Failing after 14m28s

This commit is contained in:
Dark Steveneq
2025-10-09 14:15:47 +02:00
commit 646b892680
49168 changed files with 5897842 additions and 0 deletions

View File

@@ -0,0 +1,125 @@
{
stdenv,
lib,
fetchFromGitHub,
python3,
extraPythonPackages ? ps: [ ],
unstableGitUpdater,
makeWrapper,
writeShellScript,
}:
stdenv.mkDerivation rec {
pname = "klipper";
version = "0.13.0-unstable-2025-09-26";
src = fetchFromGitHub {
owner = "KevinOConnor";
repo = "klipper";
rev = "af17c8c238ba8cdeaaabb87b25a3ca2375b47c11";
sha256 = "sha256-n3t58gsPXxlf2DnrofI28/0ZRC4EwnZvoFKxgxZ9vYA=";
};
sourceRoot = "${src.name}/klippy";
# NB: This is needed for the postBuild step
nativeBuildInputs = [
(python3.withPackages (p: with p; [ cffi ]))
makeWrapper
];
buildInputs = [
(python3.withPackages (
p:
with p;
[
python-can
cffi
pyserial
greenlet
jinja2
markupsafe
numpy
]
++ extraPythonPackages p
))
];
# we need to run this to prebuild the chelper.
postBuild = ''
python ./chelper/__init__.py
'';
# Python 3 is already supported but shebangs aren't updated yet
postPatch = ''
for file in klippy.py console.py parsedump.py; do
substituteInPlace $file \
--replace '/usr/bin/env python2' '/usr/bin/env python'
done
# needed for cross compilation
substituteInPlace ./chelper/__init__.py \
--replace 'GCC_CMD = "gcc"' 'GCC_CMD = "${stdenv.cc.targetPrefix}cc"'
'';
pythonInterpreter =
(python3.withPackages (
p: with p; [
numpy
matplotlib
]
)).interpreter;
pythonScriptWrapper = writeShellScript pname ''
${pythonInterpreter} "@out@/lib/scripts/@script@" "$@"
'';
# NB: We don't move the main entry point into `/bin`, or even symlink it,
# because it uses relative paths to find necessary modules. We could wrap but
# this is used 99% of the time as a service, so it's not worth the effort.
installPhase = ''
runHook preInstall
mkdir -p $out/lib/klipper
cp -r ./* $out/lib/klipper
# Moonraker expects `config_examples` and `docs` to be available
# under `klipper_path`
cp -r $src/docs $out/lib/docs
cp -r $src/config $out/lib/config
cp -r $src/scripts $out/lib/scripts
cp -r $src/klippy $out/lib/klippy
# Add version information. For the normal procedure see https://www.klipper3d.org/Packaging.html#versioning
# This is done like this because scripts/make_version.py is not available when sourceRoot is set to "${src.name}/klippy"
echo "${version}-NixOS" > $out/lib/klipper/.version
mkdir -p $out/bin
chmod 755 $out/lib/klipper/klippy.py
makeWrapper $out/lib/klipper/klippy.py $out/bin/klippy --chdir $out/lib/klipper
substitute "$pythonScriptWrapper" "$out/bin/klipper-calibrate-shaper" \
--subst-var "out" \
--subst-var-by "script" "calibrate_shaper.py"
chmod 755 "$out/bin/klipper-calibrate-shaper"
runHook postInstall
'';
passthru.updateScript = unstableGitUpdater {
url = meta.homepage;
tagPrefix = "v";
};
meta = with lib; {
description = "Klipper 3D printer firmware";
mainProgram = "klippy";
homepage = "https://github.com/KevinOConnor/klipper";
maintainers = with maintainers; [
lovesegfault
zhaofengli
cab404
];
platforms = platforms.linux;
license = licenses.gpl3Only;
};
}

View File

@@ -0,0 +1,119 @@
args@{
klipper-firmware,
stdenv,
lib,
pkg-config,
pkgsCross,
bintools-unwrapped,
libffi,
libusb1,
wxGTK32,
python3,
gcc-arm-embedded,
klipper,
avrdude,
stm32flash,
klipper-flash,
mcu ? "mcu",
firmwareConfig ? ./simulator.cfg,
}:
# are used by flash scripts
# find those with `rg '\[\"lib'` inside of klipper repo
let
flashBinaries = [
"lib/bossac/bin/bossac"
"lib/hidflash/hid-flash"
"lib/rp2040_flash/rp2040_flash"
];
in
stdenv.mkDerivation rec {
name = "klipper-firmware-${mcu}-${version}";
version = klipper.version;
src = klipper.src;
nativeBuildInputs = [
python3
pkgsCross.avr.stdenv.cc
gcc-arm-embedded
bintools-unwrapped
libffi
libusb1
avrdude
stm32flash
pkg-config
wxGTK32 # Required for bossac
];
configurePhase = ''
cp ${firmwareConfig} ./.config
chmod +w ./.config
echo qy | { make menuconfig >/dev/null || true; }
if ! diff ${firmwareConfig} ./.config; then
echo " !!! Klipper KConfig has changed. Please run klipper-genconf to update your configuration."
fi
'';
postPatch = ''
patchShebangs .
'';
postBuild = ''
# build flash binaries
${with builtins; concatStringsSep "\n" (map (path: "make ${path} $out/bin/ || true") flashBinaries)}
'';
makeFlags = [
"V=1"
"WXVERSION=3.2"
];
installPhase = ''
mkdir -p $out
cp ./.config $out/config
cp out/klipper.bin $out/ || true
cp out/klipper.elf $out/ || true
cp out/klipper.uf2 $out/ || true
mkdir -p $out/lib/
${
with builtins;
concatStringsSep "\n" (
map (path: ''
if [ -e ${path} ]; then
mkdir -p $out/$(dirname ${path})
cp -r ${path} $out/$(dirname ${path})
fi
'') flashBinaries
)
}
rmdir $out/lib 2>/dev/null || echo "Flash binaries exist, not cleaning up lib/"
'';
dontFixup = true;
passthru = {
makeFlasher =
{ flashDevice }:
klipper-flash.override {
klipper-firmware = klipper-firmware.override args;
inherit
klipper
firmwareConfig
mcu
flashDevice
;
};
};
meta = with lib; {
inherit (klipper.meta) homepage license;
description = "Firmware part of Klipper";
maintainers = with maintainers; [
vtuan10
cab404
];
platforms = platforms.linux;
};
}

View File

@@ -0,0 +1,53 @@
{
lib,
writeShellApplication,
klipper,
klipper-firmware,
avrdude,
dfu-util,
stm32flash,
mcu ? "mcu",
flashDevice ? "/dev/null",
firmwareConfig ? ./simulator.cfg,
}:
let
getConfigField =
field:
with builtins;
let
matches = match ''^.*${field}="([a-zA-Z0-9_]+)".*$'' (readFile firmwareConfig);
in
if matches != null then head matches else null;
matchPlatform = getConfigField "CONFIG_BOARD_DIRECTORY";
matchBoard = getConfigField "CONFIG_MCU";
in
writeShellApplication {
name = "klipper-flash-${mcu}";
runtimeInputs =
[ ]
++ lib.optionals (matchPlatform == "avr") [ avrdude ]
++ lib.optionals (matchPlatform == "stm32") [
stm32flash
dfu-util
]
++ lib.optionals (matchPlatform == "lpc176x") [ dfu-util ]
# bossac, hid-flash and RP2040 flash binaries are built by klipper-firmware
;
text =
# generic USB script for most things with serial and bootloader (see MCU_TYPES in scripts/flash_usb.py)
if matchBoard != null && matchPlatform != null then
''
pushd ${klipper-firmware}
${klipper}/lib/scripts/flash_usb.py -t ${matchBoard} -d ${flashDevice} ${klipper-firmware}/klipper.bin "$@"
popd
''
else
''
cat <<EOF
Board pair ${toString matchBoard}/${toString matchPlatform} (config ${firmwareConfig}) is not supported in NixOS auto flashing script.
Please manually flash the firmware using the appropriate tool for your board.
Built firmware is located here:
${klipper-firmware}
EOF
'';
}

View File

@@ -0,0 +1,21 @@
{
writeShellApplication,
klipper,
python3,
gnumake,
}:
writeShellApplication {
name = "klipper-genconf";
runtimeInputs = [
python3
gnumake
];
text = ''
CURRENT_DIR=$(pwd)
TMP=$(mktemp -d)
make -C ${klipper.src} OUT="$TMP" KCONFIG_CONFIG="$CURRENT_DIR/config" menuconfig
rm -rf "$TMP" config.old
printf "\nYour firmware configuration for klipper:\n\n"
cat config
'';
}

View File

@@ -0,0 +1,43 @@
# CONFIG_LOW_LEVEL_OPTIONS is not set
# CONFIG_MACH_AVR is not set
# CONFIG_MACH_ATSAM is not set
# CONFIG_MACH_ATSAMD is not set
# CONFIG_MACH_LPC176X is not set
# CONFIG_MACH_STM32 is not set
# CONFIG_MACH_HC32F460 is not set
# CONFIG_MACH_RPXXXX is not set
# CONFIG_MACH_PRU is not set
# CONFIG_MACH_AR100 is not set
# CONFIG_MACH_LINUX is not set
CONFIG_MACH_SIMU=y
CONFIG_BOARD_DIRECTORY="simulator"
CONFIG_CLOCK_FREQ=20000000
CONFIG_SERIAL=y
CONFIG_SIMULATOR_SELECT=y
CONFIG_SERIAL_BAUD=250000
CONFIG_USB_VENDOR_ID=0x1d50
CONFIG_USB_DEVICE_ID=0x614e
CONFIG_USB_SERIAL_NUMBER="12345"
CONFIG_WANT_ADC=y
CONFIG_WANT_SPI=y
CONFIG_WANT_SOFTWARE_SPI=y
CONFIG_WANT_HARD_PWM=y
CONFIG_WANT_BUTTONS=y
CONFIG_WANT_TMCUART=y
CONFIG_WANT_NEOPIXEL=y
CONFIG_WANT_PULSE_COUNTER=y
CONFIG_WANT_ST7920=y
CONFIG_WANT_HD44780=y
CONFIG_WANT_ADXL345=y
CONFIG_WANT_LIS2DW=y
CONFIG_WANT_THERMOCOUPLE=y
CONFIG_WANT_HX71X=y
CONFIG_WANT_ADS1220=y
CONFIG_WANT_SENSOR_ANGLE=y
CONFIG_NEED_SENSOR_BULK=y
CONFIG_CANBUS_FREQUENCY=1000000
CONFIG_INLINE_STEPPER_HACK=y
CONFIG_HAVE_GPIO=y
CONFIG_HAVE_GPIO_ADC=y
CONFIG_HAVE_GPIO_SPI=y
CONFIG_HAVE_GPIO_HARD_PWM=y