Merge pull request #243475 from vtuan10/enable-klipper-flash

nixos/klipper: add enableKlipperFlash option
This commit is contained in:
Sandro 2023-07-15 02:54:47 +02:00 committed by GitHub
commit 545f079f5e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -111,8 +111,11 @@ in
(submodule { (submodule {
options = { options = {
enable = mkEnableOption (lib.mdDoc '' enable = mkEnableOption (lib.mdDoc ''
building of firmware and addition of klipper-flash tools for manual flashing. building of firmware for manual flashing.
This will add `klipper-flash-$mcu` scripts to your environment which can be called to flash the firmware. '');
enableKlipperFlash = mkEnableOption (lib.mdDoc ''
flashings scripts for firmware. This will add `klipper-flash-$mcu` scripts to your environment which can be called to flash the firmware.
Please check the configs at [klipper](https://github.com/Klipper3d/klipper/tree/master/config) whether your board supports flashing via `make flash`.
''); '');
serial = mkOption { serial = mkOption {
type = types.nullOr path; type = types.nullOr path;
@ -213,11 +216,14 @@ in
with pkgs; with pkgs;
let let
default = a: b: if a != null then a else b; default = a: b: if a != null then a else b;
firmwares = filterAttrs (n: v: v!= null) (mapAttrs firmwares = filterAttrs (n: v: v != null) (mapAttrs
(mcu: { enable, configFile, serial }: if enable then pkgs.klipper-firmware.override { (mcu: { enable, enableKlipperFlash, configFile, serial }:
mcu = lib.strings.sanitizeDerivationName mcu; if enable then
firmwareConfig = configFile; pkgs.klipper-firmware.override
} else null) {
mcu = lib.strings.sanitizeDerivationName mcu;
firmwareConfig = configFile;
} else null)
cfg.firmwares); cfg.firmwares);
firmwareFlasher = mapAttrsToList firmwareFlasher = mapAttrsToList
(mcu: firmware: pkgs.klipper-flash.override { (mcu: firmware: pkgs.klipper-flash.override {
@ -226,7 +232,7 @@ in
flashDevice = default cfg.firmwares."${mcu}".serial cfg.settings."${mcu}".serial; flashDevice = default cfg.firmwares."${mcu}".serial cfg.settings."${mcu}".serial;
firmwareConfig = cfg.firmwares."${mcu}".configFile; firmwareConfig = cfg.firmwares."${mcu}".configFile;
}) })
firmwares; (filterAttrs (mcu: firmware: cfg.firmwares."${mcu}".enableKlipperFlash) firmwares);
in in
[ klipper-genconf ] ++ firmwareFlasher ++ attrValues firmwares; [ klipper-genconf ] ++ firmwareFlasher ++ attrValues firmwares;
}; };