You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.7 KiB

  1. { config, pkgs, ... }:
  2. with pkgs.lib;
  3. let
  4. fontDirs = config.fonts.fonts;
  5. localDefs = with pkgs.builderDefs; pkgs.builderDefs.passthru.function rec {
  6. src = "";/* put a fetchurl here */
  7. buildInputs = [pkgs.xorg.mkfontdir pkgs.xorg.mkfontscale];
  8. inherit fontDirs;
  9. installPhase = fullDepEntry ("
  10. list='';
  11. for i in ${toString fontDirs} ; do
  12. if [ -d \$i/ ]; then
  13. list=\"\$list \$i\";
  14. fi;
  15. done
  16. list=\$(find \$list -name fonts.dir -o -name '*.ttf' -o -name '*.otf');
  17. fontDirs='';
  18. for i in \$list ; do
  19. fontDirs=\"\$fontDirs \$(dirname \$i)\";
  20. done;
  21. mkdir -p \$out/share/X11-fonts/;
  22. find \$fontDirs -type f -o -type l | while read i; do
  23. j=\"\${i##*/}\"
  24. if ! test -e \"\$out/share/X11-fonts/\${j}\"; then
  25. ln -s \"\$i\" \"\$out/share/X11-fonts/\${j}\";
  26. fi;
  27. done;
  28. cd \$out/share/X11-fonts/
  29. rm fonts.dir
  30. rm fonts.scale
  31. rm fonts.alias
  32. mkfontdir
  33. mkfontscale
  34. cat \$( find ${pkgs.xorg.fontalias}/ -name fonts.alias) >fonts.alias
  35. ") ["minInit" "addInputs"];
  36. };
  37. x11Fonts = with localDefs; stdenv.mkDerivation rec {
  38. name = "X11-fonts";
  39. builder = writeScript (name + "-builder")
  40. (textClosure localDefs
  41. [installPhase doForceShare doPropagate]);
  42. };
  43. in
  44. {
  45. options = {
  46. fonts = {
  47. enableFontDir = mkOption {
  48. default = false;
  49. description = ''
  50. Whether to create a directory with links to all fonts in
  51. <filename>/run/current-system/sw/share/X11-fonts</filename>.
  52. '';
  53. };
  54. };
  55. };
  56. config = mkIf config.fonts.enableFontDir {
  57. environment.systemPackages = [ x11Fonts ];
  58. };
  59. }