From f19bcee3763151c1401ffa5a05384a0581b1ff3e Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Fri, 21 Oct 2022 08:32:31 +0200 Subject: [PATCH 1/7] webp-pixbuf-loader: Adopt by GNOME MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GNOME uses this for backgrounds so let’s add GNOME team to maintainers and adopt GNOME coding style aimed at cleaner git diffs: - Format with `nixpkgs-fmt` - Inherit `moduleDir` variable since it has the same name - Avoid re-using `pname` for `src` in case it is overwritten - Use conventional attribute ordering - Have one dependency per line in inputs - Move comments closer to what they describe - Wrap long substitute line - Quote bash values --- .../libraries/webp-pixbuf-loader/default.nix | 60 ++++++++++++------- 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/pkgs/development/libraries/webp-pixbuf-loader/default.nix b/pkgs/development/libraries/webp-pixbuf-loader/default.nix index 82ce1e4796d88..82c2d6a321802 100644 --- a/pkgs/development/libraries/webp-pixbuf-loader/default.nix +++ b/pkgs/development/libraries/webp-pixbuf-loader/default.nix @@ -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; }; From 4fb7c5fd58b363414383b8d16936a08172459583 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Fri, 21 Oct 2022 08:35:56 +0200 Subject: [PATCH 2/7] gnome.nautilus: Support thumbnailing WebP files Note that no other GNOME apps currently support WebP on NixOS because we lack a usable composition method for gdk-pixbuf caches. --- pkgs/desktops/gnome/core/nautilus/default.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkgs/desktops/gnome/core/nautilus/default.nix b/pkgs/desktops/gnome/core/nautilus/default.nix index 163c562a1ab67..5eacfdac5baa7 100644 --- a/pkgs/desktops/gnome/core/nautilus/default.nix +++ b/pkgs/desktops/gnome/core/nautilus/default.nix @@ -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" ) ''; From c789af60650f3f0f83f7dd0457802283430fa10a Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Fri, 21 Oct 2022 09:42:13 +0200 Subject: [PATCH 3/7] gnome._gdkPixbufCacheBuilder_DO_NOT_USE: Extract from nixos/gdk-pixbuf Unlike previously, we now fail loudly when a package not containing a gdk-pixbuf modules is passed. --- nixos/modules/services/x11/gdk-pixbuf.nix | 29 +++------------ pkgs/desktops/gnome/default.nix | 4 ++ .../gnome/gdk-pixbuf-cache-builder.nix | 37 +++++++++++++++++++ 3 files changed, 47 insertions(+), 23 deletions(-) create mode 100644 pkgs/desktops/gnome/gdk-pixbuf-cache-builder.nix diff --git a/nixos/modules/services/x11/gdk-pixbuf.nix b/nixos/modules/services/x11/gdk-pixbuf.nix index c80e2b22792aa..2105224f92ff3 100644 --- a/nixos/modules/services/x11/gdk-pixbuf.nix +++ b/nixos/modules/services/x11/gdk-pixbuf.nix @@ -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}"; }; diff --git a/pkgs/desktops/gnome/default.nix b/pkgs/desktops/gnome/default.nix index b8d48cf12fd5e..08dd450043ac9 100644 --- a/pkgs/desktops/gnome/default.nix +++ b/pkgs/desktops/gnome/default.nix @@ -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; }; diff --git a/pkgs/desktops/gnome/gdk-pixbuf-cache-builder.nix b/pkgs/desktops/gnome/gdk-pixbuf-cache-builder.nix new file mode 100644 index 0000000000000..22359e9a5827e --- /dev/null +++ b/pkgs/desktops/gnome/gdk-pixbuf-cache-builder.nix @@ -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" +'' From 7140875a66167240d502ff2205fd67892417fda8 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Fri, 21 Oct 2022 09:45:37 +0200 Subject: [PATCH 4/7] xdg-desktop-portal-gnome: Support WebP files A hack until gdk-pixbuf learns to support multiple cache files. --- .../libraries/xdg-desktop-portal-gnome/default.nix | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pkgs/development/libraries/xdg-desktop-portal-gnome/default.nix b/pkgs/development/libraries/xdg-desktop-portal-gnome/default.nix index 5339a0c54cbb8..83ea313f9e9a2 100644 --- a/pkgs/development/libraries/xdg-desktop-portal-gnome/default.nix +++ b/pkgs/development/libraries/xdg-desktop-portal-gnome/default.nix @@ -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; From e674c5bd2a85e3765edf41b8f381137d9d2d45be Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Fri, 21 Oct 2022 09:46:13 +0200 Subject: [PATCH 5/7] gnome.gnome-shell: Support WebP files A hack until gdk-pixbuf learns to support multiple cache files. --- pkgs/desktops/gnome/core/gnome-shell/default.nix | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkgs/desktops/gnome/core/gnome-shell/default.nix b/pkgs/desktops/gnome/core/gnome-shell/default.nix index ccc34ecca019e..050a88dd0b3e1 100644 --- a/pkgs/desktops/gnome/core/gnome-shell/default.nix +++ b/pkgs/desktops/gnome/core/gnome-shell/default.nix @@ -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 glib’s xdgmime is patched From b6804f78b76016eaddf1026ad918ed8db9175884 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Fri, 21 Oct 2022 09:48:14 +0200 Subject: [PATCH 6/7] gnome.gnome-control-center: Support WebP files A hack until gdk-pixbuf learns to support multiple cache files. --- .../gnome/core/gnome-control-center/default.nix | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkgs/desktops/gnome/core/gnome-control-center/default.nix b/pkgs/desktops/gnome/core/gnome-control-center/default.nix index 2c6db7f854aca..bd2777610fa3d 100644 --- a/pkgs/desktops/gnome/core/gnome-control-center/default.nix +++ b/pkgs/desktops/gnome/core/gnome-control-center/default.nix @@ -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" From a8e19491ddee91c4885e0c3282c0f6448ad023b6 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Fri, 21 Oct 2022 09:51:55 +0200 Subject: [PATCH 7/7] gnome.eog: Support WebP files A hack until gdk-pixbuf learns to support multiple cache files. --- pkgs/desktops/gnome/core/eog/default.nix | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkgs/desktops/gnome/core/eog/default.nix b/pkgs/desktops/gnome/core/eog/default.nix index ccb4d439240f9..e0a943a8e1ca3 100644 --- a/pkgs/desktops/gnome/core/eog/default.nix +++ b/pkgs/desktops/gnome/core/eog/default.nix @@ -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