From 0cbf0605d2faddba69ff8f897f574680992fd388 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 27 Jun 2013 13:12:45 +0200 Subject: [PATCH] Refactoring: Split fonts.nix into smaller modules --- modules/config/fonts.nix | 179 --------------------------- modules/config/fonts/corefonts.nix | 32 +++++ modules/config/fonts/fontconfig.nix | 45 +++++++ modules/config/fonts/fontdir.nix | 75 +++++++++++ modules/config/fonts/fonts.nix | 49 ++++++++ modules/config/fonts/ghostscript.nix | 32 +++++ modules/module-list.nix | 7 +- 7 files changed, 239 insertions(+), 180 deletions(-) delete mode 100644 modules/config/fonts.nix create mode 100644 modules/config/fonts/corefonts.nix create mode 100644 modules/config/fonts/fontconfig.nix create mode 100644 modules/config/fonts/fontdir.nix create mode 100644 modules/config/fonts/fonts.nix create mode 100644 modules/config/fonts/ghostscript.nix diff --git a/modules/config/fonts.nix b/modules/config/fonts.nix deleted file mode 100644 index 3516ed75ab61..000000000000 --- a/modules/config/fonts.nix +++ /dev/null @@ -1,179 +0,0 @@ -{ config, pkgs, ... }: - -with pkgs.lib; - -###### interface - -let - - options = { - - fonts = { - - enableFontConfig = mkOption { # !!! should be enableFontconfig - default = true; - description = " - If enabled, a Fontconfig configuration file will be built - pointing to a set of default fonts. If you don't care about - running X11 applications or any other program that uses - Fontconfig, you can turn this option off and prevent a - dependency on all those fonts. - "; - }; - - # Should be moved elsewhere. - enableGhostscriptFonts = mkOption { - default = false; - description = " - Whether to add the fonts provided by Ghostscript (such as - various URW fonts and the ``Base-14'' Postscript fonts) to the - list of system fonts, making them available to X11 - applications. - "; - }; - - enableFontDir = mkOption { - default = false; - description = " - Whether to create a directory with links to all fonts in share - - so user can configure vncserver script one time (I mean per-user - vncserver, so global service is not a good solution). - "; - }; - - # TODO: find another name for it. - fonts = mkOption { - default = [ - # - the user's .fonts directory - "~/.fonts" - # - the user's current profile - "~/.nix-profile/lib/X11/fonts" - "~/.nix-profile/share/fonts" - # - the default profile - "/nix/var/nix/profiles/default/lib/X11/fonts" - "/nix/var/nix/profiles/default/share/fonts" - ]; - description = " - List of primary font paths. - "; - apply = list: list ++ [ - # - a few statically built locations - pkgs.xorg.fontbhttf - pkgs.xorg.fontbhlucidatypewriter100dpi - pkgs.xorg.fontbhlucidatypewriter75dpi - pkgs.ttf_bitstream_vera - pkgs.freefont_ttf - pkgs.liberation_ttf - pkgs.xorg.fontbh100dpi - pkgs.xorg.fontmiscmisc - pkgs.xorg.fontcursormisc - ] - ++ optional config.fonts.enableCoreFonts pkgs.corefonts - ++ optional config.fonts.enableGhostscriptFonts "${pkgs.ghostscript}/share/ghostscript/fonts" - ++ config.fonts.extraFonts; - }; - - extraFonts = mkOption { - default = []; - example = [ pkgs.dejavu_fonts ]; - description = '' - List of packages with additional fonts. - ''; - }; - - enableCoreFonts = mkOption { - default = false; - description = '' - Whether to include Microsoft's proprietary Core Fonts. These fonts - are redistributable, but only verbatim, among other restrictions. - See - for details. - ''; - }; - - }; - - }; -in - -###### implementation -let - inherit (pkgs) builderDefs; - inherit (pkgs.xorg) mkfontdir mkfontscale fontalias; - - fontDirs = config.fonts.fonts; - - - localDefs = with builderDefs; builderDefs.passthru.function rec { - src = "";/* put a fetchurl here */ - - buildInputs = [mkfontdir mkfontscale]; - configureFlags = []; - inherit fontDirs; - installPhase = fullDepEntry (" - list=''; - for i in ${toString fontDirs} ; do - if [ -d \$i/ ]; then - list=\"\$list \$i\"; - fi; - done - list=\$(find \$list -name fonts.dir -o -name '*.ttf' -o -name '*.otf'); - fontDirs=''; - for i in \$list ; do - fontDirs=\"\$fontDirs \$(dirname \$i)\"; - done; - mkdir -p \$out/share/X11-fonts/; - find \$fontDirs -type f -o -type l | while read i; do - j=\"\${i##*/}\" - if ! test -e \"\$out/share/X11-fonts/\${j}\"; then - ln -s \"\$i\" \"\$out/share/X11-fonts/\${j}\"; - fi; - done; - cd \$out/share/X11-fonts/ - rm fonts.dir - rm fonts.scale - rm fonts.alias - mkfontdir - mkfontscale - cat \$( find ${fontalias}/ -name fonts.alias) >fonts.alias - ") ["minInit" "addInputs"]; - }; - - x11Fonts = with localDefs; stdenv.mkDerivation rec { - name = "X11-fonts"; - builder = writeScript (name + "-builder") - (textClosure localDefs - [installPhase doForceShare doPropagate]); - meta = { - description = " - Directory to contain all X11 fonts requested. - "; - }; - }; - -in - -{ - require = [options]; - - system.build.x11Fonts = x11Fonts; - - environment.etc = mkIf config.fonts.enableFontConfig - [ { # Configuration file for fontconfig used to locate - # (X11) client-rendered fonts. - source = pkgs.makeFontsConf { - fontDirectories = config.fonts.fonts; - }; - target = "fonts/fonts.conf"; - } - ]; - - environment.shellInit = - '' - export FONTCONFIG_FILE=/etc/fonts/fonts.conf - ''; - - environment.systemPackages = - optional config.fonts.enableFontDir config.system.build.x11Fonts ++ - optional config.fonts.enableFontConfig pkgs.fontconfig; -} diff --git a/modules/config/fonts/corefonts.nix b/modules/config/fonts/corefonts.nix new file mode 100644 index 000000000000..7de95200cfa9 --- /dev/null +++ b/modules/config/fonts/corefonts.nix @@ -0,0 +1,32 @@ +{ config, pkgs, ... }: + +with pkgs.lib; + +{ + + options = { + + fonts = { + + enableCoreFonts = mkOption { + default = false; + description = '' + Whether to include Microsoft's proprietary Core Fonts. These fonts + are redistributable, but only verbatim, among other restrictions. + See + for details. + ''; + }; + + }; + + }; + + + config = mkIf config.fonts.enableCoreFonts { + + fonts.extraFonts = [ pkgs.corefonts ]; + + }; + +} diff --git a/modules/config/fonts/fontconfig.nix b/modules/config/fonts/fontconfig.nix new file mode 100644 index 000000000000..ce3ffdffdc99 --- /dev/null +++ b/modules/config/fonts/fontconfig.nix @@ -0,0 +1,45 @@ +{ config, pkgs, ... }: + +with pkgs.lib; + +{ + + options = { + + fonts = { + + enableFontConfig = mkOption { # !!! should be enableFontconfig + default = true; + description = '' + If enabled, a Fontconfig configuration file will be built + pointing to a set of default fonts. If you don't care about + running X11 applications or any other program that uses + Fontconfig, you can turn this option off and prevent a + dependency on all those fonts. + ''; + }; + + }; + + }; + + + config = mkIf config.fonts.enableFontConfig { + + # Bring in the default (upstream) fontconfig configuration. + environment.etc."fonts/fonts.conf".source = + pkgs.makeFontsConf { fontDirectories = config.fonts.fonts; }; + + environment.shellInit = + '' + # FIXME: This variable is no longer needed, but we'll keep it + # around for a while for applications linked against old + # fontconfig builds. + export FONTCONFIG_FILE=/etc/fonts/fonts.conf + ''; + + environment.systemPackages = [ pkgs.fontconfig ]; + + }; + +} diff --git a/modules/config/fonts/fontdir.nix b/modules/config/fonts/fontdir.nix new file mode 100644 index 000000000000..a4f69809b2a4 --- /dev/null +++ b/modules/config/fonts/fontdir.nix @@ -0,0 +1,75 @@ +{ config, pkgs, ... }: + +with pkgs.lib; + +let + + fontDirs = config.fonts.fonts; + + localDefs = with pkgs.builderDefs; pkgs.builderDefs.passthru.function rec { + src = "";/* put a fetchurl here */ + buildInputs = [pkgs.xorg.mkfontdir pkgs.xorg.mkfontscale]; + inherit fontDirs; + installPhase = fullDepEntry (" + list=''; + for i in ${toString fontDirs} ; do + if [ -d \$i/ ]; then + list=\"\$list \$i\"; + fi; + done + list=\$(find \$list -name fonts.dir -o -name '*.ttf' -o -name '*.otf'); + fontDirs=''; + for i in \$list ; do + fontDirs=\"\$fontDirs \$(dirname \$i)\"; + done; + mkdir -p \$out/share/X11-fonts/; + find \$fontDirs -type f -o -type l | while read i; do + j=\"\${i##*/}\" + if ! test -e \"\$out/share/X11-fonts/\${j}\"; then + ln -s \"\$i\" \"\$out/share/X11-fonts/\${j}\"; + fi; + done; + cd \$out/share/X11-fonts/ + rm fonts.dir + rm fonts.scale + rm fonts.alias + mkfontdir + mkfontscale + cat \$( find ${pkgs.xorg.fontalias}/ -name fonts.alias) >fonts.alias + ") ["minInit" "addInputs"]; + }; + + x11Fonts = with localDefs; stdenv.mkDerivation rec { + name = "X11-fonts"; + builder = writeScript (name + "-builder") + (textClosure localDefs + [installPhase doForceShare doPropagate]); + }; + +in + +{ + + options = { + + fonts = { + + enableFontDir = mkOption { + default = false; + description = '' + Whether to create a directory with links to all fonts in + /run/current-system/sw/share/X11-fonts. + ''; + }; + + }; + + }; + + config = mkIf config.fonts.enableFontDir { + + environment.systemPackages = [ x11Fonts ]; + + }; + +} diff --git a/modules/config/fonts/fonts.nix b/modules/config/fonts/fonts.nix new file mode 100644 index 000000000000..f43784f6d03e --- /dev/null +++ b/modules/config/fonts/fonts.nix @@ -0,0 +1,49 @@ +{ config, pkgs, ... }: + +with pkgs.lib; + +{ + + options = { + + fonts = { + + # TODO: find another name for it. + fonts = mkOption { + default = [ + # - the user's .fonts directory + "~/.fonts" + # - the user's current profile + "~/.nix-profile/lib/X11/fonts" + "~/.nix-profile/share/fonts" + # - the default profile + "/nix/var/nix/profiles/default/lib/X11/fonts" + "/nix/var/nix/profiles/default/share/fonts" + ]; + description = "List of primary font paths."; + apply = list: list ++ [ + # - a few statically built locations + pkgs.xorg.fontbhttf + pkgs.xorg.fontbhlucidatypewriter100dpi + pkgs.xorg.fontbhlucidatypewriter75dpi + pkgs.ttf_bitstream_vera + pkgs.freefont_ttf + pkgs.liberation_ttf + pkgs.xorg.fontbh100dpi + pkgs.xorg.fontmiscmisc + pkgs.xorg.fontcursormisc + ] + ++ config.fonts.extraFonts; + }; + + extraFonts = mkOption { + default = []; + example = [ pkgs.dejavu_fonts ]; + description = "List of packages with additional fonts."; + }; + + }; + + }; + +} diff --git a/modules/config/fonts/ghostscript.nix b/modules/config/fonts/ghostscript.nix new file mode 100644 index 000000000000..9ef00396808c --- /dev/null +++ b/modules/config/fonts/ghostscript.nix @@ -0,0 +1,32 @@ +{ config, pkgs, ... }: + +with pkgs.lib; + +{ + + options = { + + fonts = { + + enableGhostscriptFonts = mkOption { + default = false; + description = '' + Whether to add the fonts provided by Ghostscript (such as + various URW fonts and the “Base-14” Postscript fonts) to the + list of system fonts, making them available to X11 + applications. + ''; + }; + + }; + + }; + + + config = mkIf config.fonts.enableGhostscriptFonts { + + fonts.extraFonts = [ "${pkgs.ghostscript}/share/ghostscript/fonts" ]; + + }; + +} diff --git a/modules/module-list.nix b/modules/module-list.nix index 6da86c0c6696..afc24f17c775 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -1,4 +1,9 @@ -[ ./config/fonts.nix +[ + ./config/fonts/corefonts.nix + ./config/fonts/fontconfig.nix + ./config/fonts/fontdir.nix + ./config/fonts/fonts.nix + ./config/fonts/ghostscript.nix ./config/gnu.nix ./config/i18n.nix ./config/krb5.nix