diff options
Diffstat (limited to 'modules/qmk.nix')
| -rw-r--r-- | modules/qmk.nix | 270 |
1 files changed, 270 insertions, 0 deletions
diff --git a/modules/qmk.nix b/modules/qmk.nix new file mode 100644 index 0000000..c892fc3 --- /dev/null +++ b/modules/qmk.nix @@ -0,0 +1,270 @@ +{ +lib, +pkgs, ... +}: +let + inherit (lib) mkOption types; + inherit (flake-parts-lib) mkPerSystemOption; +in { + options = { + firmware = { + type = mkOption { + type = types.enum [ "qmk" ]; + }; + + qmk_firmware = mkOption { + type = types.path; + default = pkgs.qmk_firmware; + description = '' + qmk firmware path + ''; + }; + + qmk = { + keyboard = { + name = mkOption { + type = types.str; + description = "keyboard path"; + example = "4pplet/steezy60"; + }; + + revision = mkOption { + type = types.nullOr types.str; + default = null; + description = "keyboard revision"; + example = "rev_a"; + }; + }; + + keymap = { + name = mkOption { + type = types.str; + default = "default"; + description = "keymap name"; + }; + + src = mkOption { + type = types.nullOr types.str; + 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}" + ''; + + 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.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}" + ''; + }; + }; +} +# 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}" +# ''; +# }; +# }; +# }); +# }; +# }; +# }; +# }; +# }); +# } |
