Files
nixpkgs/pkgs/servers/klipper/klipper-flash.nix
Dark Steveneq 646b892680
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
push sheeet
2025-10-09 14:15:47 +02:00

54 lines
1.5 KiB
Nix

{
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
'';
}