opencellid: rework package; mirror the data to an external repo

This commit is contained in:
2025-03-21 07:41:32 +00:00
parent b51352bd98
commit 56c6e97f8f

View File

@@ -1,49 +1,66 @@
{ {
common-updater-scripts, _experimental-update-script-combinators,
coreutils, curl,
fetchurl, fetchFromGitea,
git,
gzip,
lib, lib,
nix-update-script,
stdenv, stdenv,
writeShellApplication, writeShellApplication,
# database downloads are limited per API key, so please consider supplying your own API key if using this package
apiKey ? "pk.758ba60a9bf5fc060451153c3e2542dc",
}: }:
stdenv.mkDerivation rec { stdenv.mkDerivation {
pname = "opencellid"; pname = "opencellid";
version = "0-unstable-2025-03-21"; version = "0-unstable-2025-03-21";
src = fetchurl { src = fetchFromGitea {
# this is a live url. updated... weekly? the server seems to silently ignore unrecognized query parameters, domain = "git.uninsane.org";
# so i append a version tag such that bumping it forces nix to re-fetch the data. owner = "colin";
# the API key should allow for at least 2 downloads per day (maybe more?) repo = "opencellid-mirror";
# TODO: repackage this such that hashes can be stable (mirror the data in a versioned repo, and point to that here?) rev = "014e87483c749101e62352e44b180f71550838c2";
url = "https://opencellid.org/ocid/downloads?token=${apiKey}&type=full&file=cell_towers.csv.gz&_stamp=${version}"; hash = "sha256-ZOtpl/9JWX7Ob/3WCiZEls3oLp+iH25JffaCUok6Egk=";
hash = "sha256-OVh0j/TT2O1/QXcYfrakAWhyOjVyc3P71G8gUlWr6oQ=";
}; };
unpackPhase = '' dontBuild = true;
gunzip "$src" --stdout > cell_towers.csv
'';
installPhase = '' installPhase = ''
runHook preInstall runHook preInstall
mkdir $out
cp cell_towers.csv $out cp cell_towers.csv $out
runHook postInstall runHook postInstall
''; '';
passthru.updateScript = writeShellApplication { passthru = rec {
name = "opencellid-update-script"; updateFromMirror = nix-update-script {
runtimeInputs = [ common-updater-scripts coreutils ]; extraArgs = [ "--version" "branch" ];
text = '' };
# UPDATE_NIX_ATTR_PATH is supplied by the caller opencellid-update-script = writeShellApplication {
version=0-unstable-$(date +%Y-%m-%d) name = "opencellid-update-script";
update-source-version "$UPDATE_NIX_ATTR_PATH" "$version" \ runtimeInputs = [ curl git gzip ];
--ignore-same-version \ text = ''
--print-changes set -x
''; pushd "$(mktemp -d opencellid.XXXXXXXX)"
git clone git@git.uninsane.org:colin/opencellid-mirror.git
cd opencellid-mirror
./update
# with `git gc` a daily commit is compressed from ~160MB -> 4-8MB (as measured by the reported size of .git dir).
# not sure if this affects the size when pushed to the remote though.
git gc
git push origin master
popd
'';
};
updateFromOpenCellId = lib.getExe opencellid-update-script;
updateScript = _experimental-update-script-combinators.sequence [
updateFromOpenCellId
updateFromMirror
];
}; };
meta = with lib; { meta = with lib; {