aboutsummaryrefslogtreecommitdiff
path: root/modules/build/firmware.nix
blob: 3a1039b7322535246206886f31051b30484eb6ac (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
{ 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
          tar czvf $out/KoboRoot.tgz --directory="${config.firmware.package.KoboRoot}" . --mode=u+w
          rsync -rv --links --executability --chmod=u+w "${config.firmware.package.out}/" $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;
      };
    };
  };
}