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

fonts: extracts helpers to top-level let expr

This commit is contained in:
Piotr Limanowski 2018-10-05 19:17:43 +02:00
parent c2d7870587
commit da886d015c

View file

@ -1,23 +1,23 @@
{ config, lib, pkgs, ... }:
with lib;
with builtins;
let
cfg = config.fonts;
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") && !(isFont name) then readDirsRec newPath else [ newPath ]) home;
in flatten list;
isFont = name: let
fontExt = [ ".ttf" ".otf" ];
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}'";
in concatMapStringsSep "\n" print (fontFiles dir);
readDirsRec = path: let
home = readDir path;
list = mapAttrsToList (name: type:
let newPath = "${path}/${name}";
in if (type == "directory" || type == "symlink") && !(isFont name) then readDirsRec newPath else [ newPath ]) home;
in flatten list;
isFont = name: let
fontExt = [ ".ttf" ".otf" ];
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);
in {
options = {
fonts = {