Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webp-pixbuf-loader: Adopt by GNOME #197029

Merged
merged 7 commits into from
Oct 25, 2022
Merged
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
29 changes: 6 additions & 23 deletions nixos/modules/services/x11/gdk-pixbuf.nix
Original file line number Diff line number Diff line change
@@ -1,34 +1,17 @@
{ config, lib, pkgs, ... }:

with lib;

let
cfg = config.services.xserver.gdk-pixbuf;

# Get packages to generate the cache for. We always include gdk-pixbuf.
effectivePackages = unique ([pkgs.gdk-pixbuf] ++ cfg.modulePackages);

# Generate the cache file by running gdk-pixbuf-query-loaders for each
# package and concatenating the results.
loadersCache = pkgs.runCommand "gdk-pixbuf-loaders.cache" { preferLocalBuild = true; } ''
(
for package in ${concatStringsSep " " effectivePackages}; do
module_dir="$package/${pkgs.gdk-pixbuf.moduleDir}"
if [[ ! -d $module_dir ]]; then
echo "Warning (services.xserver.gdk-pixbuf): missing module directory $module_dir" 1>&2
continue
fi
GDK_PIXBUF_MODULEDIR="$module_dir" \
${pkgs.stdenv.hostPlatform.emulator pkgs.buildPackages} ${pkgs.gdk-pixbuf.dev}/bin/gdk-pixbuf-query-loaders
done
) > "$out"
'';
loadersCache = pkgs.gnome._gdkPixbufCacheBuilder_DO_NOT_USE {
extraLoaders = lib.unique (cfg.modulePackages);
};
in

{
options = {
services.xserver.gdk-pixbuf.modulePackages = mkOption {
type = types.listOf types.package;
services.xserver.gdk-pixbuf.modulePackages = lib.mkOption {
type = lib.types.listOf lib.types.package;
default = [ ];
description = lib.mdDoc "Packages providing GDK-Pixbuf modules, for cache generation.";
};
Expand All @@ -37,7 +20,7 @@ in
# If there is any package configured in modulePackages, we generate the
# loaders.cache based on that and set the environment variable
# GDK_PIXBUF_MODULE_FILE to point to it.
config = mkIf (cfg.modulePackages != []) {
config = lib.mkIf (cfg.modulePackages != []) {
environment.variables = {
GDK_PIXBUF_MODULE_FILE = "${loadersCache}";
};
Expand Down
12 changes: 12 additions & 0 deletions pkgs/desktops/gnome/core/eog/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
, shared-mime-info
, wrapGAppsHook
, librsvg
, webp-pixbuf-loader
, libexif
, gobject-introspection
, gi-docgen
Expand Down Expand Up @@ -78,6 +79,17 @@ stdenv.mkDerivation rec {
"-Dgtk_doc=true"
];

postInstall = ''
# Pull in WebP support for gnome-backgrounds.
# In postInstall to run before gappsWrapperArgsHook.
export GDK_PIXBUF_MODULE_FILE="${gnome._gdkPixbufCacheBuilder_DO_NOT_USE {
extraLoaders = [
librsvg
webp-pixbuf-loader
];
}}"
'';

preFixup = ''
gappsWrapperArgs+=(
# Thumbnailers
Expand Down
12 changes: 12 additions & 0 deletions pkgs/desktops/gnome/core/gnome-control-center/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
, libpulseaudio
, libpwquality
, librsvg
, webp-pixbuf-loader
, libsecret
, libwacom
, libxml2
Expand Down Expand Up @@ -139,6 +140,17 @@ stdenv.mkDerivation rec {
addToSearchPath "XDG_DATA_DIRS" "${polkit.out}/share"
'';

postInstall = ''
# Pull in WebP support for gnome-backgrounds.
# In postInstall to run before gappsWrapperArgsHook.
export GDK_PIXBUF_MODULE_FILE="${gnome._gdkPixbufCacheBuilder_DO_NOT_USE {
extraLoaders = [
librsvg
webp-pixbuf-loader
];
}}"
'';

preFixup = ''
gappsWrapperArgs+=(
--prefix XDG_DATA_DIRS : "${sound-theme-freedesktop}/share"
Expand Down
12 changes: 12 additions & 0 deletions pkgs/desktops/gnome/core/gnome-shell/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
, shared-mime-info
, libgweather
, librsvg
, webp-pixbuf-loader
, geoclue2
, perl
, docbook_xml_dtd_45
Expand Down Expand Up @@ -187,6 +188,17 @@ stdenv.mkDerivation rec {
rm data/theme/gnome-shell.css
'';

postInstall = ''
# Pull in WebP support for gnome-backgrounds.
# In postInstall to run before gappsWrapperArgsHook.
export GDK_PIXBUF_MODULE_FILE="${gnome._gdkPixbufCacheBuilder_DO_NOT_USE {
extraLoaders = [
librsvg
webp-pixbuf-loader
];
}}"
'';

preFixup = ''
gappsWrapperArgs+=(
# Until glib’s xdgmime is patched
Expand Down
2 changes: 2 additions & 0 deletions pkgs/desktops/gnome/core/nautilus/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
, libexif
, libseccomp
, librsvg
, webp-pixbuf-loader
, tracker
, tracker-miners
, gexiv2
Expand Down Expand Up @@ -106,6 +107,7 @@ stdenv.mkDerivation rec {
# Thumbnailers
--prefix XDG_DATA_DIRS : "${gdk-pixbuf}/share"
--prefix XDG_DATA_DIRS : "${librsvg}/share"
--prefix XDG_DATA_DIRS : "${webp-pixbuf-loader}/share"
--prefix XDG_DATA_DIRS : "${shared-mime-info}/share"
)
'';
Expand Down
4 changes: 4 additions & 0 deletions pkgs/desktops/gnome/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
lib.makeScope pkgs.newScope (self: with self; {
updateScript = callPackage ./update.nix { };

# Temporary helper until gdk-pixbuf supports multiple cache files.
# This will go away, do not use outside Nixpkgs.
_gdkPixbufCacheBuilder_DO_NOT_USE = callPackage ./gdk-pixbuf-cache-builder.nix { };

libsoup = pkgs.libsoup.override { gnomeSupport = true; };
libchamplain = pkgs.libchamplain.override { libsoup = libsoup; };

Expand Down
37 changes: 37 additions & 0 deletions pkgs/desktops/gnome/gdk-pixbuf-cache-builder.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
runCommand,
pkg-config,
gdk-pixbuf,
lib,
stdenv,
buildPackages,
}:

{
extraLoaders,
}:

let
# Get packages to generate the cache for. We always include gdk-pixbuf.
loaderPackages = [
gdk-pixbuf
] ++ extraLoaders;
in

# Generate the cache file by running gdk-pixbuf-query-loaders for each
# package and concatenating the results.
runCommand "gdk-pixbuf-loaders.cache" {
preferLocalBuild = true;
} ''
(
for package in ${lib.escapeShellArgs loaderPackages}; do
module_dir="$package/${gdk-pixbuf.moduleDir}"
if [[ ! -d "$module_dir" ]]; then
echo "Error: gdkPixbufCacheBuilder: Passed package “''${package}” does not contain GdkPixbuf loaders in “${gdk-pixbuf.moduleDir}”." 1>&2
exit 1
fi
GDK_PIXBUF_MODULEDIR="$module_dir" \
${stdenv.hostPlatform.emulator buildPackages} ${gdk-pixbuf.dev}/bin/gdk-pixbuf-query-loaders
done
) > "$out"
''
60 changes: 39 additions & 21 deletions pkgs/development/libraries/webp-pixbuf-loader/default.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
{ lib, stdenv, fetchFromGitHub
, meson, ninja, pkg-config, makeWrapper
, gdk-pixbuf, libwebp
{ lib
, stdenv
, fetchFromGitHub
, meson
, ninja
, pkg-config
, makeWrapper
, gdk-pixbuf
, libwebp
}:

let
moduleDir = gdk-pixbuf.moduleDir;
inherit (gdk-pixbuf) moduleDir;

# turning lib/gdk-pixbuf-#.#/#.#.#/loaders into lib/gdk-pixbuf-#.#/#.#.#/loaders.cache
# removeSuffix is just in case moduleDir gets a trailing slash
Expand All @@ -15,44 +22,55 @@ stdenv.mkDerivation rec {

src = fetchFromGitHub {
owner = "aruiz";
repo = pname;
repo = "webp-pixbuf-loader";
rev = version;
sha256 = "sha256-dcdydWYrXZJjo4FxJtvzGzrQLOs87/BmxshFZwsT2ws=";
};

# It looks for gdk-pixbuf-thumbnailer in this package's bin rather than the gdk-pixbuf bin. We need to patch that.
postPatch = ''
substituteInPlace webp-pixbuf.thumbnailer.in --replace @bindir@/gdk-pixbuf-thumbnailer $out/bin/webp-thumbnailer
'';
nativeBuildInputs = [
gdk-pixbuf
meson
ninja
pkg-config
makeWrapper
];

nativeBuildInputs = [ gdk-pixbuf meson ninja pkg-config makeWrapper ];
buildInputs = [ gdk-pixbuf libwebp ];
buildInputs = [
gdk-pixbuf
libwebp
];

mesonFlags = [
"-Dgdk_pixbuf_query_loaders_path=${gdk-pixbuf.dev}/bin/gdk-pixbuf-query-loaders"
"-Dgdk_pixbuf_moduledir=${placeholder "out"}/${moduleDir}"
];

# It assumes gdk-pixbuf-thumbnailer can find the webp loader in the loaders.cache referenced by environment variable, breaking containment.
# So we replace it with a wrapped executable.
postInstall = ''
mkdir -p $out/bin
makeWrapper ${gdk-pixbuf}/bin/gdk-pixbuf-thumbnailer $out/bin/webp-thumbnailer \
--set GDK_PIXBUF_MODULE_FILE $out/${loadersPath}
postPatch = ''
# It looks for gdk-pixbuf-thumbnailer in this package's bin rather than the gdk-pixbuf bin. We need to patch that.
substituteInPlace webp-pixbuf.thumbnailer.in \
--replace "@bindir@/gdk-pixbuf-thumbnailer" "$out/bin/webp-thumbnailer"
'';

# environment variables controlling loaders.cache generation by gdk-pixbuf-query-loaders
preInstall = ''
export GDK_PIXBUF_MODULE_FILE=$out/${loadersPath}
export GDK_PIXBUF_MODULEDIR=$out/${moduleDir}
# environment variables controlling loaders.cache generation by gdk-pixbuf-query-loaders
export GDK_PIXBUF_MODULE_FILE="$out/${loadersPath}"
export GDK_PIXBUF_MODULEDIR="$out/${moduleDir}"
'';

postInstall = ''
# It assumes gdk-pixbuf-thumbnailer can find the webp loader in the loaders.cache referenced by environment variable, breaking containment.
# So we replace it with a wrapped executable.
mkdir -p "$out/bin"
makeWrapper "${gdk-pixbuf}/bin/gdk-pixbuf-thumbnailer" "$out/bin/webp-thumbnailer" \
--set GDK_PIXBUF_MODULE_FILE "$out/${loadersPath}"
'';

meta = with lib; {
description = "WebP GDK Pixbuf Loader library";
homepage = "https://github.com/aruiz/webp-pixbuf-loader";
license = licenses.lgpl2Plus;
platforms = platforms.unix;
maintainers = [ maintainers.cwyc ];
maintainers = teams.gnome.members ++ [ maintainers.cwyc ];
# meson.build:16:0: ERROR: Program or command 'gcc' not found or not executable
broken = stdenv.isDarwin;
};
Expand Down
13 changes: 13 additions & 0 deletions pkgs/development/libraries/xdg-desktop-portal-gnome/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
, xdg-desktop-portal
, wayland
, gnome
, librsvg
, webp-pixbuf-loader
}:

stdenv.mkDerivation rec {
Expand Down Expand Up @@ -47,6 +49,17 @@ stdenv.mkDerivation rec {
"-Dsystemduserunitdir=${placeholder "out"}/lib/systemd/user"
];

postInstall = ''
# Pull in WebP support for gnome-backgrounds.
# In postInstall to run before gappsWrapperArgsHook.
export GDK_PIXBUF_MODULE_FILE="${gnome._gdkPixbufCacheBuilder_DO_NOT_USE {
extraLoaders = [
librsvg
webp-pixbuf-loader
];
}}"
'';

passthru = {
updateScript = gnome.updateScript {
packageName = pname;
Expand Down