From e0832b1bd8e6f6f5ff6cfc1f639792971f938208 Mon Sep 17 00:00:00 2001 From: eljamm Date: Thu, 8 Aug 2024 12:51:38 +0100 Subject: [PATCH] taler-merchant: fix wrong templates and spa dirs The taler-exchange package is wrongfully used when initializing the `templates` and `spa` directories, which results in the merchant not working. Replacing this relative path searching with an absolute path pointing to the correct merchant directories fixes this. --- .../0001-add-TALER_TEMPLATING_init_path.patch | 75 +++++++++++++++++++ pkgs/by-name/ta/taler-exchange/package.nix | 2 + pkgs/by-name/ta/taler-merchant/package.nix | 24 +++++- 3 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 pkgs/by-name/ta/taler-exchange/0001-add-TALER_TEMPLATING_init_path.patch diff --git a/pkgs/by-name/ta/taler-exchange/0001-add-TALER_TEMPLATING_init_path.patch b/pkgs/by-name/ta/taler-exchange/0001-add-TALER_TEMPLATING_init_path.patch new file mode 100644 index 000000000000..60ea8051366e --- /dev/null +++ b/pkgs/by-name/ta/taler-exchange/0001-add-TALER_TEMPLATING_init_path.patch @@ -0,0 +1,75 @@ +From 3ca51717bbb7643eb0629729d0680cca75ce34c8 Mon Sep 17 00:00:00 2001 +From: eljamm +Date: Wed, 14 Aug 2024 11:14:41 +0100 +Subject: [PATCH] add TALER_TEMPLATING_init_path + +The merchant uses `TALER_TEMPLATING_init` function from the exchange's +headers, which makes it harder to patch in the correct directory. + +To circumvent this, a similar function that takes the templates path +directly is added. +--- + src/include/taler_templating_lib.h | 9 +++++++++ + src/templating/templating_api.c | 25 +++++++++++++++++++++++++ + 2 files changed, 34 insertions(+) + +diff --git a/src/include/taler_templating_lib.h b/src/include/taler_templating_lib.h +index 6af6db715..343004ef1 100644 +--- a/src/include/taler_templating_lib.h ++++ b/src/include/taler_templating_lib.h +@@ -120,6 +120,16 @@ TALER_TEMPLATING_reply_error (struct MHD_Connection *connection, + enum GNUNET_GenericReturnValue + TALER_TEMPLATING_init (const char *subsystem); + ++/** ++ * Preload templates from path. ++ * ++ * @param subsystem name of the subsystem, "merchant" or "exchange" ++ * @param path name of the absolute template path ++ * @return #GNUNET_OK on success ++ */ ++enum GNUNET_GenericReturnValue ++TALER_TEMPLATING_init_path (const char *subsystem, const char *path); ++ + + /** + * Nicely shut down templating subsystem. +diff --git a/src/templating/templating_api.c b/src/templating/templating_api.c +index 88a17c682..a9afa2b70 100644 +--- a/src/templating/templating_api.c ++++ b/src/templating/templating_api.c +@@ -506,6 +506,31 @@ TALER_TEMPLATING_init (const char *subsystem) + } + + ++enum GNUNET_GenericReturnValue ++TALER_TEMPLATING_init_path (const char *subsystem, const char *path) ++{ ++ char *dn; ++ int ret; ++ ++ { ++ GNUNET_asprintf (&dn, ++ "%s/%s/templates/", ++ path, ++ subsystem); ++ } ++ ret = GNUNET_DISK_directory_scan (dn, ++ &load_template, ++ NULL); ++ GNUNET_free (dn); ++ if (-1 == ret) ++ { ++ GNUNET_break (0); ++ return GNUNET_SYSERR; ++ } ++ return GNUNET_OK; ++} ++ ++ + void + TALER_TEMPLATING_done (void) + { +-- +2.45.2 + diff --git a/pkgs/by-name/ta/taler-exchange/package.nix b/pkgs/by-name/ta/taler-exchange/package.nix index 4bea04b1c29e..5460db04a5e4 100644 --- a/pkgs/by-name/ta/taler-exchange/package.nix +++ b/pkgs/by-name/ta/taler-exchange/package.nix @@ -34,6 +34,8 @@ stdenv.mkDerivation { hash = "sha256-yHRRMlqFA2OiFg0rBVzn7130wyVaxKn2dChFTPnVtbs="; }; + patches = [ ./0001-add-TALER_TEMPLATING_init_path.patch ]; + nativeBuildInputs = [ autoreconfHook pkg-config diff --git a/pkgs/by-name/ta/taler-merchant/package.nix b/pkgs/by-name/ta/taler-merchant/package.nix index b5762464c3ab..dcc45968894f 100644 --- a/pkgs/by-name/ta/taler-merchant/package.nix +++ b/pkgs/by-name/ta/taler-merchant/package.nix @@ -8,6 +8,7 @@ libtool, pkg-config, autoreconfHook, + makeWrapper, jq, }: @@ -36,9 +37,20 @@ stdenv.mkDerivation { ln -s ${taler-wallet-core}/spa.html $sourceRoot/contrib/ ''; + # Use an absolute path for `templates` and `spa` directories, else a relative + # path to the `taler-exchange` package is used. + postPatch = '' + substituteInPlace src/backend/taler-merchant-httpd.c \ + --replace-fail 'TALER_TEMPLATING_init ("merchant");' "TALER_TEMPLATING_init_path (\"merchant\", \"$out/share/taler\");" + + substituteInPlace src/backend/taler-merchant-httpd_spa.c \ + --replace-fail 'GNUNET_DISK_directory_scan (dn,' "GNUNET_DISK_directory_scan (\"$out/share/taler/merchant/spa/\"," + ''; + nativeBuildInputs = [ pkg-config autoreconfHook + makeWrapper ]; buildInputs = taler-exchange.buildInputs ++ [ @@ -59,10 +71,14 @@ stdenv.mkDerivation { popd ''; - configureFlags = [ - "--with-gnunet=${gnunet}" - "--with-exchange=${taler-exchange}" - ]; + # NOTE: The executables that need database access fail to detect the + # postgresql library in `$out/lib/taler`, so we need to wrap them. + postInstall = '' + for exec in dbinit httpd webhook wirewatch depositcheck exchange; do + wrapProgram $out/bin/taler-merchant-$exec \ + --prefix LD_LIBRARY_PATH : "$out/lib/taler" + done + ''; enableParallelBuilding = true;