diff options
| author | Chris Wells <chris@mathematicaster.org> | 2024-09-10 14:51:28 -0500 |
|---|---|---|
| committer | Chris Wells <chris@mathematicaster.org> | 2024-09-10 14:51:28 -0500 |
| commit | 4f471484b3a1e16230979a8406503a220b9101f4 (patch) | |
| tree | dc3f5256f275f34d3bcc9573462ed34c7fd97f77 /modules/build | |
| parent | 5cb16c34a8c5b803ec723934c1dc828c0e8e3bad (diff) | |
| download | kobo-manager-4f471484b3a1e16230979a8406503a220b9101f4.tar kobo-manager-4f471484b3a1e16230979a8406503a220b9101f4.tar.gz kobo-manager-4f471484b3a1e16230979a8406503a220b9101f4.tar.bz2 kobo-manager-4f471484b3a1e16230979a8406503a220b9101f4.tar.lz kobo-manager-4f471484b3a1e16230979a8406503a220b9101f4.tar.xz kobo-manager-4f471484b3a1e16230979a8406503a220b9101f4.tar.zst kobo-manager-4f471484b3a1e16230979a8406503a220b9101f4.zip | |
I think this is almost working!
Diffstat (limited to 'modules/build')
| -rw-r--r-- | modules/build/default.nix | 2 | ||||
| -rw-r--r-- | modules/build/firmware.nix | 70 | ||||
| -rw-r--r-- | modules/build/info.nix | 55 | ||||
| -rw-r--r-- | modules/build/koboroot.nix | 31 |
4 files changed, 120 insertions, 38 deletions
diff --git a/modules/build/default.nix b/modules/build/default.nix index be3f3b0..3c0948e 100644 --- a/modules/build/default.nix +++ b/modules/build/default.nix @@ -1,5 +1,7 @@ { imports = [ ./firmware.nix + ./info.nix + ./koboroot.nix ]; } diff --git a/modules/build/firmware.nix b/modules/build/firmware.nix index 673c379..3a1039b 100644 --- a/modules/build/firmware.nix +++ b/modules/build/firmware.nix @@ -1,60 +1,54 @@ { config, pkgs, lib, ... }: with builtins // lib; let - cfg = config.build; + cfg = config.build.firmware; in { options.build = { firmware = { - checkDevice = mkOption { + updateCheck = mkOption { internal = true; readOnly = true; type = types.package; default = pkgs.writeShellApplication { - name = "check-firmware"; + name = "update-check"; runtimeInputs = with pkgs; [ - kobo-utils + curl + jq ]; - text = '' - echo "hi" + text = with config.device; '' + curl --silent "https://api.kobobooks.com/1.0/UpgradeCheck/Device/${deviceID}/${affiliate}/${config.firmware.version}/${serialNumber}" | jq . ''; }; }; - - bundle = - let - b = pkgs.runCommandLocal "package-firmware" {} '' - cp -r "${config.firmware.package.out}" $out - tar czvf $out/KoboRoot.tgz --directory="${config.firmware.package.KoboRoot}" - ''; - in pkgs.runCommandLocal "bundle-firmware" {} '' - tar czvf $out --directory "${b}" - ''; - - - deploy = pkgs.writeShellApplication { - name = "deploy-firmware"; - runtimeInputs = with pkgs; [ - gnutar - kobo-utils - ]; - text = '' - echo "Looking for kobo" - KOBOPATH="$(kobo-find -f -w)" - - if [ -z "$KOBOPATH" ]; then - >&2 echo "Cannot locate kobo device" + 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 - - echo "Found kobo device at $KOBOPATH" - - echo "Placing firmware on device" - - tar xzvf "${cfg.fimware.bundle}" --directory="$KOBOPATH/.kobo/" - - echo "Successfully installed kobo firmware. Please eject your device so it can install." ''; }; + deploy = mkOption { + internal = true; + readOnly = true; + type = types.package; + default = pkgs.kobo-deploy cfg.payload; + }; }; }; } diff --git a/modules/build/info.nix b/modules/build/info.nix new file mode 100644 index 0000000..95ef664 --- /dev/null +++ b/modules/build/info.nix @@ -0,0 +1,55 @@ +{ config, pkgs, lib, ... }: +with builtins // lib; +let + json = pkgs.formats.json {}; + cfg = config.build.info; +in { + options = { + info = mkOption { + internal = true; + type = json.type; + default = {}; + }; + build = { + info = mkOption { + internal = true; + readOnly = true; + type = types.package; + default = pkgs.writeShellApplication { + name = "kobo-info"; + runtimeInputs = with pkgs; [ + jq + kobo-utils + ]; + text = '' + echo "Local information:" + echo '${toJSON config.info}' | jq . + + + echo "Remote information:" + + KOBOPATH="$(kobo-find -f || echo "")" + + if [[ -z "$KOBOPATH" ]]; then + echo "No remote found" + exit 0 + fi + + kobo-info --json "$KOBOPATH" | jq . + ''; + }; + }; + }; + }; + + config = { + info = { + device = { + inherit (config.device) name affiliate hardware deviceID serialNumber; + }; + firmware = { + inherit (config.firmware) version date; + }; + }; + }; +} diff --git a/modules/build/koboroot.nix b/modules/build/koboroot.nix new file mode 100644 index 0000000..9bea19d --- /dev/null +++ b/modules/build/koboroot.nix @@ -0,0 +1,31 @@ +{ config, pkgs, lib, ... }: +with builtins // lib; +let + cfg = config.build.koboroot; +in { + options.build = { + koboroot = { + unpacked-payload = mkOption { + type = types.path; + internal = true; + readOnly = true; + default = config.koboroot.finalPackage; + }; + payload = mkOption { + type = types.path; + internal = true; + readOnly = true; + default = pkgs.runCommandLocal "koboroot-payload" {} '' + mkdir $out + tar czvf $out/KoboRoot.tgz --directory="${cfg.unpacked-payload}" . --mode=u+w + ''; + }; + deploy = mkOption { + internal = true; + readOnly = true; + type = types.package; + default = pkgs.kobo-deploy cfg.payload; + }; + }; + }; +} |
