Proliferation of symbolic links in /run/current-system/sw/share/icons

In NixOS when an icon theme is a parent of other icon themes from different packages and they are installed system wide, there are a proliferation of symbolic links in /run/current-system/sw/share/icons.

For refrence see:

Suppose a situation where an icon theme themeA is a parent theme of other icon themes theme1 and theme2. Because of that themeA would appear in the nix store several times: once in its own package, and also as a symbolic link in the packages of the child themes:

/nix/store/themeA_dir/share/icons/themeA
/nix/store/theme1_dir/share/icons/themeA -> /nix/store/themeA_dir/share/icons/themeA
/nix/store/theme2_dir/share/icons/themeA -> /nix/store/themeA_dir/share/icons/themeA

In this situation themeA would also appear several times in /run/current-system/sw/share/icons, generating conflicts:

/run/current-system/sw/share/icons/themeA -> /nix/store/themeA_dir/share/icons/themeA
/run/current-system/sw/share/icons/themeA -> /nix/store/theme1_dir/share/icons/themeA
/run/current-system/sw/share/icons/themeA -> /nix/store/theme2_dir/share/icons/themeA

But notice that all of them points to the same directory in the nix store after following the symbolic links.

When those collisions are detected by a nixos module, a new directory /run/current-system/sw/share/icons/themeA is created and the contents of /nix/store/themeA_dir/share/icons/themeA, /nix/store/theme1_dir/share/icons/themeA and /nix/store/theme2_dir/share/icons/themeA are recursively merged there. At the end each file in the theme is linked individually.

It would be much more efficient to detect that each of /nix/store/theme{A,1,2}_dir/share/icons/themeA resolves to the same directory in the nix store after following symbolic links, and just use it as the target link in /run/current-system/sw/share/icons.

I would like to know from others if this new approach is viable and can be implemented in NixOS.

cc @jtojnar @Mic92 @michaelpj @worldofpeace

I think it sounds reasonable.

Relevant file:

It is written in perl :frowning:

You don’t need to read the perl, the nix file describes the parameters for the buildEnv function: https://github.com/NixOS/nixpkgs/blob/ac44b7f958c51bd59b67eecf1efa1f17f0336f31/pkgs/build-support/buildenv/default.nix

I have submitted a pull request to implement this.