aboutsummaryrefslogtreecommitdiff
path: root/modules/build/firmware.nix
blob: 785de4fb1775484c2a2ff3710fb83ceb5b73a1e4 (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
{ config, pkgs, lib, ... }:
with builtins // lib;
let
  cfg = config.build.firmware;
in {
  options.build = {
    firmware = {
      updateCheck = mkOption {
        internal = true;
        readOnly = true;
        type = types.package;
        default = pkgs.writeShellApplication {
          name = "update-check";
          runtimeInputs = with pkgs; [
            curl
            jq
          ];
          text = with config.device; ''
            curl --silent "https://api.kobobooks.com/1.0/UpgradeCheck/Device/${deviceID}/${affiliate}/${config.firmware.version}/${serialNumber}" | jq .
          '';
        };
      };
      payload = mkOption {
        internal = true;
        readOnly = true;
        type = types.path;
        default = pkgs.runCommandLocal "firmware-payload" {
          nativeBuildInputs = with pkgs; [
            kobo-utils
            gawk
            rsync
          ];
        } ''
          mkdir $out
          rsync -rv --links --executability --chmod=u+w "${config.firmware.package}/" $out

          # Check that we haven't fucked up!
          KOBOVERSION="$(kobo-versionextract "$out/KoboRoot.tgz" | awk '{if ($1 == "Version:") print $2}')"
          if [[ ! "$KOBOVERSION" == "${config.firmware.version}" ]]; then
            >&2 echo "Expected version ${config.firmware.version}, but actual firmware is version $KOBOVERSION"
            exit 1
          fi
        '';
      };
      deploy = mkOption {
        internal = true;
        readOnly = true;
        type = types.package;
        default = pkgs.kobo-deploy cfg.payload;
      };
    };
  };
}