diff --git a/pkgs/by-name/no/notion-app/info.json b/pkgs/by-name/no/notion-app/info.json new file mode 100644 index 000000000000..20ea51f293f2 --- /dev/null +++ b/pkgs/by-name/no/notion-app/info.json @@ -0,0 +1,12 @@ +{ + "x86_64-darwin": { + "version": "4.2.0", + "url": "https://desktop-release.notion-static.com/Notion-4.2.0.zip", + "hash": "sha512-FLptPNEtS9fTevSeGC00hDtpgSks+8JtEKRTtWlYPtI0vpA1KqixBdv2OaNSK1W7Krlsl25RpTOl8cJdQxcv4Q==" + }, + "aarch64-darwin": { + "version": "4.2.0", + "url": "https://desktop-release.notion-static.com/Notion-arm64-4.2.0.zip", + "hash": "sha512-cxfO3Bm7ZzAQMi0Pdwd3nvQlRPjn4w7j0ojYUCcn660YsBtoVkpNhiuqg9pbWzY0Umh+/8Zig9CGXKjjP94Iww==" + } +} diff --git a/pkgs/by-name/no/notion-app/package.nix b/pkgs/by-name/no/notion-app/package.nix new file mode 100644 index 000000000000..544d6454528e --- /dev/null +++ b/pkgs/by-name/no/notion-app/package.nix @@ -0,0 +1,42 @@ +{ + lib, + stdenvNoCC, + fetchurl, + unzip, +}: +let + info = + (builtins.fromJSON (builtins.readFile ./info.json))."${stdenvNoCC.targetPlatform.system}" + or (throw "notion-app: unsupported system ${stdenvNoCC.targetPlatform.system}"); +in +stdenvNoCC.mkDerivation (finalAttrs: { + pname = "notion-app"; + version = info.version; + + src = fetchurl { inherit (info) url hash; }; + + sourceRoot = "."; + nativeBuildInputs = [ unzip ]; + installPhase = '' + runHook preInstall + + mkdir -p $out/Applications + mv Notion.app $out/Applications + + runHook postInstall + ''; + + passthru.updateScript = ./update/update.mjs; + + meta = { + description = "App to write, plan, collaborate, and get organised"; + homepage = "https://www.notion.so/"; + license = lib.licenses.unfree; + maintainers = with lib.maintainers; [ xiaoxiangmoe ]; + platforms = [ + "x86_64-darwin" + "aarch64-darwin" + ]; + sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ]; + }; +}) diff --git a/pkgs/by-name/no/notion-app/update/jsconfig.json b/pkgs/by-name/no/notion-app/update/jsconfig.json new file mode 100644 index 000000000000..347a07fb3e23 --- /dev/null +++ b/pkgs/by-name/no/notion-app/update/jsconfig.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "allowJs": true, + "checkJs": true, + "module": "NodeNext", + "noEmit": true, + "strict": true + } +} diff --git a/pkgs/by-name/no/notion-app/update/update.mjs b/pkgs/by-name/no/notion-app/update/update.mjs new file mode 100755 index 000000000000..d17e5d38bf9e --- /dev/null +++ b/pkgs/by-name/no/notion-app/update/update.mjs @@ -0,0 +1,88 @@ +#!/usr/bin/env nix-shell +/* +#!nix-shell -i node --pure --packages cacert nodejs yq-go +*/ +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 {{ + version: string; + path: `${string}.zip`; + sha512: string; + releaseDate: string; + files: Array<{ url: string; sha512: string; size: number }>; +}} LiveCheckInfo */ + +/** @typedef {{ + version: string; + url: string; + hash: `sha512-${string}`; +}} Info */ + +/** @typedef {{ + "x86_64-darwin": Info; + "aarch64-darwin": Info; +}} InfoMap */ + +const BASE_URL = "https://desktop-release.notion-static.com/"; +/** + * + * @param {"latest-mac.yml" | "arm64-mac.yml"} liveCheckFile + * @returns {Promise} + */ +async function getInfo(liveCheckFile) { + const url = /** @type {const} */ (`${BASE_URL}${liveCheckFile}`); + const response = await fetch(url); + assert.ok(response.ok, `Failed to fetch ${url}`); + /** @type {LiveCheckInfo} */ + const { version, path, sha512 } = JSON.parse( + child_process + .execSync(`yq eval --output-format=json`, { + input: Buffer.from(await response.arrayBuffer()), + }) + .toString() + ); + assert.ok(version, "version is required"); + assert.ok(path, "path is required"); + assert.ok(sha512, "sha512 is required"); + return { + version, + url: BASE_URL + path, + hash: `sha512-${sha512}`, + }; +} + +async function main() { + const filePath = path.join(__dirname, "../info.json"); + /** @type {InfoMap} */ + const oldInfo = JSON.parse( + await fsPromises.readFile(filePath, { encoding: "utf-8" }) + ); + /** @type {InfoMap} */ + const info = { + "x86_64-darwin": await getInfo("latest-mac.yml"), + "aarch64-darwin": await getInfo("arm64-mac.yml"), + }; + if (JSON.stringify(oldInfo) === JSON.stringify(info)) { + console.log("[update] No updates found"); + return; + } + const platforms = /** @type {const} */ (["x86_64-darwin", "aarch64-darwin"]); + for (const platform of platforms) { + console.log( + `[update] Updating Notion ${platform} ${oldInfo[platform].version} -> ${info[platform].version}` + ); + } + await fsPromises.writeFile( + filePath, + JSON.stringify(info, null, 2) + "\n", + "utf-8" + ); + console.log("[update] Updating Notion complete"); +} + +main();