From 1def69720c0ca26c3f3238622f8c535a2ba764a7 Mon Sep 17 00:00:00 2001 From: Leah Amelia Chen Date: Thu, 12 Dec 2024 12:41:58 +0100 Subject: [PATCH] libglycin: Introduce setup hook for adding loader paths to wrapper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This setup hook discovers glycin loaders in the inputs list it is placed into, and adds them to `gappsWrapperArgs`. This should simplify glycin-dependent programs’ expressions. Just add `libglycin.setupHook` (for Rust programs) or `libglycin` (for other languages) to `buildInputs`. The latter will also pull in the setup hook. Note, the setup hook needs to go to the `buildInputs` since we cannot have a different offset when used as standalone hook instead of propagated from `libglycin`. We chose `hostOffset` to make it work with the proper placement of `libglycin` in `buildInputs`. Co-authored-by: Seth Flynn Co-authored-by: Jan Tojnar --- doc/hooks/libglycin.section.md | 15 +++++++++------ doc/languages-frameworks/gnome.section.md | 2 ++ doc/redirects.json | 9 +++++++++ pkgs/by-name/li/libglycin/package.nix | 2 ++ pkgs/by-name/li/libglycin/path-hook.sh | 18 ++++++++++++++++++ 5 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 pkgs/by-name/li/libglycin/path-hook.sh diff --git a/doc/hooks/libglycin.section.md b/doc/hooks/libglycin.section.md index a758c1f08d7f..48c52e1b4036 100644 --- a/doc/hooks/libglycin.section.md +++ b/doc/hooks/libglycin.section.md @@ -2,7 +2,7 @@ [Glycin](https://gitlab.gnome.org/GNOME/glycin) is a library for sandboxed and extendable image loading. -For most applications using it, individual image formats are loaded through binaries provided by `glycin-loaders`. The paths of these loaders must be injected into the environment, e.g. using [`wrapGAppsHook`](#ssec-gnome-hooks). +[]{#libglycin-setup-hook} For most applications using it, individual image formats are loaded through binaries provided by `glycin-loaders`. The paths of these loaders must be injected into the environment, e.g. using [`wrapGAppsHook`](#ssec-gnome-hooks). `libglycin.setupHook` will do that. []{#libglycin-patch-vendor-hook} Additionally, for Rust projects `glycin` Rust crate itself requires a patch to become self-contained. `libglycin.patchVendorHook` will do that. This is not needed for projects using the ELF library from `libglycin` package. @@ -27,11 +27,10 @@ rustPlatform.buildRustPackage { libglycin.patchVendorHook ]; - preFixup = '' - gappsWrapperArgs+=( - --prefix XDG_DATA_DIRS : "${glycin-loaders}/share" - ) - ''; + buildInputs = [ + libglycin.setupHook + glycin-loaders + ]; # ... } @@ -42,3 +41,7 @@ rustPlatform.buildRustPackage { ### `glycinCargoDepsPath` {#glycin-cargo-deps-path} Path to a directory containing the `glycin` crate to patch. Defaults to the crate directory created by `cargoSetupHook`, or `./vendor/`. + +### `dontWrapGlycinLoaders` {#glycin-dont-wrap} + +Disable adding the Glycin loaders path `XDG_DATA_DIRS` with `wrapGAppsHook`. diff --git a/doc/languages-frameworks/gnome.section.md b/doc/languages-frameworks/gnome.section.md index 252f7ea3dea7..ecfda62b5700 100644 --- a/doc/languages-frameworks/gnome.section.md +++ b/doc/languages-frameworks/gnome.section.md @@ -129,6 +129,8 @@ The hooks do the following: - []{#ssec-gnome-hooks-gst-grl-plugins} Setup hooks of `gst_all_1.gstreamer` and `grilo` will populate the `GST_PLUGIN_SYSTEM_PATH_1_0` and `GRL_PLUGIN_PATH` variables, respectively, which will then be added to the wrapper by `wrapGApps*` hook. +- []{#ssec-gnome-hooks-libglycin} `libglycin`'s [setup hook](#libglycin-setup-hook) will populate `XDG_DATA_DIRS` with the path to the loaders. + You can also pass additional arguments to `makeWrapper` using `gappsWrapperArgs` in `preFixup` hook: ```nix diff --git a/doc/redirects.json b/doc/redirects.json index 31896397c31f..4bb444117189 100644 --- a/doc/redirects.json +++ b/doc/redirects.json @@ -2471,6 +2471,9 @@ "libglycin-hooks": [ "index.html#libglycin-hooks" ], + "libglycin-setup-hook": [ + "index.html#libglycin-setup-hook" + ], "libglycin-patch-vendor-hook": [ "index.html#libglycin-patch-vendor-hook" ], @@ -2483,6 +2486,9 @@ "glycin-cargo-deps-path": [ "index.html#glycin-cargo-deps-path" ], + "glycin-dont-wrap": [ + "index.html#glycin-dont-wrap" + ], "ghc": [ "index.html#ghc" ], @@ -3173,6 +3179,9 @@ "ssec-gnome-hooks-gst-grl-plugins": [ "index.html#ssec-gnome-hooks-gst-grl-plugins" ], + "ssec-gnome-hooks-libglycin": [ + "index.html#ssec-gnome-hooks-libglycin" + ], "ssec-gnome-updating": [ "index.html#ssec-gnome-updating" ], diff --git a/pkgs/by-name/li/libglycin/package.nix b/pkgs/by-name/li/libglycin/package.nix index 137e8aa9eaff..ca0310b0a27f 100644 --- a/pkgs/by-name/li/libglycin/package.nix +++ b/pkgs/by-name/li/libglycin/package.nix @@ -38,6 +38,8 @@ stdenv.mkDerivation (finalAttrs: { "devdoc" ]; + setupHook = ./path-hook.sh; + src = fetchFromGitLab { domain = "gitlab.gnome.org"; owner = "GNOME"; diff --git a/pkgs/by-name/li/libglycin/path-hook.sh b/pkgs/by-name/li/libglycin/path-hook.sh new file mode 100644 index 000000000000..19de8ecfbec2 --- /dev/null +++ b/pkgs/by-name/li/libglycin/path-hook.sh @@ -0,0 +1,18 @@ +find_glycin_loader_paths() { + if [ -d "$1/share/glycin-loaders" ]; then + addToSearchPath NIX_GLYCIN_LOADER_PATHS $1/share + fi +} + +addEnvHooks "$hostOffset" find_glycin_loader_paths + +glycinLoadersWrapperArgsHook() { + echo "executing glycinLoadersWrapperArgsHook" + if [[ -n "$NIX_GLYCIN_LOADER_PATHS" ]]; then + gappsWrapperArgs+=(--prefix XDG_DATA_DIRS : "$NIX_GLYCIN_LOADER_PATHS") + fi +} + +if [[ -z ${dontWrapGlycinLoaders:-} ]]; then + preFixupPhases+=(glycinLoadersWrapperArgsHook) +fi