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, ... }: { config, lib, pkgs, ... }:
with lib;
let let
cfg = config.services.xserver.gdk-pixbuf; cfg = config.services.xserver.gdk-pixbuf;
# Get packages to generate the cache for. We always include gdk-pixbuf. loadersCache = pkgs.gnome._gdkPixbufCacheBuilder_DO_NOT_USE {
effectivePackages = unique ([pkgs.gdk-pixbuf] ++ cfg.modulePackages); extraLoaders = lib.unique (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"
'';
in in
{ {
options = { options = {
services.xserver.gdk-pixbuf.modulePackages = mkOption { services.xserver.gdk-pixbuf.modulePackages = lib.mkOption {
type = types.listOf types.package; type = lib.types.listOf lib.types.package;
default = [ ]; default = [ ];
description = lib.mdDoc "Packages providing GDK-Pixbuf modules, for cache generation."; 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 # If there is any package configured in modulePackages, we generate the
# loaders.cache based on that and set the environment variable # loaders.cache based on that and set the environment variable
# GDK_PIXBUF_MODULE_FILE to point to it. # GDK_PIXBUF_MODULE_FILE to point to it.
config = mkIf (cfg.modulePackages != []) { config = lib.mkIf (cfg.modulePackages != []) {
environment.variables = { environment.variables = {
GDK_PIXBUF_MODULE_FILE = "${loadersCache}"; GDK_PIXBUF_MODULE_FILE = "${loadersCache}";
}; };

View file

@ -22,6 +22,7 @@
, shared-mime-info , shared-mime-info
, wrapGAppsHook , wrapGAppsHook
, librsvg , librsvg
, webp-pixbuf-loader
, libexif , libexif
, gobject-introspection , gobject-introspection
, gi-docgen , gi-docgen
@ -78,6 +79,17 @@ stdenv.mkDerivation rec {
"-Dgtk_doc=true" "-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 = '' preFixup = ''
gappsWrapperArgs+=( gappsWrapperArgs+=(
# Thumbnailers # Thumbnailers

View file

@ -33,6 +33,7 @@
, libpulseaudio , libpulseaudio
, libpwquality , libpwquality
, librsvg , librsvg
, webp-pixbuf-loader
, libsecret , libsecret
, libwacom , libwacom
, libxml2 , libxml2
@ -139,6 +140,17 @@ stdenv.mkDerivation rec {
addToSearchPath "XDG_DATA_DIRS" "${polkit.out}/share" 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 = '' preFixup = ''
gappsWrapperArgs+=( gappsWrapperArgs+=(
--prefix XDG_DATA_DIRS : "${sound-theme-freedesktop}/share" --prefix XDG_DATA_DIRS : "${sound-theme-freedesktop}/share"

View file

@ -20,6 +20,7 @@
, shared-mime-info , shared-mime-info
, libgweather , libgweather
, librsvg , librsvg
, webp-pixbuf-loader
, geoclue2 , geoclue2
, perl , perl
, docbook_xml_dtd_45 , docbook_xml_dtd_45
@ -187,6 +188,17 @@ stdenv.mkDerivation rec {
rm data/theme/gnome-shell.css 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 = '' preFixup = ''
gappsWrapperArgs+=( gappsWrapperArgs+=(
# Until glibs xdgmime is patched # Until glibs xdgmime is patched

View file

@ -21,6 +21,7 @@
, libexif , libexif
, libseccomp , libseccomp
, librsvg , librsvg
, webp-pixbuf-loader
, tracker , tracker
, tracker-miners , tracker-miners
, gexiv2 , gexiv2
@ -106,6 +107,7 @@ stdenv.mkDerivation rec {
# Thumbnailers # Thumbnailers
--prefix XDG_DATA_DIRS : "${gdk-pixbuf}/share" --prefix XDG_DATA_DIRS : "${gdk-pixbuf}/share"
--prefix XDG_DATA_DIRS : "${librsvg}/share" --prefix XDG_DATA_DIRS : "${librsvg}/share"
--prefix XDG_DATA_DIRS : "${webp-pixbuf-loader}/share"
--prefix XDG_DATA_DIRS : "${shared-mime-info}/share" --prefix XDG_DATA_DIRS : "${shared-mime-info}/share"
) )
''; '';

View file

@ -3,6 +3,10 @@
lib.makeScope pkgs.newScope (self: with self; { lib.makeScope pkgs.newScope (self: with self; {
updateScript = callPackage ./update.nix { }; 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; }; libsoup = pkgs.libsoup.override { gnomeSupport = true; };
libchamplain = pkgs.libchamplain.override { libsoup = libsoup; }; 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 { lib
, meson, ninja, pkg-config, makeWrapper , stdenv
, gdk-pixbuf, libwebp , fetchFromGitHub
, meson
, ninja
, pkg-config
, makeWrapper
, gdk-pixbuf
, libwebp
}: }:
let let
moduleDir = gdk-pixbuf.moduleDir; inherit (gdk-pixbuf) moduleDir;
# turning lib/gdk-pixbuf-#.#/#.#.#/loaders into lib/gdk-pixbuf-#.#/#.#.#/loaders.cache # turning lib/gdk-pixbuf-#.#/#.#.#/loaders into lib/gdk-pixbuf-#.#/#.#.#/loaders.cache
# removeSuffix is just in case moduleDir gets a trailing slash # removeSuffix is just in case moduleDir gets a trailing slash
@ -15,36 +22,47 @@ stdenv.mkDerivation rec {
src = fetchFromGitHub { src = fetchFromGitHub {
owner = "aruiz"; owner = "aruiz";
repo = pname; repo = "webp-pixbuf-loader";
rev = version; rev = version;
sha256 = "sha256-dcdydWYrXZJjo4FxJtvzGzrQLOs87/BmxshFZwsT2ws="; 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. nativeBuildInputs = [
postPatch = '' gdk-pixbuf
substituteInPlace webp-pixbuf.thumbnailer.in --replace @bindir@/gdk-pixbuf-thumbnailer $out/bin/webp-thumbnailer meson
''; ninja
pkg-config
makeWrapper
];
nativeBuildInputs = [ gdk-pixbuf meson ninja pkg-config makeWrapper ]; buildInputs = [
buildInputs = [ gdk-pixbuf libwebp ]; gdk-pixbuf
libwebp
];
mesonFlags = [ mesonFlags = [
"-Dgdk_pixbuf_query_loaders_path=${gdk-pixbuf.dev}/bin/gdk-pixbuf-query-loaders" "-Dgdk_pixbuf_query_loaders_path=${gdk-pixbuf.dev}/bin/gdk-pixbuf-query-loaders"
"-Dgdk_pixbuf_moduledir=${placeholder "out"}/${moduleDir}" "-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. postPatch = ''
# So we replace it with a wrapped executable. # It looks for gdk-pixbuf-thumbnailer in this package's bin rather than the gdk-pixbuf bin. We need to patch that.
postInstall = '' substituteInPlace webp-pixbuf.thumbnailer.in \
mkdir -p $out/bin --replace "@bindir@/gdk-pixbuf-thumbnailer" "$out/bin/webp-thumbnailer"
makeWrapper ${gdk-pixbuf}/bin/gdk-pixbuf-thumbnailer $out/bin/webp-thumbnailer \
--set GDK_PIXBUF_MODULE_FILE $out/${loadersPath}
''; '';
# environment variables controlling loaders.cache generation by gdk-pixbuf-query-loaders
preInstall = '' preInstall = ''
export GDK_PIXBUF_MODULE_FILE=$out/${loadersPath} # environment variables controlling loaders.cache generation by gdk-pixbuf-query-loaders
export GDK_PIXBUF_MODULEDIR=$out/${moduleDir} 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; { meta = with lib; {
@ -52,7 +70,7 @@ stdenv.mkDerivation rec {
homepage = "https://github.com/aruiz/webp-pixbuf-loader"; homepage = "https://github.com/aruiz/webp-pixbuf-loader";
license = licenses.lgpl2Plus; license = licenses.lgpl2Plus;
platforms = platforms.unix; 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 # meson.build:16:0: ERROR: Program or command 'gcc' not found or not executable
broken = stdenv.isDarwin; broken = stdenv.isDarwin;
}; };

View file

@ -14,6 +14,8 @@
, xdg-desktop-portal , xdg-desktop-portal
, wayland , wayland
, gnome , gnome
, librsvg
, webp-pixbuf-loader
}: }:
stdenv.mkDerivation rec { stdenv.mkDerivation rec {
@ -47,6 +49,17 @@ stdenv.mkDerivation rec {
"-Dsystemduserunitdir=${placeholder "out"}/lib/systemd/user" "-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 = { passthru = {
updateScript = gnome.updateScript { updateScript = gnome.updateScript {
packageName = pname; packageName = pname;