Skip to content

Commit 5a15c1a

Browse files
authored
immich: update geodata (NixOS#365307)
2 parents 323cbfd + 31da557 commit 5a15c1a

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

pkgs/by-name/im/immich/package.nix

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,15 @@ let
5050

5151
# The geodata website is not versioned, so we use the internet archive
5252
geodata =
53+
let
54+
inherit (sources.components.geonames) timestamp;
55+
date =
56+
"${lib.substring 0 4 timestamp}-${lib.substring 4 2 timestamp}-${lib.substring 6 2 timestamp}T"
57+
+ "${lib.substring 8 2 timestamp}:${lib.substring 10 2 timestamp}:${lib.substring 12 2 timestamp}Z";
58+
in
5359
runCommand "immich-geodata"
5460
{
55-
outputHash = "sha256-imqSfzXaEMNo9T9tZr80sr/89n19kiFc8qwidFzRUaY=";
61+
outputHash = sources.components.geonames.hash;
5662
outputHashMode = "recursive";
5763
nativeBuildInputs = [
5864
cacert
@@ -64,15 +70,15 @@ let
6470
}
6571
''
6672
mkdir $out
67-
url="https://web.archive.org/web/20240724153050/http://download.geonames.org/export/dump"
73+
url="https://web.archive.org/web/${timestamp}/http://download.geonames.org/export/dump"
6874
curl -Lo ./cities500.zip "$url/cities500.zip"
6975
curl -Lo $out/admin1CodesASCII.txt "$url/admin1CodesASCII.txt"
7076
curl -Lo $out/admin2Codes.txt "$url/admin2Codes.txt"
7177
curl -Lo $out/ne_10m_admin_0_countries.geojson \
72-
https://raw.githubusercontent.com/nvkelso/natural-earth-vector/ca96624a56bd078437bca8184e78163e5039ad19/geojson/ne_10m_admin_0_countries.geojson
78+
https://github.com/nvkelso/natural-earth-vector/raw/ca96624a56bd078437bca8184e78163e5039ad19/geojson/ne_10m_admin_0_countries.geojson
7379
7480
unzip ./cities500.zip -d $out/
75-
echo "2024-07-24T15:30:50Z" > $out/geodata-date.txt
81+
echo "${date}" > $out/geodata-date.txt
7682
'';
7783

7884
src = fetchFromGitHub {
@@ -241,7 +247,10 @@ buildNpmPackage' {
241247
meta = {
242248
description = "Self-hosted photo and video backup solution";
243249
homepage = "https://immich.app/";
244-
license = lib.licenses.agpl3Only;
250+
license = with lib.licenses; [
251+
agpl3Only
252+
cc-by-40 # geonames
253+
];
245254
maintainers = with lib.maintainers; [
246255
dotlambda
247256
jvanbruegge

pkgs/by-name/im/immich/sources.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
"open-api/typescript-sdk": {
1818
"npmDepsHash": "sha256-GtqS59I+By1u6WcR+lDj2HKXVwh7jw5/N6MRdUctlaM=",
1919
"version": "1.122.3"
20+
},
21+
"geonames": {
22+
"timestamp": "20241215052013",
23+
"hash": "sha256-Gv85Y5KAkeqNU8iMMKwepI5o14Z0s5aQbLJVxhtjY14="
2024
}
2125
}
2226
}

pkgs/by-name/im/immich/update.sh

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env nix-shell
2-
#!nix-shell -i bash -p curl jq prefetch-npm-deps nix-prefetch-github coreutils
2+
#!nix-shell -i bash -p curl jq prefetch-npm-deps nix-prefetch-github coreutils ripgrep
33

44
set -euo pipefail
55
cd "$(dirname "${BASH_SOURCE[0]}")"
@@ -39,6 +39,24 @@ for npm_component in cli server web "open-api/typescript-sdk"; do
3939
'.components += {($npm_component): {npmDepsHash: $hash, version: $version}}' \
4040
"$sources_tmp")" > "$sources_tmp"
4141
done
42-
4342
rm "$lock"
43+
44+
url="http://download.geonames.org/export/dump"
45+
curl -s "http://web.archive.org/save/$url/cities500.zip"
46+
curl -s "http://web.archive.org/save/$url/admin1CodesASCII.txt"
47+
curl -s "http://web.archive.org/save/$url/admin1Codes.txt"
48+
timestamp=$(curl -s \
49+
"http://archive.org/wayback/available?url=$url/cities500.zip" \
50+
| jq -r ".archived_snapshots.closest.timestamp")
51+
echo "$(jq --arg timestamp "$timestamp" --arg hash "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" \
52+
'.components += {geonames: {timestamp: $timestamp, hash: $hash}}' \
53+
"$sources_tmp")" > "$sources_tmp"
54+
55+
cp "$sources_tmp" sources.json
56+
set +o pipefail
57+
output="$(nix-build ../../../.. -A immich.geodata 2>&1 || true)"
58+
set -o pipefail
59+
hash=$(echo "$output" | rg 'got:\s+(sha256-.*)$' -or '$1')
60+
echo "$(jq --arg hash "$hash" '.components.geonames.hash = $hash' "$sources_tmp")" > "$sources_tmp"
61+
4462
mv "$sources_tmp" sources.json

0 commit comments

Comments
 (0)