diff options
| author | Chris Wells <chris@mathematicaster.org> | 2025-10-18 00:27:05 -0500 |
|---|---|---|
| committer | Chris Wells <chris@mathematicaster.org> | 2025-10-18 00:27:05 -0500 |
| commit | 22720e4a4ca088bb80dcded6667cec1f5becc0f4 (patch) | |
| tree | a454918dbd366ec97b74352d8596e4a1f6bb186d /modules | |
| parent | bf9ccc339a2da236afdbad0fe63eb0c9bcb74d7e (diff) | |
| download | fw-manager-22720e4a4ca088bb80dcded6667cec1f5becc0f4.tar fw-manager-22720e4a4ca088bb80dcded6667cec1f5becc0f4.tar.gz fw-manager-22720e4a4ca088bb80dcded6667cec1f5becc0f4.tar.bz2 fw-manager-22720e4a4ca088bb80dcded6667cec1f5becc0f4.tar.lz fw-manager-22720e4a4ca088bb80dcded6667cec1f5becc0f4.tar.xz fw-manager-22720e4a4ca088bb80dcded6667cec1f5becc0f4.tar.zst fw-manager-22720e4a4ca088bb80dcded6667cec1f5becc0f4.zip | |
qmk seems to be mostly working. Now working on pinecil
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/default.nix | 18 | ||||
| -rw-r--r-- | modules/pinecil.nix | 64 | ||||
| -rw-r--r-- | modules/qmk.nix | 295 |
3 files changed, 150 insertions, 227 deletions
diff --git a/modules/default.nix b/modules/default.nix index c1c2646..dea6fb3 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -12,23 +12,23 @@ in { # ]; options.perSystem = mkPerSystemOption ({ pkgs, system, config, ... }: { - # options.firmware = mkOption { - # default = {}; - # type = types.submodule { - # options = { - options.devices = mkOption { default = {}; type = types.lazyAttrsOf <| types.submoduleWith { shorthandOnlyDefinesConfig = true; modules = [ - ({ name, ... }: { + { _module.args = { - inherit pkgs lib flake-parts-lib; + inherit pkgs lib; }; + } + ({ name, ... }: { + # _module.args = { + # inherit pkgs lib flake-parts-lib; + # }; options = { enable = mkEnableOption name // { default = true; }; - firmware.type = mkOption { + type = mkOption { type = types.enum [ ]; description = '' Firmware type. Extensible for other firmwares. @@ -47,7 +47,7 @@ in { }; }) - ./qmk + ./qmk.nix ]; }; diff --git a/modules/pinecil.nix b/modules/pinecil.nix new file mode 100644 index 0000000..d59c37d --- /dev/null +++ b/modules/pinecil.nix @@ -0,0 +1,64 @@ +{ lib, pkgs, config, ... }: let + inherit (lib) mkOption mkPackageOption mkIf types; +in { + options = { + type = types.enum [ "pinecil" ]; + + pinecil = { + version = mkOption { + type = types.enum [ "v1" "v2" ]; + description = "v1 or v2?"; + }; + + iron-os = mkOption { + type = types.path; + default = let + v = "2.23"; + in if config.pinecil.version == "v1" + then pkgs.fetchzip { + url = "https://github.com/Ralim/IronOS/releases/download/v${v}/Pinecil.zip"; + } else pkgs.fetchzip { + url = "https://github.com/Ralim/IronOS/releases/download/v${v}/PinecilV2.zip"; + }; + }; + + blisp = mkPackageOption pkgs "blisp" {}; + dfu = mkPackageOption pkgs "dfu-util" {}; + + build = { + bin = mkOption { + type = types.path; + default = pkgs.runCommandLocal "getbin" {} (let + iron = config.pinecil.iron-os; + in if config.pinecil.version == "v1" + then '' + cp ${iron}/Pinecil_EN.dfu $out + '' + else '' + cp ${iron}/Pinecilv2_EN.bin $out + ''; + ); + + }; + }; + }; + }; + + config = mkIf (config.type == "pinecil") { + build.flash = let + flasher = if config.pinecil.version == "v1" then { + pkg = config.pinecil.dfu-util; + tool = "dfu-util"; + } else { + pkg = config.pinecil.blisp; + tool = "blisp" + }; + in pkgs.writeShellApplication { + name = "flash"; + runtimeInputs = [ flasher.pkg ]; + text = '' + ${flasher.tool} "${config.pinecil.build.bin}" + ''; + }; + }; +} diff --git a/modules/qmk.nix b/modules/qmk.nix index c892fc3..6288d7e 100644 --- a/modules/qmk.nix +++ b/modules/qmk.nix @@ -1,26 +1,26 @@ { lib, -pkgs, ... +pkgs, +config, +... }: let - inherit (lib) mkOption types; - inherit (flake-parts-lib) mkPerSystemOption; + inherit (lib) mkOption mkIf types; in { - options = { - firmware = { + options = { type = mkOption { type = types.enum [ "qmk" ]; }; - qmk_firmware = mkOption { - type = types.path; - default = pkgs.qmk_firmware; - description = '' - qmk firmware path - ''; - }; qmk = { + qmk_firmware = mkOption { + type = types.path; + default = pkgs.qmk_firmware; + description = '' + qmk firmware path + ''; + }; keyboard = { name = mkOption { type = types.str; @@ -34,6 +34,12 @@ in { description = "keyboard revision"; example = "rev_a"; }; + + _path = mkOption { + type = types.str; + internal = true; + default = lib.concatStringsSep "/" ([config.qmk.keyboard.name] ++ lib.optional (config.qmk.keyboard.revision != null) config.qmk.keyboard.revision); + }; }; keymap = { @@ -44,227 +50,80 @@ in { }; src = mkOption { - type = types.nullOr types.str; + type = types.nullOr types.path; default = null; description = "qmk keymap files"; }; - }; - - build = { - bin = mkOption { - type = type.path; - internal = true; - readOnly = true; - default = let - ksrc = config.firmware.qmk_firmware; - in pkgs.stdenv.mkDerivation { - name = "qmk:${config.qmk.keyboard._path}:${config.qmk.keymap.name}"; - srcs = [ - { - name = "qmk_firmware"; - src = config.qmk_firmware; - } - ] ++ lib.optional (ksrc != null) { - name = "keymap"; - src = ksrc; - }; - - sourceRoot = "qmk_firmware"; - - nativeBuildImports = [ - pkgs.qmk - ]; - dontFixup = true; - - postUnpack = lib.optionalString (ksrc != null) '' - mkdir -pv "${config.qmk.keymap._path}" - cp -rv $keymap/* "${config.qmk.keymap._path}" - ''; + _path = mkOption { + type = types.str; + internal = true; + default = "keyboards/${config.qmk.keyboard.name}/keymaps/${config.qmk.keymap.name}"; + }; + }; - buildPhase = '' + build = { + bin = mkOption { + type = types.path; + internal = true; + readOnly = true; + default = let + ksrc = config.qmk.keymap.src; + in pkgs.stdenv.mkDerivation { + name = "qmk:${config.qmk.keyboard._path}:${config.qmk.keymap.name}"; + src = config.qmk.qmk_firmware; + # { + # name = "qmk_firmware"; + # src = config.qmk.qmk_firmware; + # } + # ] ++ lib.optional (ksrc != null) { + # name = "keymap"; + # src = ksrc; + # }; + # + # sourceRoot = "qmk_firmware"; + + nativeBuildInputs = [ + pkgs.qmk + ]; + + dontFixup = true; + + preConfigure = lib.optionalString (ksrc != null) '' + 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=true \ --env BUILD_DIR=build \ - --env TARGET=fw \ - --keyboard ${config.qmk.keyboard._path} \ - --keymap ${config.qmk.keymap.name} - ''; + --keyboard "${config.qmk.keyboard._path}" \ + --keymap "${config.qmk.keymap.name}" + ''; - installPhase = '' - mkdir -p $out - cp -v build/*.{bin,hex,elf,dfu,uf2,eep} $out/ - ''; + installPhase = '' + mkdir -p $out + cp -v build/*.{bin,hex,elf,dfu,uf2,eep} $out + ''; - }; - flash = mkOption { - type = types.either types.package types.str; }; - - }; }; + flash = mkOption { + type = types.functionTo (types.either types.package types.str); + }; + + }; }; }; - }; - config = { - build.flash = pkgs.symlinkJoin { - name = "flash"; - nativeBuildInputs = [ pkgs.wrapProgram ]; - paths = if builtins.isPackage config.qmk.build.flash - then [ config.qmk.build.flash ] - else [(pkgs.writeShellApplication { - name = "flash"; - text = config.qmk.build.flash - })]; - postBuild = '' - wrapProgram $out/bin/flash --set-arg "''${config.qmk.build.bin}" - ''; - }; + config = mkIf (config.type == "qmk") { + build.flash = let + p = lib.replaceStrings [ "/" ":" ] [ "_" "_" ] "${config.qmk.keyboard._path}:${config.qmk.keymap.name}"; + n = config.qmk.build.flash "${builtins.toString config.qmk.build.bin}/${p}"; + in if builtins.isString n then pkgs.writeShellApplication { name = "flash"; text = n; } else n; }; } -# options.perSystem = mkPerSystemOption ({ pkgs, system, config', ... }: { -# options.firmware = mkOption { -# type = (f: types.submoduleWith { shorthandOnlyDefinesConfig = true; modules = [ f ]; }) { -# options = { -# qmk_firmware = mkOption { -# type = types.path; -# default = pkgs.qmk_firmware; -# description = "Default qmk_firmware to use"; -# }; -# -# devices = mkOption { -# type = types.attrsOf <| types.submodule ({ config, ... }: { -# options = { -# firmware = { -# type = mkOption { -# type = types.enum [ "qmk" ]; -# }; -# -# qmk_firmware = mkOption { -# type = types.path; -# default = config'.kbdConfigurations.qmk_firmware; -# description = "qmk_firmware to use"; -# }; -# }; -# -# qmk = { -# keyboard = { -# name = mkOption { -# type = types.str; -# description = "path to keyboard"; -# example = "4pplet/steezy60"; -# }; -# -# revision = mkOption { -# type = types.nullOr types.str; -# description = "keyboard revision"; -# example = "rev_a"; -# }; -# -# _basePath = mkOption { -# type = types.str; -# internal = true; -# default = config.qmk.keyboard.name; -# }; -# -# _path = mkOption { -# type = types.str; -# internal = true; -# default = lib.concatStringsSep "/" ([config.qmk.keyboard.basePath] ++ lib.optional (config.qmk.keyboard.revision != null) config.qmk.keyboard.revision); -# }; -# -# }; -# -# keymap = { -# name = mkOption { -# type = types.str; -# default = "default"; -# example = "default"; -# }; -# -# _path = mkOption { -# type = types.str; -# default = "${config.qmk.keyboard._basePath}/keymaps/${config.qmk.keymap.name}"; -# internal = true; -# }; -# -# src = mkOption { -# type = types.nullOr types.path; -# default = null; -# }; -# }; -# -# build = { -# bin = mkOption { -# type = types.path; -# default = let -# ksrc = config.qmk.keymap.src; -# in pkgs.stdenv.mkDerivation { -# name = "qmk:${config.qmk.keyboard._path}:${config.qmk.keymap.name}"; -# srcs = [ -# { -# name = "qmk_firmware"; -# src = config.qmk_firmware; -# } -# ] ++ lib.optional (ksrc != null) { -# name = "keymap"; -# src = ksrc; -# }; -# -# sourceRoot = "qmk_firmware"; -# -# nativeBuildImports = [ -# pkgs.qmk -# ]; -# -# dontFixup = true; -# -# postUnpack = lib.optionalString (ksrc != null) '' -# mkdir -pv "${config.qmk.keymap._path}" -# cp -rv $keymap/* "${config.qmk.keymap._path}" -# ''; -# -# buildPhase = '' -# qmk compile \ -# --env SKIP_GIT=true \ -# --env BUILD_DIR=build \ -# --env TARGET=fw \ -# --keyboard ${config.qmk.keyboard._path} \ -# --keymap ${config.qmk.keymap.name} -# ''; -# -# installPhase = '' -# mkdir -p $out -# cp -v build/*.{bin,hex,elf,dfu,uf2,eep} $out/ -# ''; -# -# -# }; -# }; -# -# flash = mkOption { -# type = types.package; -# }; -# }; -# -# }; -# -# }; -# -# config = { -# build.flash = pkgs.writeShellApplication { -# name = "flash"; -# text = '' -# exec "''${lib.getExe config.qmk.build.flash}" "${config.qmk.build.bin}" -# ''; -# }; -# }; -# }); -# }; -# }; -# }; -# }; -# }); -# } |
