From f652ee5019602718f4286b3ce6d0e4526407cd6d Mon Sep 17 00:00:00 2001 From: James Connolly Date: Sat, 23 May 2026 15:51:19 -0700 Subject: [PATCH] lensfun: update lens database also switches to the new `generate_db.py` script this was done because the old `lensfun_convert_db_v2_to_v1.py` script has been removed upstream and this is the new preferred method additionally, this adds the optional `lensfunDatabases` argument which can be used to override the lens database used when building the package --- pkgs/by-name/le/lensfun/package.nix | 64 +++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 17 deletions(-) diff --git a/pkgs/by-name/le/lensfun/package.nix b/pkgs/by-name/le/lensfun/package.nix index 55fa9762f086..a211bfc15ed4 100644 --- a/pkgs/by-name/le/lensfun/package.nix +++ b/pkgs/by-name/le/lensfun/package.nix @@ -1,6 +1,7 @@ { lib, stdenv, + stdenvNoCC, fetchFromGitHub, pkg-config, glib, @@ -9,20 +10,54 @@ cmake, python3, python3Packages, + + # optionally specify a derivation containing the lens data as generated from the `generate_db.py` script + lensfunDatabases ? null, }: let version = "0.3.4"; pname = "lensfun"; - # Fetch a more recent version of the repo containing a more recent lens - # database - lensfunDatabase = fetchFromGitHub { - owner = "lensfun"; - repo = "lensfun"; - rev = "a1510e6f33ce9bc8b5056a823c6d5bc6b8cba033"; - sha256 = "sha256-qdONyKk873Tq11M33JmznhJMAGd4dqp5KdXdVhfy/Ak="; - }; + lensData = + if lensfunDatabases != null then + lensfunDatabases + else + # fetch a more recent version of the lens database + stdenvNoCC.mkDerivation { + name = "lensfun-databases"; + + src = fetchFromGitHub { + owner = "lensfun"; + repo = "lensfun"; + rev = "201da1a7433626a2a1ecd67e1f21a42fb17aa4a5"; + sha256 = "sha256-64ZcupHA4oClPRCnG8KofGC46M/mZFermugzQ15B6k4="; + + leaveDotGit = true; + # generate timestamp based on the most recent commit + postFetch = '' + cd $out + git log -1 --format=%at > $out/timestamp.txt + rm -R .git + ''; + }; + + nativeBuildInputs = [ + python3 + python3Packages.setuptools + python3Packages.lxml + ]; + + # generates versioned tarballs of lens data + # patch applied so that we read the previously generated `timestamp.txt` instead + # of trying to read from `.git` (which is deleted during `postFetch`) + buildPhase = '' + substituteInPlace tools/update_database/generate_db.py \ + --replace-fail '"git", "log", "-1", "--format=%ad", "--date=raw", "--", "*.xml"' '"cat", "timestamp.txt"' + python3 tools/update_database/generate_db.py --input data/db --output $out + cp timestamp.txt $out/timestamp.txt + ''; + }; in stdenv.mkDerivation { @@ -36,15 +71,13 @@ stdenv.mkDerivation { }; # replace database with a more recent snapshot - # the master branch uses version 2 profiles, while 0.3.3 requires version 1 profiles, - # so we run the conversion tool the project provides, - # then untar the version 1 profiles into the source dir before we build + # the master branch uses version 2 profiles, while this version requires version 1 profiles + # also copies in the required `timestamp.txt` file prePatch = '' rm -R data/db - python3 ${lensfunDatabase}/tools/lensfun_convert_db_v2_to_v1.py $TMPDIR ${lensfunDatabase}/data/db mkdir -p data/db - tar xvf $TMPDIR/db/version_1.tar -C data/db - date +%s > data/db/timestamp.txt + tar xvfj ${lensData}/version_1.tar.bz2 -C data/db + cp ${lensData}/timestamp.txt data/db/timestamp.txt '' # Backport CMake 4 support # This is already on master, but not yet in a stable release: @@ -60,9 +93,6 @@ stdenv.mkDerivation { nativeBuildInputs = [ cmake pkg-config - python3 - python3Packages.setuptools - python3Packages.lxml # For the db converison ]; buildInputs = [