9 gtk.iconCache.enable = lib.mkOption {
10 type = lib.types.bool;
11 default = config.services.xserver.enable;
12 defaultText = lib.literalExpression "config.services.xserver.enable";
14 Whether to build icon theme caches for GTK applications.
19 config = lib.mkIf config.gtk.iconCache.enable {
21 # (Re)build icon theme caches
22 # ---------------------------
23 # Each icon theme has its own cache. The difficult is that many
24 # packages may contribute with icons to the same theme by installing
27 # For instance, on my current NixOS system, the following packages
28 # (among many others) have icons installed into the hicolor icon
29 # theme: hicolor-icon-theme, psensor, wpa_gui, caja, etc.
31 # As another example, the mate icon theme has icons installed by the
32 # packages mate-icon-theme, mate-settings-daemon, and libmateweather.
34 # The HighContrast icon theme also has icons from different packages,
35 # like gnome-theme-extras and meld.
37 # When the cache is built all of its icons has to be known. How to
40 # I think that most themes have all icons installed by only one
41 # package. On my system there are 71 themes installed. Only 3 of them
42 # have icons installed from more than one package.
44 # If the main package of the theme provides a cache, presumably most
45 # of its icons will be available to applications without running this
46 # module. But additional icons offered by other packages will not be
47 # available. Therefore I think that it is good that the main theme
48 # package installs a cache (although it does not completely fixes the
49 # situation for packages installed with nix-env).
51 # The module solution presented here keeps the cache when there is
52 # only one package contributing with icons to the theme. Otherwise it
53 # rebuilds the cache taking into account the icons provided all
56 environment.extraSetup = ''
57 # For each icon theme directory ...
58 find $out/share/icons -exec test -d {} ';' -mindepth 1 -maxdepth 1 -print0 | while read -d $'\0' themedir
60 # In order to build the cache, the theme dir should be
61 # writable. When the theme dir is a symbolic link to somewhere
62 # in the nix store it is not writable and it means that only
63 # one package is contributing to the theme. If it already has
64 # a cache, no rebuild is needed. Otherwise a cache has to be
65 # built, and to be able to do that we first remove the
66 # symbolic link and make a directory, and then make symbolic
67 # links from the original directory into the new one.
69 if [ ! -w "$themedir" -a -L "$themedir" -a ! -r "$themedir"/icon-theme.cache ]; then
70 name=$(basename "$themedir")
71 path=$(readlink -f "$themedir")
74 ln -s "$path"/* "$themedir"/
77 # (Re)build the cache if the theme dir is writable, replacing any
78 # existing cache for the theme
80 if [ -w "$themedir" ]; then
81 rm -f "$themedir"/icon-theme.cache
82 ${pkgs.buildPackages.gtk3.out}/bin/gtk-update-icon-cache --ignore-theme-index "$themedir"