diff options
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/default.nix | 169 | ||||
| -rw-r--r-- | modules/qmk.nix | 270 |
2 files changed, 315 insertions, 124 deletions
diff --git a/modules/default.nix b/modules/default.nix index b6ac53a..c1c2646 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -1,144 +1,65 @@ { - lib, - flake-parts-lib, +lib, +flake-parts-lib, +... }: let - inherit (lib) mkOption types; - inherit (flake-parts-lib) mkPerSystemModule; + inherit (lib) mkOption mkEnableOption types; + inherit (flake-parts-lib) mkPerSystemOption; in { - options.perSystem = mkPerSystemModule ({ pkgs, system, config', ... }: { - - kbdConfigurations = { - firmware = { - qmk_firmware = mkOption { - type = types.path; - default = pkgs.qmk_firmware; - description = "Default qmk_firmware to use"; - }; - }; - - kbds = mkOption { - default = {}; - type = types.attrsOf <| types.submodule (args: let - cfg = args.config; - in { - options = { - firmware = { - type = mkOption { - type = types.enum [ "qmk" ]; - default = "qmk"; - description = "Keyboard firmware type. Extensible for other firmwares"; - }; - - qmk_firmware = mkOption { - type = types.path; - default = config'.kbdConfigurations.qmk_firmware; - description = "qmk_firmware to use"; - }; + # imports = [ + # ./qmk.nix + # ]; + + 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; }; - - 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 = "keyboards/${cfg.qmk.keyboard.name}"; - }; - - _path = mkOption { - type = types.str; - internal = true - default = lib.concatStringsSep "/" ([cfg.qmk.keyboard.basePath] ++ optional (cfg.qmk.keyboard.revision != null) cfg.qmk.keyboard.revision); - }; - - }; - - keymap = { - name = mkOption { - type = types.str; - default = "default"; - example = "default"; - }; - - _path = mkOption { - type = types.str; - default = "${cfg.qmk.keyboard._basePath}/keymaps/${cfg.qmk.keymap.name}"; - internal = true; - }; - - src = mkOption { - type = types.nullOr types.path; - default = null; - }; + options = { + enable = mkEnableOption name // { default = true; }; + firmware.type = mkOption { + type = types.enum [ ]; + description = '' + Firmware type. Extensible for other firmwares. + ''; }; build = { - bin = mkOption { - type = types.path; - default = let - ksrc = cfg.qmk.keymap.src; - in pkgs.stdenv.mkDerivation { - name = "qmk:${cfg.qmk.keyboard._path}:${cfg.qmk.keymap.name}"; - srcs = [ - { - name = "qmk_firmware"; - src = cfg.qmk_firmware; - } - ] ++ lib.optional (ksrc != null) { - name = "keymap"; - src = ksrc; - }; - - sourceRoot = "qmk_firmware"; - - # nativeBuildImports = [ - # pkgs.qmk - # ]; - - postUnpack = lib.optionalString (ksrc != null) '' - mkdir -pv "${cfg.qmk.keymap._path}" - cp -rv ../keymap/* "${cfg.qmk.keymap._path}" - ''; - - buildPhase = '' - SKIP_GIT=yes SKIP_VERSION=yes \ - make "${cfg.qmk.keyboard._path}:${cfg.qmk.keymap.name}" - ''; - - installPhase = '' - mkdir -p $out - cp -v *.{bin,hex} $out/ - ''; - - - }; - }; - flash = mkOption { type = types.package; + description = '' + Flash script + ''; }; - }; + }; }; + }) - }; - }); + ./qmk + ]; }; + }; + # config._type = "submodule"; + # }; + # }; + # }; + config = { + packages = config.devices |> lib.filterAttrs (_: v: v.enable) |> builtins.mapAttrs (_: v: v.build.flash); }; - }) + }); } 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}" +# ''; +# }; +# }; +# }); +# }; +# }; +# }; +# }; +# }); +# } |
