From 93a6c43ae005b39cce3b33a1dddf0e50ca5e06ad Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Wed, 8 Oct 2025 13:16:08 -0500 Subject: Started writing modules --- flake.nix | 13 +++++ modules/default.nix | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 flake.nix create mode 100644 modules/default.nix diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..739f1cf --- /dev/null +++ b/flake.nix @@ -0,0 +1,13 @@ +{ + description = "Nix utilities to manage keyboard firmware"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs"; + flake-parts.url = "github:hercules-ci/flake-parts"; + systems.url = "github:nix-systems/default"; + }; + + outputs = inputs@{self, ... }: inputs.flake-parts.mkFlake { inherit inputs self; } { + systems = import inputs.systems; + }; +} diff --git a/modules/default.nix b/modules/default.nix new file mode 100644 index 0000000..c5b8e4e --- /dev/null +++ b/modules/default.nix @@ -0,0 +1,134 @@ +{ + lib, + flake-parts-lib, +}: +let + inherit (lib) mkOption types; + inherit (flake-parts-lib) mkPerSystemModule; +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: { + 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"; + }; + }; + + qmk = { + keyboard = { + name = mkOption { + type = types.str; + description = "path to keyboard"; + }; + + revision = mkOption { + type = types.nullOr types.str; + description = "keyboard revision"; + }; + + _path = mkOption { + type = types.str; + default = lib.concatStringsSep "/" ([ args.config.name ] ++ optional (args.config.revision != null) args.config.revision); + }; + + _keymapsPath = mkOption { + type = types.str; + default = lib.concatStringsSep [ args.config.qmk.keyboard._path "keymaps" ]; + }; + }; + + keymap = { + name = mkOption { + type = types.str; + }; + + _path = mkOption { + type = types.str; + default = "${args.config.qmk.keyboard._path}/keymaps/${args.config.qmk.keymap.name}"; + }; + + src = mkOption { + type = types.nullOr types.path; + default = null; + }; + }; + + build = { + bin = mkOption { + type = types.path; + default = let + ksrc = args.config.keymap.src; + in pkgs.stdenv.mkDerivation { + name = "qmk:${args.config.qmk.keyboard._path}:${args.config.qmk.keymap.name}"; + srcs = [ + { + name = "qmk_firmware"; + src = args.config.firmware.qmk_firmware; + } + ] ++ lib.optional (ksrc != null) { + name = "keymap"; + src = ksrc; + }; + + sourceRoot = "qmk_firmware"; + + nativeBuildImports = [ + pkgs.qmk + ]; + + postUnpack = lib.optionalString (ksrc != null) '' + mkdir -pv "keyboards/${args.config.keymap._path}" + cp -rv ../keymap/* "keyboards/${args.config.keymap._path}" + ''; + + buildPhase = '' + SKIP_GIT=yes SKIP_VERSION=yes \ + make "keyboards/${args.config.keyboard._path}:${args.config.keymap.name}" + ''; + + installPhase = '' + mkdir -p $out + cp -v *.{bin,hex} $out/ + ''; + + + }; + }; + + flash = mkOption { + type = types.package; + }; + }; + + }; + + }; + }); + }; + + + + }; + }) +} -- cgit v1.2.3