aboutsummaryrefslogtreecommitdiff
path: root/modules/qmk.nix
diff options
context:
space:
mode:
Diffstat (limited to 'modules/qmk.nix')
-rw-r--r--modules/qmk.nix295
1 files changed, 77 insertions, 218 deletions
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}"
-# '';
-# };
-# };
-# });
-# };
-# };
-# };
-# };
-# });
-# }