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