From 31da557c1c83698aab50524ebd22987db61144fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=BCtz?= Date: Sat, 14 Dec 2024 20:52:08 -0800 Subject: [PATCH] immich: update geodata Also include the geonames license CC-BY-4.0 in meta. --- pkgs/by-name/im/immich/package.nix | 19 ++++++++++++++----- pkgs/by-name/im/immich/sources.json | 4 ++++ pkgs/by-name/im/immich/update.sh | 22 ++++++++++++++++++++-- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/pkgs/by-name/im/immich/package.nix b/pkgs/by-name/im/immich/package.nix index 3ab09c8dec0a..11561c25b4da 100644 --- a/pkgs/by-name/im/immich/package.nix +++ b/pkgs/by-name/im/immich/package.nix @@ -50,9 +50,15 @@ let # The geodata website is not versioned, so we use the internet archive geodata = + let + inherit (sources.components.geonames) timestamp; + date = + "${lib.substring 0 4 timestamp}-${lib.substring 4 2 timestamp}-${lib.substring 6 2 timestamp}T" + + "${lib.substring 8 2 timestamp}:${lib.substring 10 2 timestamp}:${lib.substring 12 2 timestamp}Z"; + in runCommand "immich-geodata" { - outputHash = "sha256-imqSfzXaEMNo9T9tZr80sr/89n19kiFc8qwidFzRUaY="; + outputHash = sources.components.geonames.hash; outputHashMode = "recursive"; nativeBuildInputs = [ cacert @@ -64,15 +70,15 @@ let } '' mkdir $out - url="https://web.archive.org/web/20240724153050/http://download.geonames.org/export/dump" + url="https://web.archive.org/web/${timestamp}/http://download.geonames.org/export/dump" curl -Lo ./cities500.zip "$url/cities500.zip" curl -Lo $out/admin1CodesASCII.txt "$url/admin1CodesASCII.txt" curl -Lo $out/admin2Codes.txt "$url/admin2Codes.txt" curl -Lo $out/ne_10m_admin_0_countries.geojson \ - https://raw.githubusercontent.com/nvkelso/natural-earth-vector/ca96624a56bd078437bca8184e78163e5039ad19/geojson/ne_10m_admin_0_countries.geojson + https://github.com/nvkelso/natural-earth-vector/raw/ca96624a56bd078437bca8184e78163e5039ad19/geojson/ne_10m_admin_0_countries.geojson unzip ./cities500.zip -d $out/ - echo "2024-07-24T15:30:50Z" > $out/geodata-date.txt + echo "${date}" > $out/geodata-date.txt ''; src = fetchFromGitHub { @@ -241,7 +247,10 @@ buildNpmPackage' { meta = { description = "Self-hosted photo and video backup solution"; homepage = "https://immich.app/"; - license = lib.licenses.agpl3Only; + license = with lib.licenses; [ + agpl3Only + cc-by-40 # geonames + ]; maintainers = with lib.maintainers; [ dotlambda jvanbruegge diff --git a/pkgs/by-name/im/immich/sources.json b/pkgs/by-name/im/immich/sources.json index 735452b0e5dc..61baf35adda7 100644 --- a/pkgs/by-name/im/immich/sources.json +++ b/pkgs/by-name/im/immich/sources.json @@ -17,6 +17,10 @@ "open-api/typescript-sdk": { "npmDepsHash": "sha256-GtqS59I+By1u6WcR+lDj2HKXVwh7jw5/N6MRdUctlaM=", "version": "1.122.3" + }, + "geonames": { + "timestamp": "20241215052013", + "hash": "sha256-Gv85Y5KAkeqNU8iMMKwepI5o14Z0s5aQbLJVxhtjY14=" } } } diff --git a/pkgs/by-name/im/immich/update.sh b/pkgs/by-name/im/immich/update.sh index a1a5e2e0585c..1e11085e3adf 100755 --- a/pkgs/by-name/im/immich/update.sh +++ b/pkgs/by-name/im/immich/update.sh @@ -1,5 +1,5 @@ #!/usr/bin/env nix-shell -#!nix-shell -i bash -p curl jq prefetch-npm-deps nix-prefetch-github coreutils +#!nix-shell -i bash -p curl jq prefetch-npm-deps nix-prefetch-github coreutils ripgrep set -euo pipefail cd "$(dirname "${BASH_SOURCE[0]}")" @@ -39,6 +39,24 @@ for npm_component in cli server web "open-api/typescript-sdk"; do '.components += {($npm_component): {npmDepsHash: $hash, version: $version}}' \ "$sources_tmp")" > "$sources_tmp" done - rm "$lock" + +url="http://download.geonames.org/export/dump" +curl -s "http://web.archive.org/save/$url/cities500.zip" +curl -s "http://web.archive.org/save/$url/admin1CodesASCII.txt" +curl -s "http://web.archive.org/save/$url/admin1Codes.txt" +timestamp=$(curl -s \ + "http://archive.org/wayback/available?url=$url/cities500.zip" \ + | jq -r ".archived_snapshots.closest.timestamp") +echo "$(jq --arg timestamp "$timestamp" --arg hash "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" \ + '.components += {geonames: {timestamp: $timestamp, hash: $hash}}' \ + "$sources_tmp")" > "$sources_tmp" + +cp "$sources_tmp" sources.json +set +o pipefail +output="$(nix-build ../../../.. -A immich.geodata 2>&1 || true)" +set -o pipefail +hash=$(echo "$output" | rg 'got:\s+(sha256-.*)$' -or '$1') +echo "$(jq --arg hash "$hash" '.components.geonames.hash = $hash' "$sources_tmp")" > "$sources_tmp" + mv "$sources_tmp" sources.json