Skip to content

Commit

Permalink
the-unarchiver: init at 4.3.8 (NixOS#371773)
Browse files Browse the repository at this point in the history
  • Loading branch information
GaetanLepage authored Jan 14, 2025
2 parents 2ea7851 + 5b3170b commit d6f326a
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkgs/by-name/th/the-unarchiver/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"version": "4.3.8",
"url": "https://dl.devmate.com/com.macpaw.site.theunarchiver/146/1715865652/TheUnarchiver-146.zip",
"hash": "sha256-VcgNT7z7KtdAZxya8DS4Kuk323AAh3Mv/2L7LpUS2NU="
}
41 changes: 41 additions & 0 deletions pkgs/by-name/th/the-unarchiver/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
lib,
stdenvNoCC,
fetchurl,
unzip,
}:
let
info = lib.importJSON ./info.json;
in
stdenvNoCC.mkDerivation (finalAttrs: {
pname = "the-unarchiver";
inherit (info) version;

src = fetchurl { inherit (info) url hash; };

sourceRoot = ".";
nativeBuildInputs = [ unzip ];

installPhase = ''
runHook preInstall
mkdir -p $out/Applications
mv "The Unarchiver.app" $out/Applications
runHook postInstall
'';

passthru.updateScript = ./update/update.mjs;

meta = {
description = "Unpacks archive files";
homepage = "https://theunarchiver.com/";
license = lib.licenses.unfree;
maintainers = with lib.maintainers; [ xiaoxiangmoe ];
platforms = [
"aarch64-darwin"
"x86_64-darwin"
];
sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
};
})
9 changes: 9 additions & 0 deletions pkgs/by-name/th/the-unarchiver/update/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"module": "NodeNext",
"noEmit": true,
"strict": true
}
}
103 changes: 103 additions & 0 deletions pkgs/by-name/th/the-unarchiver/update/update.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/usr/bin/env nix-shell
/*
#!nix-shell -i node --pure --packages cacert nodejs yq-go nix
*/
import * as assert from "node:assert/strict";
import * as child_process from "node:child_process";
import * as fsPromises from "node:fs/promises";
import * as path from "node:path";

const __dirname = import.meta.dirname;

/** @typedef {{
rss: {
channel: {
item: Array<{
pubDate: string;
enclosure: {
"+@url": string;
"+@length": string;
"+@type": string;
"+@sparkle:version": string;
"+@sparkle:shortVersionString": string;
};
}>
}
}
}} UpdatesXmlInfo */

/** @typedef {{
version: string;
url: string;
hash: string;
}} Info */

const UPDATE_URL =
"https://updateinfo.devmate.com/com.macpaw.site.theunarchiver/updates.xml";

async function main() {
const filePath = path.join(__dirname, "../info.json");
/** @type {Info} */
const oldInfo = JSON.parse(
await fsPromises.readFile(filePath, { encoding: "utf-8" })
);

const response = await fetch(UPDATE_URL);
assert.ok(response.ok, `Failed to fetch ${UPDATE_URL}`);
/** @type {UpdatesXmlInfo} */
const updatesXmlInfo = JSON.parse(
child_process
.execSync(`yq eval --input-format=xml --output-format=json`, {
input: Buffer.from(await response.arrayBuffer()),
})
.toString()
);
const items = updatesXmlInfo?.rss?.channel?.item;
assert.ok(Array.isArray(items), "items is required");
const item = items.sort(
(a, b) => new Date(b.pubDate).getTime() - new Date(a.pubDate).getTime()
)[0];
const {
"+@url": url,
"+@sparkle:shortVersionString": version,
"+@length": fileSize,
} = item.enclosure;
assert.ok(url, "url is required");
assert.ok(version, "version is required");
assert.ok(fileSize, "fileSize is required");

if (oldInfo.url === url && oldInfo.version === version) {
console.log("[update] No updates found");
return;
}

const [prefetchHash, prefetchStorePath] = child_process
.execSync(`nix-prefetch-url --print-path ${url}`)
.toString()
.split("\n");

const downloadedFileSize = (await fsPromises.stat(prefetchStorePath)).size;
if (Number(fileSize) !== downloadedFileSize) {
console.error(
`File size mismatch: expected ${fileSize}, got ${downloadedFileSize}`
);
process.exit(1);
}
const hash = child_process
.execSync(`nix hash convert --hash-algo sha256 --to sri ${prefetchHash}`)
.toString()
.trim();
/** @type {Info} */
const info = {
version,
url,
hash,
};
console.log(`[update] Updating Notion ${oldInfo.version} -> ${info.version}`);
await fsPromises.writeFile(filePath, JSON.stringify(info, null, 2) + "\n", {
encoding: "utf-8",
});
console.log("[update] Updating Notion complete");
}

main();

0 comments on commit d6f326a

Please sign in to comment.