From 00cd92968e19be6aae25e8e835fde490cfe77f4b Mon Sep 17 00:00:00 2001 From: Piotr Limanowski Date: Sat, 6 Oct 2018 17:55:21 +0200 Subject: [PATCH] skip buildEnv and create a package with /share/fonts --- modules/fonts/default.nix | 24 +++++++++++++----------- tests/fonts.nix | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/modules/fonts/default.nix b/modules/fonts/default.nix index 5c80b30f..ba775f3a 100644 --- a/modules/fonts/default.nix +++ b/modules/fonts/default.nix @@ -16,16 +16,22 @@ let hasExt = exts: name: foldl' (acc: ext: (hasSuffix ext name) || acc) false exts; in hasExt fontExt name; fontFiles = dir: filter isFont (readDirsRec dir); - print = font: "ln -fn '${font}' '/Library/Fonts/${baseNameOf font}'"; - printLinks = dir: concatMapStringsSep "\n" print (fontFiles dir); + libraryLink = font: "ln -fn '/run/current-system/sw/share/fonts/${baseNameOf font}' '/Library/Fonts/${baseNameOf font}'"; + outLink = font: "ln -sfn -t $out/share/fonts/ '${font}'"; + fontLinks = link: dir: concatMapStringsSep "\n" link (fontFiles dir); + systemFontsDir = pkgs.runCommand "systemFontsDir" {} '' + mkdir -p "$out/share/fonts" + echo ${toString config.fonts.fonts} + ${concatMapStringsSep "\n" (fontLinks outLink) config.fonts.fonts} + ''; in { options = { fonts = { enableFontDir = mkOption { default = false; description = '' - Whether to enable font directory management. - Important: enabling font directory management removes all manually-added fonts. + Whether to enable font directory management and link all fonts in /run/current-system/sw/share/fonts. + Important: removes all manually-added fonts. ''; }; fonts = mkOption { @@ -38,18 +44,14 @@ in { }; config = { - system.build.fonts = mkIf cfg.enableFontDir (pkgs.buildEnv { - name = "system-fonts"; - paths = cfg.fonts; - pathsToLink = "/share/fonts"; - }); system.activationScripts.fonts.text = "" + optionalString cfg.enableFontDir '' # Set up fonts. echo "resetting fonts..." >&2 fontrestore default -n 2>&1 | grep -o '/Library/Fonts/.*' | tr '\n' '\0' | xargs -0 rm || true echo "updating fonts..." >&2 - ${printLinks config.system.build.fonts} - ''; + ${fontLinks libraryLink systemFontsDir} + ''; + environment.systemPackages = [ systemFontsDir ]; environment.pathsToLink = [ "/share/fonts" ]; }; } diff --git a/tests/fonts.nix b/tests/fonts.nix index cde4d3ac..8a6eb6ea 100644 --- a/tests/fonts.nix +++ b/tests/fonts.nix @@ -11,7 +11,7 @@ in { test = '' echo checking installed fonts >&2 grep -o "fontrestore default -n" ${config.out}/activate - grep -o "/share/fonts/truetype/DejaVuSans.ttf' '/Library/Fonts/DejaVuSans.ttf'" ${config.out}/activate + grep -o "ln -fn '/run/current-system/sw/share/fonts/DejaVuSans.ttf' '/Library/Fonts/DejaVuSans.ttf'" ${config.out}/activate ''; }