Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions doc/hooks/glycin-loaders.section.md
Original file line number Diff line number Diff line change
@@ -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`.
1 change: 1 addition & 0 deletions doc/hooks/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions doc/languages-frameworks/gnome.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions doc/redirects.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
],
Expand Down Expand Up @@ -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"
],
Expand Down
3 changes: 0 additions & 3 deletions pkgs/by-name/au/authenticator/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
sqlite,
wayland,
zbar,
glycin-loaders,
nix-update-script,
}:

Expand Down Expand Up @@ -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"
)
'';

Expand Down
15 changes: 1 addition & 14 deletions pkgs/by-name/fr/fractal/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -77,6 +69,7 @@ stdenv.mkDerivation (finalAttrs: {

buildInputs = [
glib
glycin-loaders
gtk4
gtksourceview5
lcms2
Expand All @@ -96,12 +89,6 @@ stdenv.mkDerivation (finalAttrs: {
gst-plugins-rs
]);

preFixup = ''
gappsWrapperArgs+=(
--prefix XDG_DATA_DIRS : "${glycin-loaders}/share"
)
'';

passthru = {
updateScript = nix-update-script { };
};
Expand Down
24 changes: 0 additions & 24 deletions pkgs/by-name/gl/glycin-loaders/fix-glycin-paths.patch

This file was deleted.

50 changes: 50 additions & 0 deletions pkgs/by-name/gl/glycin-loaders/hook.sh
Original file line number Diff line number Diff line change
@@ -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
40 changes: 23 additions & 17 deletions pkgs/by-name/gl/glycin-loaders/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@
stdenv,
lib,
fetchurl,
replaceVars,
bubblewrap,
cairo,
cargo,
gettext,
git,
gnome,
gtk4,
jq,
lcms2,
libheif,
libjxl,
librsvg,
libseccomp,
libxml2,
meson,
moreutils,
ninja,
pkg-config,
rustc,
Expand All @@ -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
Expand All @@ -49,6 +47,12 @@ stdenv.mkDerivation (finalAttrs: {
rustc
];

# Required for setup hook
propagatedNativeBuildInputs = [
jq
moreutils
];

buildInputs = [
gtk4 # for GdkTexture
cairo
Expand All @@ -68,25 +72,27 @@ 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 = 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;
};
})
27 changes: 6 additions & 21 deletions pkgs/by-name/lo/loupe/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,14 @@ stdenv.mkDerivation (finalAttrs: {
];

buildInputs = [
glycin-loaders
gtk4
lcms2
libadwaita
libgweather
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
Expand Down Expand Up @@ -103,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";
};
})
Loading
Loading