From 7aa390883104725c64c65d20a0713cfcd654f637 Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Tue, 21 Oct 2025 10:38:26 -0500 Subject: More correct dfu-util flash script + rearranged personal devices --- modules/default.nix | 2 ++ modules/klipper.nix | 42 ++++++++++++++++++++++++++++++++++++++++++ modules/pinecil.nix | 10 ++++++---- modules/qmk.nix | 32 +++++++++++++++++++------------- 4 files changed, 69 insertions(+), 17 deletions(-) create mode 100644 modules/klipper.nix (limited to 'modules') diff --git a/modules/default.nix b/modules/default.nix index dea6fb3..fbed630 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -48,6 +48,8 @@ in { }) ./qmk.nix + ./pinecil.nix + ./klipper.nix ]; }; diff --git a/modules/klipper.nix b/modules/klipper.nix new file mode 100644 index 0000000..2782bcd --- /dev/null +++ b/modules/klipper.nix @@ -0,0 +1,42 @@ +{ + lib, + pkgs, + config, + ... +}: +let + inherit (lib) mkOption mkIf mkPackageOption types; +in { + options = { + type = mkOption { + type = types.enum [ "klipper" ]; + }; + + klipper = { + klipper-firmware = mkPackageOption pkgs "klipper-firmware" {}; + + mcu = mkOption { + type = types.str; + }; + + firmwareConfig = mkOption { + type = types.path; + }; + + build = { + bin = mkOption { + type = types.path; + default = "${config.klipper.klipper-firmware.override { + inherit (config.klipper) mcu firmwareConfig; + }}/klipper.bin"; + }; + flash = mkOption { + type = types.functionTo <| types.either types.str types.package; + }; + }; + }; + }; + + config = mkIf (config.type == "klipper") { + }; +} diff --git a/modules/pinecil.nix b/modules/pinecil.nix index d59c37d..137de94 100644 --- a/modules/pinecil.nix +++ b/modules/pinecil.nix @@ -2,7 +2,9 @@ inherit (lib) mkOption mkPackageOption mkIf types; in { options = { - type = types.enum [ "pinecil" ]; + type = mkOption { + type = types.enum [ "pinecil" ]; + }; pinecil = { version = mkOption { @@ -36,7 +38,7 @@ in { '' else '' cp ${iron}/Pinecilv2_EN.bin $out - ''; + '' ); }; @@ -48,10 +50,10 @@ in { build.flash = let flasher = if config.pinecil.version == "v1" then { pkg = config.pinecil.dfu-util; - tool = "dfu-util"; + tool = "dfu-util -D"; } else { pkg = config.pinecil.blisp; - tool = "blisp" + tool = "blisp write -c bl70x --reset"; }; in pkgs.writeShellApplication { name = "flash"; diff --git a/modules/qmk.nix b/modules/qmk.nix index c083b06..3834369 100644 --- a/modules/qmk.nix +++ b/modules/qmk.nix @@ -73,6 +73,8 @@ in { name = "qmk:${config.qmk.keyboard._path}:${config.qmk.keymap.name}"; src = config.qmk.qmk_firmware; + allowSubstitutes = false; + # hardeningDisable = [ "pic" "pie" ]; nativeBuildInputs = [ @@ -81,22 +83,23 @@ in { # dontFixup = true; - preBuild = lib.optionalString (ksrc != null) '' + postPatch = lib.optionalString (ksrc != null) /* bash */ '' mkdir -pv "${config.qmk.keymap._path}" cp -v "${ksrc}"/* "${config.qmk.keymap._path}" ''; - buildPhase = '' - # SKIP_GIT=true BUILD_DIR=build \ - # make "${config.qmk.keyboard._path}:${config.qmk.keymap.name}" - qmk compile \ - --env SKIP_GIT=yes \ - --env BUILD_DIR=build \ - --env SKIP_VERSION=yes \ - --env VERBOSE=true \ - --env ALLOW_WARNINGS=yes \ - --keyboard "${config.qmk.keyboard._path}" \ - --keymap "${config.qmk.keymap.name}" + buildPhase = /* bash */ '' + runHook preBuild + + qmk compile \ + --env SKIP_GIT=yes \ + --env BUILD_DIR=build \ + --env SKIP_VERSION=yes \ + --env VERBOSE=true \ + --keyboard "${config.qmk.keyboard._path}" \ + --keymap "${config.qmk.keymap.name}" + + runHook postBuild ''; installPhase = '' @@ -108,7 +111,10 @@ in { }; }; flash = mkOption { - type = types.functionTo (types.either types.package types.str); + type = types.functionTo <| types.either types.package types.str; + default = hex: '' + "${pkgs.dfu-util}/bin/dfu-util" --alt 0 --dfuse-address 0x08000000:leave -D "${hex}.hex" + ''; }; }; -- cgit v1.2.3