From 883d3dde97c0fe3802f9f0da0df26551ad1ec074 Mon Sep 17 00:00:00 2001 From: Leah Amelia Chen Date: Thu, 12 Dec 2024 12:41:58 +0100 Subject: [PATCH 1/5] glycin-loaders: don't use `with lib;` --- pkgs/by-name/gl/glycin-loaders/package.nix | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkgs/by-name/gl/glycin-loaders/package.nix b/pkgs/by-name/gl/glycin-loaders/package.nix index 06bc12716d638..eef390f47e8b9 100644 --- a/pkgs/by-name/gl/glycin-loaders/package.nix +++ b/pkgs/by-name/gl/glycin-loaders/package.nix @@ -79,14 +79,14 @@ stdenv.mkDerivation (finalAttrs: { }; }; - meta = with lib; { + meta = { description = "Glycin loaders for several formats"; homepage = "https://gitlab.gnome.org/GNOME/glycin"; - teams = [ teams.gnome ]; - license = with licenses; [ + teams = [ lib.teams.gnome ]; + license = with lib.licenses; [ mpl20 # or lgpl21Plus ]; - platforms = platforms.linux; + platforms = lib.platforms.linux; }; }) From 30054bcca5a6a777b0a713f41cb3fb7342bdd059 Mon Sep 17 00:00:00 2001 From: Leah Amelia Chen Date: Thu, 12 Dec 2024 12:41:58 +0100 Subject: [PATCH 2/5] glycin-loaders: replace glycinPathsPatch with setup hook `glycinPathsPatch` doesn't work with apps that use `rustPlatform.cargoSetupHook` since it assumes a setup where snapshots of GNOME sources already contain vendored Rust dependencies under `vendor/`. The setup hook instead provides a much more flexible approach that uses the `$cargoDepsCopy` variable provided by `cargoSetupHook`, which points to the local, modifiable copy of Cargo dependencies, to patch `src/sandbox.rs` just like `glycinPathsPatch`. If `$cargoDepsCopy` is not found, then the old behavior is used where Cargo dependencies are assumed to be under `vendor/`. The setup hook also consolidates the various checksum patches and additions to `gappsWrapperArgs`, making packages that use glycin much more DRY. Hopefully, new packages using glycin would be able to simply add `glycin-loaders` to their `buildInputs`, and have it work OOTB. Co-authored-by: Seth Flynn --- doc/hooks/glycin-loaders.section.md | 44 ++++++++++++++++ doc/hooks/index.md | 1 + doc/languages-frameworks/gnome.section.md | 2 + doc/redirects.json | 21 ++++++++ pkgs/by-name/fr/fractal/package.nix | 15 +----- .../gl/glycin-loaders/fix-glycin-paths.patch | 24 --------- pkgs/by-name/gl/glycin-loaders/hook.sh | 50 +++++++++++++++++++ pkgs/by-name/gl/glycin-loaders/package.nix | 32 +++++++----- pkgs/by-name/lo/loupe/package.nix | 17 +------ pkgs/by-name/sn/snapshot/package.nix | 17 +------ 10 files changed, 140 insertions(+), 83 deletions(-) create mode 100644 doc/hooks/glycin-loaders.section.md delete mode 100644 pkgs/by-name/gl/glycin-loaders/fix-glycin-paths.patch create mode 100644 pkgs/by-name/gl/glycin-loaders/hook.sh diff --git a/doc/hooks/glycin-loaders.section.md b/doc/hooks/glycin-loaders.section.md new file mode 100644 index 0000000000000..f5117d43bb9fa --- /dev/null +++ b/doc/hooks/glycin-loaders.section.md @@ -0,0 +1,44 @@ +# glycin-loaders {#glycin-loaders-hook} + +[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 via [`wrapGAppsHook`](#ssec-gnome-hooks). Likewise, `glycin` itself requires a patch to its internal sandbox in order to find certain binaries and understand the `/nix/store` model. + +In Nixpkgs, this is all handled through the `glycin-loaders` setup hook. + +## Example code snippet {#glycin-loaders-hook-example-code-snippet} + +```nix +{ + lib, + rustPlatform, + glycin-loaders, + wrapGAppsHook4, +}: + +rustPlatform.buildRustPackage { + # ... + + cargoHash = "..."; + + nativeBuildInputs = [ wrapGAppsHook4 ]; + + buildInputs = [ glycin-loaders ]; + + # ... +} +``` + +## Variables controlling glycin-loaders {#glycin-loaders-hook-variables-controlling} + +### `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/`. + +### `dontPatchGlycinLoaders` {#dont-patch-glycin} + +Disables the patching of `glycin` crates in your Cargo dependencies. + +### `dontWrapGlycinLoaders` {#dont-wrap-glycin} + +Disable adding the Glycin loaders path `XDG_DATA_DIRS` with `wrapGAppsHook`. diff --git a/doc/hooks/index.md b/doc/hooks/index.md index cd04fd84495ab..230a07af8b221 100644 --- a/doc/hooks/index.md +++ b/doc/hooks/index.md @@ -17,6 +17,7 @@ cmake.section.md desktop-file-utils.section.md gdk-pixbuf.section.md ghc.section.md +glycin-loaders.section.md gnome.section.md haredo.section.md installShellFiles.section.md diff --git a/doc/languages-frameworks/gnome.section.md b/doc/languages-frameworks/gnome.section.md index 0b4d66a430f45..2b09fea731685 100644 --- a/doc/languages-frameworks/gnome.section.md +++ b/doc/languages-frameworks/gnome.section.md @@ -129,6 +129,8 @@ The hooks do the 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-glycin-loaders} `glycin-loader`'s [setup hook](#glycin-loaders-hook) will patch the crates of your build to work with Nix and 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 8210470b5bcb7..109bec4d8b5ce 100644 --- a/doc/redirects.json +++ b/doc/redirects.json @@ -2324,6 +2324,24 @@ "setup-hook-gdk-pixbuf": [ "index.html#setup-hook-gdk-pixbuf" ], + "glycin-loaders-hook": [ + "index.html#glycin-loaders-hook" + ], + "glycin-loaders-hook-example-code-snippet": [ + "index.html#glycin-loaders-hook-example-code-snippet" + ], + "glycin-loaders-hook-variables-controlling": [ + "index.html#glycin-loaders-hook-variables-controlling" + ], + "glycin-cargo-deps-path": [ + "index.html#glycin-cargo-deps-path" + ], + "dont-patch-glycin": [ + "index.html#dont-patch-glycin" + ], + "dont-wrap-glycin": [ + "index.html#dont-wrap-glycin" + ], "ghc": [ "index.html#ghc" ], @@ -3032,6 +3050,9 @@ "ssec-gnome-hooks-gst-grl-plugins": [ "index.html#ssec-gnome-hooks-gst-grl-plugins" ], + "ssec-gnome-hooks-glycin-loaders": [ + "index.html#ssec-gnome-hooks-glycin-loaders" + ], "ssec-gnome-updating": [ "index.html#ssec-gnome-updating" ], diff --git a/pkgs/by-name/fr/fractal/package.nix b/pkgs/by-name/fr/fractal/package.nix index cfa580c253c13..fd81ff920f18d 100644 --- a/pkgs/by-name/fr/fractal/package.nix +++ b/pkgs/by-name/fr/fractal/package.nix @@ -51,14 +51,6 @@ stdenv.mkDerivation (finalAttrs: { ./disable-debug.patch ]; - # Dirty approach to add patches after cargoSetupPostUnpackHook - # We should eventually use a cargo vendor patch hook instead - preConfigure = '' - pushd ../$(stripHash $cargoDeps)/glycin-2.* - patch -p3 < ${glycin-loaders.passthru.glycinPathsPatch} - popd - ''; - nativeBuildInputs = [ glib grass-sass @@ -77,6 +69,7 @@ stdenv.mkDerivation (finalAttrs: { buildInputs = [ glib + glycin-loaders gtk4 gtksourceview5 lcms2 @@ -96,12 +89,6 @@ stdenv.mkDerivation (finalAttrs: { gst-plugins-rs ]); - preFixup = '' - gappsWrapperArgs+=( - --prefix XDG_DATA_DIRS : "${glycin-loaders}/share" - ) - ''; - passthru = { updateScript = nix-update-script { }; }; diff --git a/pkgs/by-name/gl/glycin-loaders/fix-glycin-paths.patch b/pkgs/by-name/gl/glycin-loaders/fix-glycin-paths.patch deleted file mode 100644 index 27b4b14015887..0000000000000 --- a/pkgs/by-name/gl/glycin-loaders/fix-glycin-paths.patch +++ /dev/null @@ -1,24 +0,0 @@ -diff --git a/vendor/glycin/src/sandbox.rs b/vendor/glycin/src/sandbox.rs -index 08db832..4f44b21 100644 ---- a/vendor/glycin/src/sandbox.rs -+++ b/vendor/glycin/src/sandbox.rs -@@ -202,7 +202,7 @@ impl Sandbox { - - args.push(self.exec()); - -- ("bwrap".into(), args, Some(seccomp_memfd)) -+ ("@bwrap@".into(), args, Some(seccomp_memfd)) - } - SandboxMechanism::FlatpakSpawn => { - let memory_limit = Self::memory_limit(); -@@ -299,8 +299,8 @@ impl Sandbox { - "/", - // Make /usr available as read only - "--ro-bind", -- "/usr", -- "/usr", -+ "/nix/store", -+ "/nix/store", - // Make tmpfs dev available - "--dev", - "/dev", diff --git a/pkgs/by-name/gl/glycin-loaders/hook.sh b/pkgs/by-name/gl/glycin-loaders/hook.sh new file mode 100644 index 0000000000000..4692d5f190e27 --- /dev/null +++ b/pkgs/by-name/gl/glycin-loaders/hook.sh @@ -0,0 +1,50 @@ +glycinLoadersPatchHook() { + echo "executing glycinLoadersPatchHook" + + local glycinPath + + if [[ -z ${glycinCargoDepsPath:-} ]]; then + # When cargoSetupHook is used, `cargoDepsCopy` would be set and preferred. + # Otherwise, fallback to vendor/ + local cargoDepsPath=${cargoDepsCopy:-vendor} + fi + + while read -r path; do + # Ensure the paths we're patching exist (and that this crate probably isn't something like glycin-utils) + if [[ -f $path/src/sandbox.rs ]]; then + glycinPath="$path" + break + fi + done < <(find "$cargoDepsPath" -type d -name 'glycin*') + + if [[ -z ${glycinPath:-} ]]; then + echo >&2 "error: glycin was not found within the cargo dependencies at '$cargoDepsPath'." + echo >&2 "are you sure glycin-loaders is still required?" + exit 1 + fi + echo "patching glycin crate at '$glycinPath'" + + substituteInPlace "$glycinPath/src/sandbox.rs" \ + --replace-fail '"/usr"' '"/nix/store"' \ + --replace-fail '"bwrap"' '"@bwrap@"' + + # Replace hash of file we patch in vendored glycin. + jq \ + --arg hash "$(sha256sum "$glycinPath/src/sandbox.rs" | cut -d' ' -f 1)" \ + '.files."src/sandbox.rs" = $hash' \ + "$glycinPath/.cargo-checksum.json" | + sponge "$glycinPath/.cargo-checksum.json" +} + +glycinLoadersWrapperArgsHook() { + echo "executing glycinLoadersWrapperArgsHook" + gappsWrapperArgs+=(--prefix XDG_DATA_DIRS : "@out@/share") +} + +if [[ -z ${dontPatchGlycinLoaders:-} ]]; then + prePatchHooks+=(glycinLoadersPatchHook) +fi + +if [[ -z ${dontWrapGlycinLoaders:-} ]]; then + preFixupPhases+=(glycinLoadersWrapperArgsHook) +fi diff --git a/pkgs/by-name/gl/glycin-loaders/package.nix b/pkgs/by-name/gl/glycin-loaders/package.nix index eef390f47e8b9..dd75c40a5359a 100644 --- a/pkgs/by-name/gl/glycin-loaders/package.nix +++ b/pkgs/by-name/gl/glycin-loaders/package.nix @@ -2,7 +2,6 @@ stdenv, lib, fetchurl, - replaceVars, bubblewrap, cairo, cargo, @@ -10,6 +9,7 @@ git, gnome, gtk4, + jq, lcms2, libheif, libjxl, @@ -17,6 +17,7 @@ libseccomp, libxml2, meson, + moreutils, ninja, pkg-config, rustc, @@ -26,19 +27,16 @@ stdenv.mkDerivation (finalAttrs: { pname = "glycin-loaders"; version = "1.2.3"; + outputs = [ + "out" + "dev" + ]; + src = fetchurl { url = "mirror://gnome/sources/glycin/${lib.versions.majorMinor finalAttrs.version}/glycin-${finalAttrs.version}.tar.xz"; hash = "sha256-OAqv4r+07KDEW0JmDr/0SWANAKQ7YJ1bHIP3lfXI+zw="; }; - patches = [ - # Fix paths in glycin library. - # Not actually needed for this package since we are only building loaders - # and this patch is relevant just to apps that use the loaders - # but apply it here to ensure the patch continues to apply. - finalAttrs.passthru.glycinPathsPatch - ]; - nativeBuildInputs = [ cargo gettext # for msgfmt @@ -49,6 +47,12 @@ stdenv.mkDerivation (finalAttrs: { rustc ]; + # Required for setup hook + propagatedNativeBuildInputs = [ + jq + moreutils + ]; + buildInputs = [ gtk4 # for GdkTexture cairo @@ -68,15 +72,17 @@ stdenv.mkDerivation (finalAttrs: { strictDeps = true; + setupHook = ./hook.sh; + + env = { + bwrap = lib.getExe bubblewrap; + }; + passthru = { updateScript = gnome.updateScript { attrPath = "glycin-loaders"; packageName = "glycin"; }; - - glycinPathsPatch = replaceVars ./fix-glycin-paths.patch { - bwrap = "${bubblewrap}/bin/bwrap"; - }; }; meta = { diff --git a/pkgs/by-name/lo/loupe/package.nix b/pkgs/by-name/lo/loupe/package.nix index 4f887f68316aa..49efead887ca0 100644 --- a/pkgs/by-name/lo/loupe/package.nix +++ b/pkgs/by-name/lo/loupe/package.nix @@ -50,6 +50,7 @@ stdenv.mkDerivation (finalAttrs: { ]; buildInputs = [ + glycin-loaders gtk4 lcms2 libadwaita @@ -57,22 +58,6 @@ stdenv.mkDerivation (finalAttrs: { libseccomp ]; - preConfigure = '' - # Dirty approach to add patches after cargoSetupPostUnpackHook - # We should eventually use a cargo vendor patch hook instead - pushd ../$(stripHash $cargoDeps)/glycin-2.* - patch -p3 < ${glycin-loaders.passthru.glycinPathsPatch} - popd - ''; - - preFixup = '' - # Needed for the glycin crate to find loaders. - # https://gitlab.gnome.org/sophie-h/glycin/-/blob/0.1.beta.2/glycin/src/config.rs#L44 - gappsWrapperArgs+=( - --prefix XDG_DATA_DIRS : "${glycin-loaders}/share" - ) - ''; - passthru = { updateScript = let diff --git a/pkgs/by-name/sn/snapshot/package.nix b/pkgs/by-name/sn/snapshot/package.nix index 0bd79455bc32e..aeb393fec2644 100644 --- a/pkgs/by-name/sn/snapshot/package.nix +++ b/pkgs/by-name/sn/snapshot/package.nix @@ -31,11 +31,6 @@ stdenv.mkDerivation (finalAttrs: { hash = "sha256-OTF2hZogt9I138MDAxuiDGhkQRBpiNyRHdkbe21m4f0="; }; - patches = [ - # Fix paths in glycin library - glycin-loaders.passthru.glycinPathsPatch - ]; - nativeBuildInputs = [ cargo desktop-file-utils @@ -50,6 +45,7 @@ stdenv.mkDerivation (finalAttrs: { buildInputs = [ glib + glycin-loaders gst_all_1.gst-plugins-bad gst_all_1.gst-plugins-base gst_all_1.gst-plugins-good @@ -62,21 +58,10 @@ stdenv.mkDerivation (finalAttrs: { pipewire # for device provider ]; - postPatch = '' - # Replace hash of file we patch in vendored glycin. - jq \ - --arg hash "$(sha256sum vendor/glycin/src/sandbox.rs | cut -d' ' -f 1)" \ - '.files."src/sandbox.rs" = $hash' \ - vendor/glycin/.cargo-checksum.json \ - | sponge vendor/glycin/.cargo-checksum.json - ''; - preFixup = '' gappsWrapperArgs+=( # vp8enc preset --prefix GST_PRESET_PATH : "${gst_all_1.gst-plugins-good}/share/gstreamer-1.0/presets" - # See https://gitlab.gnome.org/sophie-h/glycin/-/blob/0.1.beta.2/glycin/src/config.rs#L44 - --prefix XDG_DATA_DIRS : "${glycin-loaders}/share" ) ''; From a6d199241824249db3c4ad0ee1fac448ffe65b44 Mon Sep 17 00:00:00 2001 From: Leah Amelia Chen Date: Wed, 20 Aug 2025 18:40:10 -0400 Subject: [PATCH 3/5] snapshot: don't use `with lib;` --- pkgs/by-name/sn/snapshot/package.nix | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkgs/by-name/sn/snapshot/package.nix b/pkgs/by-name/sn/snapshot/package.nix index aeb393fec2644..8e80859c18f2f 100644 --- a/pkgs/by-name/sn/snapshot/package.nix +++ b/pkgs/by-name/sn/snapshot/package.nix @@ -69,12 +69,12 @@ stdenv.mkDerivation (finalAttrs: { packageName = "snapshot"; }; - meta = with lib; { + meta = { homepage = "https://gitlab.gnome.org/GNOME/snapshot"; description = "Take pictures and videos on your computer, tablet, or phone"; - teams = [ teams.gnome ]; - license = licenses.gpl3Plus; - platforms = platforms.unix; + teams = [ lib.teams.gnome ]; + license = lib.licenses.gpl3Plus; + platforms = lib.platforms.unix; mainProgram = "snapshot"; }; }) From 2dd23b7c341301a317eaec617f078aca555115a8 Mon Sep 17 00:00:00 2001 From: Leah Amelia Chen Date: Wed, 20 Aug 2025 18:40:30 -0400 Subject: [PATCH 4/5] loupe: don't use `with lib;` --- pkgs/by-name/lo/loupe/package.nix | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkgs/by-name/lo/loupe/package.nix b/pkgs/by-name/lo/loupe/package.nix index 49efead887ca0..ca8d618884aa0 100644 --- a/pkgs/by-name/lo/loupe/package.nix +++ b/pkgs/by-name/lo/loupe/package.nix @@ -88,14 +88,14 @@ stdenv.mkDerivation (finalAttrs: { ]; }; - meta = with lib; { + meta = { homepage = "https://gitlab.gnome.org/GNOME/loupe"; changelog = "https://gitlab.gnome.org/GNOME/loupe/-/blob/${finalAttrs.version}/NEWS?ref_type=tags"; description = "Simple image viewer application written with GTK4 and Rust"; - license = licenses.gpl3Plus; - maintainers = with maintainers; [ jk ]; - teams = [ teams.gnome ]; - platforms = platforms.unix; + license = lib.licenses.gpl3Plus; + maintainers = with lib.maintainers; [ jk ]; + teams = [ lib.teams.gnome ]; + platforms = lib.platforms.unix; mainProgram = "loupe"; }; }) From 16ab70a3858a62446ad29ef24af58b9416290df1 Mon Sep 17 00:00:00 2001 From: Seth Flynn Date: Wed, 20 Aug 2025 18:41:02 -0400 Subject: [PATCH 5/5] authenticator: remove unneeded glycin-loaders dependency --- pkgs/by-name/au/authenticator/package.nix | 3 --- 1 file changed, 3 deletions(-) diff --git a/pkgs/by-name/au/authenticator/package.nix b/pkgs/by-name/au/authenticator/package.nix index 082bada63e836..d17ae0756f478 100644 --- a/pkgs/by-name/au/authenticator/package.nix +++ b/pkgs/by-name/au/authenticator/package.nix @@ -21,7 +21,6 @@ sqlite, wayland, zbar, - glycin-loaders, nix-update-script, }: @@ -78,8 +77,6 @@ stdenv.mkDerivation (finalAttrs: { gappsWrapperArgs+=( # vp8enc preset --prefix GST_PRESET_PATH : "${gst_all_1.gst-plugins-good}/share/gstreamer-1.0/presets" - # See https://gitlab.gnome.org/sophie-h/glycin/-/blob/0.1.beta.2/glycin/src/config.rs#L44 - --prefix XDG_DATA_DIRS : "${glycin-loaders}/share" ) '';