@@ -0,0 +1,45 @@
1+{ config, lib, pkgs, ... }:
2+
3+with lib;
4+
5+let
6+ cfg = config.services.xserver.gdk-pixbuf;
7+
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" {} ''
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.gdk_pixbuf.dev}/bin/gdk-pixbuf-query-loaders
23+ done
24+ ) > "$out"
25+ '';
26+in
27+
28+{
29+ options = {
30+ services.xserver.gdk-pixbuf.modulePackages = mkOption {
31+ type = types.listOf types.package;
32+ default = [ ];
33+ description = "Packages providing GDK-Pixbuf modules, for cache generation.";
34+ };
35+ };
36+
37+ # If there is any package configured in modulePackages, we generate the
38+ # loaders.cache based on that and set the environment variable
39+ # GDK_PIXBUF_MODULE_FILE to point to it.
40+ config = mkIf (cfg.modulePackages != []) {
41+ environment.variables = {
42+ GDK_PIXBUF_MODULE_FILE = "${loadersCache}";
43+ };
44+ };
45+}