Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions pkgs/by-name/cartes/app-icons-fetch.patch
Original file line number Diff line number Diff line change
@@ -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) => {
143 changes: 143 additions & 0 deletions pkgs/by-name/cartes/package.nix
Original file line number Diff line number Diff line change
@@ -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;
};
})