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.

+47 -23
+6 -23
nixos/modules/services/x11/gdk-pixbuf.nix
··· 1 1 { config, lib, pkgs, ... }: 2 2 3 - with lib; 4 - 5 3 let 6 4 cfg = config.services.xserver.gdk-pixbuf; 7 5 8 - # Get packages to generate the cache for. We always include gdk-pixbuf. 9 - effectivePackages = unique ([pkgs.gdk-pixbuf] ++ cfg.modulePackages); 10 - 11 - # Generate the cache file by running gdk-pixbuf-query-loaders for each 12 - # package and concatenating the results. 13 - loadersCache = pkgs.runCommand "gdk-pixbuf-loaders.cache" { preferLocalBuild = true; } '' 14 - ( 15 - for package in ${concatStringsSep " " effectivePackages}; do 16 - module_dir="$package/${pkgs.gdk-pixbuf.moduleDir}" 17 - if [[ ! -d $module_dir ]]; then 18 - echo "Warning (services.xserver.gdk-pixbuf): missing module directory $module_dir" 1>&2 19 - continue 20 - fi 21 - GDK_PIXBUF_MODULEDIR="$module_dir" \ 22 - ${pkgs.stdenv.hostPlatform.emulator pkgs.buildPackages} ${pkgs.gdk-pixbuf.dev}/bin/gdk-pixbuf-query-loaders 23 - done 24 - ) > "$out" 25 - ''; 6 + loadersCache = pkgs.gnome._gdkPixbufCacheBuilder_DO_NOT_USE { 7 + extraLoaders = lib.unique (cfg.modulePackages); 8 + }; 26 9 in 27 10 28 11 { 29 12 options = { 30 - services.xserver.gdk-pixbuf.modulePackages = mkOption { 31 - type = types.listOf types.package; 13 + services.xserver.gdk-pixbuf.modulePackages = lib.mkOption { 14 + type = lib.types.listOf lib.types.package; 32 15 default = [ ]; 33 16 description = lib.mdDoc "Packages providing GDK-Pixbuf modules, for cache generation."; 34 17 }; ··· 37 20 # If there is any package configured in modulePackages, we generate the 38 21 # loaders.cache based on that and set the environment variable 39 22 # GDK_PIXBUF_MODULE_FILE to point to it. 40 - config = mkIf (cfg.modulePackages != []) { 23 + config = lib.mkIf (cfg.modulePackages != []) { 41 24 environment.variables = { 42 25 GDK_PIXBUF_MODULE_FILE = "${loadersCache}"; 43 26 };
+4
pkgs/desktops/gnome/default.nix
··· 3 3 lib.makeScope pkgs.newScope (self: with self; { 4 4 updateScript = callPackage ./update.nix { }; 5 5 6 + # Temporary helper until gdk-pixbuf supports multiple cache files. 7 + # This will go away, do not use outside Nixpkgs. 8 + _gdkPixbufCacheBuilder_DO_NOT_USE = callPackage ./gdk-pixbuf-cache-builder.nix { }; 9 + 6 10 libsoup = pkgs.libsoup.override { gnomeSupport = true; }; 7 11 libchamplain = pkgs.libchamplain.override { libsoup = libsoup; }; 8 12
+37
pkgs/desktops/gnome/gdk-pixbuf-cache-builder.nix
··· 1 + { 2 + runCommand, 3 + pkg-config, 4 + gdk-pixbuf, 5 + lib, 6 + stdenv, 7 + buildPackages, 8 + }: 9 + 10 + { 11 + extraLoaders, 12 + }: 13 + 14 + let 15 + # Get packages to generate the cache for. We always include gdk-pixbuf. 16 + loaderPackages = [ 17 + gdk-pixbuf 18 + ] ++ extraLoaders; 19 + in 20 + 21 + # Generate the cache file by running gdk-pixbuf-query-loaders for each 22 + # package and concatenating the results. 23 + runCommand "gdk-pixbuf-loaders.cache" { 24 + preferLocalBuild = true; 25 + } '' 26 + ( 27 + for package in ${lib.escapeShellArgs loaderPackages}; do 28 + module_dir="$package/${gdk-pixbuf.moduleDir}" 29 + if [[ ! -d "$module_dir" ]]; then 30 + echo "Error: gdkPixbufCacheBuilder: Passed package “''${package}” does not contain GdkPixbuf loaders in “${gdk-pixbuf.moduleDir}”." 1>&2 31 + exit 1 32 + fi 33 + GDK_PIXBUF_MODULEDIR="$module_dir" \ 34 + ${stdenv.hostPlatform.emulator buildPackages} ${gdk-pixbuf.dev}/bin/gdk-pixbuf-query-loaders 35 + done 36 + ) > "$out" 37 + ''