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