From 6f861e19166f497c78b6a3eae3128fd3f195e6de Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Thu, 4 Dec 2025 10:44:03 +0800 Subject: [PATCH] feat(cartes): init at 3-unstable-2025-12-10 --- pkgs/by-name/cartes/app-icons-fetch.patch | 82 +++++++++++++ pkgs/by-name/cartes/package.nix | 143 ++++++++++++++++++++++ 2 files changed, 225 insertions(+) create mode 100644 pkgs/by-name/cartes/app-icons-fetch.patch create mode 100644 pkgs/by-name/cartes/package.nix diff --git a/pkgs/by-name/cartes/app-icons-fetch.patch b/pkgs/by-name/cartes/app-icons-fetch.patch new file mode 100644 index 000000000..a75ccd5b8 --- /dev/null +++ b/pkgs/by-name/cartes/app-icons-fetch.patch @@ -0,0 +1,82 @@ +--- a/app/icons/fetch.ts ++++ b/app/icons/fetch.ts +@@ -17,7 +17,8 @@ + + import { bash, BashError } from 'https://deno.land/x/bash/mod.ts' + +-const shouldDownload = Deno.env.get('DO_DOWNLOAD') ++const nixUsePrefetched = Deno.env.get('NIX_USE_PREFETCHED') ++const shouldDownload = nixUsePrefetched || Deno.env.get('DO_DOWNLOAD') + + if (!shouldDownload) { + console.log( +@@ -29,12 +30,18 @@ + const downloadCommand = `curl -L https://github.com/osmandapp/OsmAnd-resources/tarball/master/ > osmand-resources.tar.gz` + + try { +- console.log('Will download Github folder as tarball') +- const tarball = await bash(downloadCommand) +- console.log('Github folder download as tarball') +- const extract = await bash( +- `rm -rf public/osmand-icons && mkdir public/osmand-icons && tar -xzvf osmand-resources.tar.gz -C public/osmand-icons --strip-components=1 --wildcards osman*/icons/svg/` +- ) ++ if (nixUsePrefetched) { ++ const extract = await bash( ++ `rm -rf public/osmand-icons && mkdir -p public/osmand-icons/icons && cp -r ${nixUsePrefetched}/icons/svg public/osmand-icons/icons/svg` ++ ) ++ } else { ++ console.log('Will download Github folder as tarball') ++ const tarball = await bash(downloadCommand) ++ console.log('Github folder download as tarball') ++ const extract = await bash( ++ `rm -rf public/osmand-icons && mkdir public/osmand-icons && tar -xzvf osmand-resources.tar.gz -C public/osmand-icons --strip-components=1 --wildcards osman*/icons/svg/` ++ ) ++ } + + const newLastUpdateDate = new Date().toISOString().split('T')[0] + await bash( +@@ -46,11 +53,16 @@ + } + } + ++let text + // This scripts relies on this file that contains all icon names +-const req = await fetch( +- 'https://raw.githubusercontent.com/osmandapp/OsmAnd-resources/master/icons/tools/sortfiles.sh' +-) +-const text = await req.text() ++if (nixUsePrefetched) { ++ text = await Deno.readTextFile(nixUsePrefetched + "/icons/tools/sortfiles.sh") ++} else { ++ const req = await fetch( ++ 'https://raw.githubusercontent.com/osmandapp/OsmAnd-resources/master/icons/tools/sortfiles.sh' ++ ) ++ text = await req.text() ++} + + const results = text + .split('\n') +@@ -58,11 +70,18 @@ + .map((el) => el.split('#')[0].trimEnd()) // they can have comments to end the line + .filter((el) => el.length > 0) + +-const iconDirectories = await listDirectory( +- 'osmandapp', +- 'OsmAnd-resources', +- 'icons/svg' +-) ++let iconDirectories = [] ++if (nixUsePrefetched) { ++ for await (const dirEntry of Deno.readDir("public/osmand-icons/icons/svg")) { ++ iconDirectories.push(dirEntry.name); ++ } ++} else { ++ iconDirectories = await listDirectory( ++ 'osmandapp', ++ 'OsmAnd-resources', ++ 'icons/svg' ++ ) ++} + + //console.log('cyan', iconDirectories) + const iconUrls = results.map((el) => { diff --git a/pkgs/by-name/cartes/package.nix b/pkgs/by-name/cartes/package.nix new file mode 100644 index 000000000..59888611b --- /dev/null +++ b/pkgs/by-name/cartes/package.nix @@ -0,0 +1,143 @@ +{ + bun, + deno, + fetchFromGitea, + fetchFromGitHub, + fetchurl, + lib, + makeWrapper, + nodejs, + stdenvNoCC, +}: +let + inherit (stdenvNoCC.hostPlatform) system; + denoBash = fetchurl { + name = "bash.ts"; + url = "https://raw.githubusercontent.com/justinawrey/bash/refs/tags/0.2.0/mod.ts"; + hash = "sha256-rPyhsPAkmH8V/xz0etN6SkoMU/QHW2L9lOuRkV30aCM="; + }; +in +stdenvNoCC.mkDerivation (finalAttrs: { + pname = "cartes"; + version = "3-unstable-2025-12-10"; + + src = fetchFromGitea { + domain = "codeberg.org"; + owner = "cartes"; + repo = "web"; + rev = "8d33e9c70c4e279695663088fe21625fbeb7d3d3"; + hash = "sha256-jDUdm36HIv4szaoBlt23Xtv8X6iLJU6pTxV8EBzvU7M="; + }; + + patches = [ + ./app-icons-fetch.patch + ]; + + postPatch = '' + substituteInPlace app/icons/fetch.ts \ + --replace-fail 'https://deno.land/x/bash/mod.ts' '${denoBash}' + substituteInPlace app/sitemap.ts \ + --replace-fail 'generateAgencies = async () => {' 'generateAgencies = async () => { return [];' + substituteInPlace lib/issues.ts \ + --replace-fail 'downloadIssues() {' 'downloadIssues() { return [];' + ''; + + nativeBuildInputs = [ + bun + deno + makeWrapper + ]; + + postConfigure = '' + cp -r ${finalAttrs.passthru.bunDeps}/node_modules . + substituteInPlace node_modules/.bin/next \ + --replace-fail "/usr/bin/env node" "${lib.getExe nodejs}" + + export DENO_DIR=$(mktemp -d) + deno run --allow-all app/icons/fetch.ts + ''; + + buildPhase = '' + runHook preBuild + + bun run build + + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + + mkdir -p $out/lib/cartes + cp -R . $out/lib/cartes/ + + mkdir -p $out/bin + makeWrapper $out/lib/cartes/node_modules/.bin/next $out/bin/cartes \ + --add-flag start + + runHook postInstall + ''; + + env = { + NIX_USE_PREFETCHED = finalAttrs.passthru.osmand-resources; + }; + + passthru = { + bunDeps = stdenvNoCC.mkDerivation { + name = "${finalAttrs.pname}-bun-deps"; + inherit (finalAttrs) src; + + postPatch = '' + substituteInPlace package.json \ + --replace-fail " deno run " " ${lib.getExe deno} run " + ''; + + buildPhase = '' + runHook preBuild + + export BUN_INSTALL_CACHE_DIR=$(mktemp -d) + export DENO_DIR=$(mktemp -d) + + ${lib.getExe bun} install --no-save --frozen-lockfile --no-progress + + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + + mkdir -p $out + cp -R node_modules $out/ + + runHook postInstall + ''; + + # breaks FOD + dontPatchShebangs = true; + + outputHash = finalAttrs.passthru.bunDepsHashes.${system} or (throw "Unsupported system: ${system}"); + outputHashAlgo = "sha256"; + outputHashMode = "recursive"; + }; + bunDepsHashes = { + x86_64-linux = "sha256-6VRnPZ522x89kX2Y4XdAKuXeyZJG3Yz/ldDVBk+bido="; + }; + osmand-resources = fetchFromGitHub { + owner = "osmandapp"; + repo = "OsmAnd-resources"; + rev = "8c50e17d79910c60dfcd7a037526a7c0a948ad0f"; + hash = "sha256-/f5VqqLaiGqGRwDQzztyv5CTZxeiy1QUoLaU/7ofZZw="; + }; + }; + + meta = { + description = "Modern web map application with transit support"; + homepage = "https://cartes.app/"; + downloadPage = "https://codeberg.org/cartes/web"; + license = lib.licenses.agpl3Plus; + maintainers = with lib.maintainers; [ prince213 ]; + teams = with lib.teams; [ ngi ]; + mainProgram = "cartes"; + platforms = lib.attrNames finalAttrs.passthru.bunDepsHashes; + }; +})