klipper-firmware: Make runtimeInput conditional

+8 -11
+8 -11
pkgs/servers/klipper/klipper-flash.nix
··· 12 , firmwareConfig ? ./simulator.cfg 13 }: 14 let 15 - isNotSupported = with builtins; isNull (match ''^.*CONFIG_BOARD_DIRECTORY="(avr|stm32|lpc176x)".*$'' (readFile firmwareConfig)); 16 - isNotStm = with builtins; isNull (match ''^.*CONFIG_BOARD_DIRECTORY="(stm32)".*$'' (readFile firmwareConfig)); 17 in 18 writeShellApplication { 19 name = "klipper-flash-${mcu}"; 20 runtimeInputs = [ 21 python2 22 - avrdude 23 - stm32flash 24 pkgsCross.avr.stdenv.cc 25 gnumake 26 - ]; 27 text = '' 28 - NOT_SUPPORTED=${lib.boolToString isNotSupported} 29 - NOT_STM=${lib.boolToString isNotStm} 30 - if $NOT_SUPPORTED; then 31 printf "Flashing Klipper firmware to your board is not supported yet.\n" 32 printf "Please use the compiled firmware at ${klipper-firmware} and flash it using the tools provided for your microcontroller." 33 exit 1 34 fi 35 - if $NOT_STM; then 36 - make -C ${klipper.src} FLASH_DEVICE="${toString flashDevice}" OUT="${klipper-firmware}/" KCONFIG_CONFIG="${klipper-firmware}/config" flash 37 else 38 - make -C ${klipper.src} FLASH_DEVICE="${toString flashDevice}" OUT="${klipper-firmware}/" KCONFIG_CONFIG="${klipper-firmware}/config" serialflash 39 fi 40 ''; 41 }
··· 12 , firmwareConfig ? ./simulator.cfg 13 }: 14 let 15 + supportedArches = [ "avr" "stm32" "lpc176x" ]; 16 + matchBoard = with builtins; match ''^.*CONFIG_BOARD_DIRECTORY="([a-zA-Z0-9_]+)".*$'' (readFile firmwareConfig); 17 + boardArch = if matchBoard == null then null else builtins.head matchBoard; 18 in 19 writeShellApplication { 20 name = "klipper-flash-${mcu}"; 21 runtimeInputs = [ 22 python2 23 pkgsCross.avr.stdenv.cc 24 gnumake 25 + ] ++ lib.optionals (boardArch == "avr") [ avrdude ] ++ lib.optionals (boardArch == "stm32") [ stm32flash ]; 26 text = '' 27 + if ${lib.boolToString (!builtins.elem boardArch supportedArches)}; then 28 printf "Flashing Klipper firmware to your board is not supported yet.\n" 29 printf "Please use the compiled firmware at ${klipper-firmware} and flash it using the tools provided for your microcontroller." 30 exit 1 31 fi 32 + if ${lib.boolToString (boardArch == "stm32")}; then 33 + make -C ${klipper.src} FLASH_DEVICE="${toString flashDevice}" OUT="${klipper-firmware}/" KCONFIG_CONFIG="${klipper-firmware}/config" serialflash 34 else 35 + make -C ${klipper.src} FLASH_DEVICE="${toString flashDevice}" OUT="${klipper-firmware}/" KCONFIG_CONFIG="${klipper-firmware}/config" flash 36 fi 37 ''; 38 }