1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2025-03-13 20:30:02 +00:00

adds recursive font searching

This commit is contained in:
Piotr Limanowski 2018-10-04 13:03:21 +02:00
parent 6d0cf2d842
commit 8fe33a584e
2 changed files with 12 additions and 6 deletions

View file

@ -4,8 +4,16 @@ with lib;
let
cfg = config.fonts;
fontFiles = env: with builtins;
filter (n: match ".*\\.ttf" n != null) (attrNames (readDir "${env}/share/fonts/truetype/"));
printLinks = dir: with builtins;
let readDirsRec = path: let
home = readDir path;
list = mapAttrsToList (name: type:
let newPath = "${path}/${name}";
in if (type == "directory" || type == "symlink") && !(hasSuffix ".ttf" name) then readDirsRec newPath else [ newPath ]) home;
in flatten list;
fontFiles = dir: filter (name: hasSuffix ".ttf" name) (readDirsRec dir);
print = font: "ln -fn '${font}' '/Library/Fonts/${baseNameOf font}'";
in concatMapStringsSep "\n" print (fontFiles dir);
in {
options = {
fonts = {
@ -29,10 +37,8 @@ in {
echo "resetting fonts..." >&2
fontrestore default -n 2>&1 | grep -o '/Library/Fonts/.*' | tr '\n' '\0' | xargs -0 rm || true
echo "updating fonts..." >&2
${concatMapStrings (font: "ln -fn '${config.system.build.fonts}/share/fonts/truetype/${font}' '/Library/Fonts/${font}'\n")
(fontFiles config.system.build.fonts)}
${printLinks config.system.build.fonts}
'';
environment.pathsToLink = [ "/share/fonts" ];
};
}

View file

@ -8,7 +8,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 "/share/fonts/truetype/DejaVuSans.ttf' '/Library/Fonts/DejaVuSans.ttf'" ${config.out}/activate
'';
}