nixpkgs/nixos/modules/services/x11/gdk-pixbuf.nix

46 lines
1.4 KiB
Nix
Raw Normal View History

Use a NixOS module for generating the gdk-pixbuf loaders cache. Fixes issue #33231 and makes it possible to enable Plasma and KDE at the same time. Previously, this worked like this: - The gdk-pixbuf package comes with a cache file covering the modules bundled with gdk-pixbuf. - The librsvg package comes with a cache covering modules from gdk-pixbuf as well as librsvg. - plasma5 and xfce modules set the environment variable GDK_PIXBUF_MODULE_FILE to the one from librsvg, so that SVG was supported in addition to the formats supported by gdk-pixbuf. However if both were enabled a configuration conflict would result (despite setting to the same value). While this sort of worked (ignoring the conflict which perhaps could be hacked around), it is unscalable and a hack, as there would be a real problem when one wanted to add a third package that supports additional image formats. A new NixOS module (gdk-pixbuf) is added with a configuration option (modulePackages) that other modules use to request specific packages to be included in the loaders cache. When any package is present in the list, the module generates a system-wide loaders cache which includes the requested packages (and always gdk-pixbuf itself), and sets the environment variable GDK_PIXBUF_MODULE_FILE to point to the generated cache file. The plasma5 and xfce modules are updated to add librsvg to modulePackages instead of setting GDK_PIXBUF_MODULE_FILE. Note that many packages create wrappers that set GDK_PIXBUF_MODULE_FILE, some directly to the one from librsvg. Therefore this change does not change the existing hack in the librsvg package which ensures that file is generated. This change aims only to solve the conflict in the global environent variable configuration.
2018-06-25 13:11:59 +01:00
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.xserver.gdk-pixbuf;
2019-05-22 12:03:39 +01:00
# Get packages to generate the cache for. We always include gdk-pixbuf.
effectivePackages = unique ([pkgs.gdk-pixbuf] ++ cfg.modulePackages);
Use a NixOS module for generating the gdk-pixbuf loaders cache. Fixes issue #33231 and makes it possible to enable Plasma and KDE at the same time. Previously, this worked like this: - The gdk-pixbuf package comes with a cache file covering the modules bundled with gdk-pixbuf. - The librsvg package comes with a cache covering modules from gdk-pixbuf as well as librsvg. - plasma5 and xfce modules set the environment variable GDK_PIXBUF_MODULE_FILE to the one from librsvg, so that SVG was supported in addition to the formats supported by gdk-pixbuf. However if both were enabled a configuration conflict would result (despite setting to the same value). While this sort of worked (ignoring the conflict which perhaps could be hacked around), it is unscalable and a hack, as there would be a real problem when one wanted to add a third package that supports additional image formats. A new NixOS module (gdk-pixbuf) is added with a configuration option (modulePackages) that other modules use to request specific packages to be included in the loaders cache. When any package is present in the list, the module generates a system-wide loaders cache which includes the requested packages (and always gdk-pixbuf itself), and sets the environment variable GDK_PIXBUF_MODULE_FILE to point to the generated cache file. The plasma5 and xfce modules are updated to add librsvg to modulePackages instead of setting GDK_PIXBUF_MODULE_FILE. Note that many packages create wrappers that set GDK_PIXBUF_MODULE_FILE, some directly to the one from librsvg. Therefore this change does not change the existing hack in the librsvg package which ensures that file is generated. This change aims only to solve the conflict in the global environent variable configuration.
2018-06-25 13:11:59 +01:00
# 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; } ''
Use a NixOS module for generating the gdk-pixbuf loaders cache. Fixes issue #33231 and makes it possible to enable Plasma and KDE at the same time. Previously, this worked like this: - The gdk-pixbuf package comes with a cache file covering the modules bundled with gdk-pixbuf. - The librsvg package comes with a cache covering modules from gdk-pixbuf as well as librsvg. - plasma5 and xfce modules set the environment variable GDK_PIXBUF_MODULE_FILE to the one from librsvg, so that SVG was supported in addition to the formats supported by gdk-pixbuf. However if both were enabled a configuration conflict would result (despite setting to the same value). While this sort of worked (ignoring the conflict which perhaps could be hacked around), it is unscalable and a hack, as there would be a real problem when one wanted to add a third package that supports additional image formats. A new NixOS module (gdk-pixbuf) is added with a configuration option (modulePackages) that other modules use to request specific packages to be included in the loaders cache. When any package is present in the list, the module generates a system-wide loaders cache which includes the requested packages (and always gdk-pixbuf itself), and sets the environment variable GDK_PIXBUF_MODULE_FILE to point to the generated cache file. The plasma5 and xfce modules are updated to add librsvg to modulePackages instead of setting GDK_PIXBUF_MODULE_FILE. Note that many packages create wrappers that set GDK_PIXBUF_MODULE_FILE, some directly to the one from librsvg. Therefore this change does not change the existing hack in the librsvg package which ensures that file is generated. This change aims only to solve the conflict in the global environent variable configuration.
2018-06-25 13:11:59 +01:00
(
for package in ${concatStringsSep " " effectivePackages}; do
2019-05-22 12:03:39 +01:00
module_dir="$package/${pkgs.gdk-pixbuf.moduleDir}"
Use a NixOS module for generating the gdk-pixbuf loaders cache. Fixes issue #33231 and makes it possible to enable Plasma and KDE at the same time. Previously, this worked like this: - The gdk-pixbuf package comes with a cache file covering the modules bundled with gdk-pixbuf. - The librsvg package comes with a cache covering modules from gdk-pixbuf as well as librsvg. - plasma5 and xfce modules set the environment variable GDK_PIXBUF_MODULE_FILE to the one from librsvg, so that SVG was supported in addition to the formats supported by gdk-pixbuf. However if both were enabled a configuration conflict would result (despite setting to the same value). While this sort of worked (ignoring the conflict which perhaps could be hacked around), it is unscalable and a hack, as there would be a real problem when one wanted to add a third package that supports additional image formats. A new NixOS module (gdk-pixbuf) is added with a configuration option (modulePackages) that other modules use to request specific packages to be included in the loaders cache. When any package is present in the list, the module generates a system-wide loaders cache which includes the requested packages (and always gdk-pixbuf itself), and sets the environment variable GDK_PIXBUF_MODULE_FILE to point to the generated cache file. The plasma5 and xfce modules are updated to add librsvg to modulePackages instead of setting GDK_PIXBUF_MODULE_FILE. Note that many packages create wrappers that set GDK_PIXBUF_MODULE_FILE, some directly to the one from librsvg. Therefore this change does not change the existing hack in the librsvg package which ensures that file is generated. This change aims only to solve the conflict in the global environent variable configuration.
2018-06-25 13:11:59 +01:00
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" \
2019-05-22 12:03:39 +01:00
${pkgs.gdk-pixbuf.dev}/bin/gdk-pixbuf-query-loaders
Use a NixOS module for generating the gdk-pixbuf loaders cache. Fixes issue #33231 and makes it possible to enable Plasma and KDE at the same time. Previously, this worked like this: - The gdk-pixbuf package comes with a cache file covering the modules bundled with gdk-pixbuf. - The librsvg package comes with a cache covering modules from gdk-pixbuf as well as librsvg. - plasma5 and xfce modules set the environment variable GDK_PIXBUF_MODULE_FILE to the one from librsvg, so that SVG was supported in addition to the formats supported by gdk-pixbuf. However if both were enabled a configuration conflict would result (despite setting to the same value). While this sort of worked (ignoring the conflict which perhaps could be hacked around), it is unscalable and a hack, as there would be a real problem when one wanted to add a third package that supports additional image formats. A new NixOS module (gdk-pixbuf) is added with a configuration option (modulePackages) that other modules use to request specific packages to be included in the loaders cache. When any package is present in the list, the module generates a system-wide loaders cache which includes the requested packages (and always gdk-pixbuf itself), and sets the environment variable GDK_PIXBUF_MODULE_FILE to point to the generated cache file. The plasma5 and xfce modules are updated to add librsvg to modulePackages instead of setting GDK_PIXBUF_MODULE_FILE. Note that many packages create wrappers that set GDK_PIXBUF_MODULE_FILE, some directly to the one from librsvg. Therefore this change does not change the existing hack in the librsvg package which ensures that file is generated. This change aims only to solve the conflict in the global environent variable configuration.
2018-06-25 13:11:59 +01:00
done
) > "$out"
'';
in
{
options = {
services.xserver.gdk-pixbuf.modulePackages = mkOption {
type = types.listOf types.package;
default = [ ];
description = "Packages providing GDK-Pixbuf modules, for cache generation.";
};
};
# 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 != []) {
environment.variables = {
GDK_PIXBUF_MODULE_FILE = "${loadersCache}";
};
};
}