aboutsummaryrefslogtreecommitdiff
path: root/modules/pinecil.nix
blob: 137de946db44560dc7ca3742be7fe2f8b0dc6e4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
{ lib, pkgs, config, ... }: let
  inherit (lib) mkOption mkPackageOption mkIf types;
in {
  options = {
    type = mkOption {
      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 -D";
      } else {
        pkg = config.pinecil.blisp;
        tool = "blisp write -c bl70x --reset";
      };
    in pkgs.writeShellApplication {
        name = "flash";
        runtimeInputs = [ flasher.pkg ];
        text = ''
          ${flasher.tool} "${config.pinecil.build.bin}"
        '';
      };
  };
}