diff options
Diffstat (limited to 'modules/pinecil.nix')
| -rw-r--r-- | modules/pinecil.nix | 64 |
1 files changed, 64 insertions, 0 deletions
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}" + ''; + }; + }; +} |
