From c789af60650f3f0f83f7dd0457802283430fa10a Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Fri, 21 Oct 2022 09:42:13 +0200 Subject: [PATCH] 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 c80e2b22792a..2105224f92ff 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 b8d48cf12fd5..08dd450043ac 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 000000000000..22359e9a5827 --- /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" +''