Merge pull request #197029 from jtojnar/webp-loader

webp-pixbuf-loader: Adopt by GNOME
This commit is contained in:
Jan Tojnar 2022-10-25 17:02:06 +02:00 committed by GitHub
commit 361d98667c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 137 additions and 44 deletions

View File

@ -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.";
};
@ -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}";
};

View File

@ -22,6 +22,7 @@
, shared-mime-info
, wrapGAppsHook
, librsvg
, webp-pixbuf-loader
, libexif
, gobject-introspection
, gi-docgen
@ -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

View File

@ -33,6 +33,7 @@
, libpulseaudio
, libpwquality
, librsvg
, webp-pixbuf-loader
, libsecret
, libwacom
, libxml2
@ -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"

View File

@ -20,6 +20,7 @@
, shared-mime-info
, libgweather
, librsvg
, webp-pixbuf-loader
, geoclue2
, perl
, docbook_xml_dtd_45
@ -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 glibs xdgmime is patched

View File

@ -21,6 +21,7 @@
, libexif
, libseccomp
, librsvg
, webp-pixbuf-loader
, tracker
, tracker-miners
, gexiv2
@ -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"
)
'';

View File

@ -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; };

View File

@ -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"
''

View File

@ -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
@ -15,36 +22,47 @@ 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; {
@ -52,7 +70,7 @@ stdenv.mkDerivation rec {
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;
};

View File

@ -14,6 +14,8 @@
, xdg-desktop-portal
, wayland
, gnome
, librsvg
, webp-pixbuf-loader
}:
stdenv.mkDerivation rec {
@ -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;