{ 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}" ''; }; }; }