mirror of
https://github.com/LnL7/nix-darwin.git
synced 2025-03-13 20:30:02 +00:00
Merge pull request #102 from peel/f-fonts-module
initialise fonts module
This commit is contained in:
commit
166560ca76
6 changed files with 78 additions and 0 deletions
|
@ -131,6 +131,7 @@ Whether to activate system at boot time.
|
|||
## Modules
|
||||
|
||||
- [`environment`](https://github.com/LnL7/nix-darwin/blob/master/modules/environment)
|
||||
- [`fonts`](https://github.com/LnL7/nix-darwin/blob/master/modules/fonts)
|
||||
- [`launchd.daemons`](https://github.com/LnL7/nix-darwin/blob/master/modules/launchd/launchd.nix)
|
||||
- [`launchd.envVariables`](https://github.com/LnL7/nix-darwin/blob/master/modules/launchd)
|
||||
- [`launchd.user.agents`](https://github.com/LnL7/nix-darwin/blob/master/modules/launchd/launchd.nix)
|
||||
|
|
|
@ -43,6 +43,7 @@ let
|
|||
./modules/nix/nix-info.nix
|
||||
./modules/nix/nixpkgs.nix
|
||||
./modules/environment
|
||||
./modules/fonts
|
||||
./modules/launchd
|
||||
./modules/services/activate-system
|
||||
./modules/services/buildkite-agent.nix
|
||||
|
|
57
modules/fonts/default.nix
Normal file
57
modules/fonts/default.nix
Normal file
|
@ -0,0 +1,57 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
with builtins;
|
||||
|
||||
let
|
||||
cfg = config.fonts;
|
||||
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);
|
||||
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 and link all fonts in <filename>/run/current-system/sw/share/fonts</filename>.
|
||||
Important: removes all manually-added fonts.
|
||||
'';
|
||||
};
|
||||
fonts = mkOption {
|
||||
type = types.listOf types.path;
|
||||
default = [];
|
||||
example = literalExample "[ pkgs.dejavu_fonts ]";
|
||||
description = "List of primary font paths.";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
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
|
||||
${fontLinks libraryLink systemFontsDir}
|
||||
'';
|
||||
environment.systemPackages = [ systemFontsDir ];
|
||||
environment.pathsToLink = [ "/share/fonts" ];
|
||||
};
|
||||
}
|
|
@ -64,6 +64,7 @@ in
|
|||
${cfg.activationScripts.time.text}
|
||||
${cfg.activationScripts.networking.text}
|
||||
${cfg.activationScripts.keyboard.text}
|
||||
${cfg.activationScripts.fonts.text}
|
||||
|
||||
${cfg.activationScripts.postActivation.text}
|
||||
|
||||
|
|
|
@ -114,6 +114,7 @@ let
|
|||
tests.system-path-fish = makeTest ./tests/system-path-fish.nix;
|
||||
tests.system-shells = makeTest ./tests/system-shells.nix;
|
||||
tests.users-groups = makeTest ./tests/users-groups.nix;
|
||||
tests.fonts = makeTest ./tests/fonts.nix;
|
||||
|
||||
}
|
||||
// (mapTestOn (packagePlatforms packageSet));
|
||||
|
|
17
tests/fonts.nix
Normal file
17
tests/fonts.nix
Normal file
|
@ -0,0 +1,17 @@
|
|||
{ config, pkgs, ... }:
|
||||
|
||||
let
|
||||
fonts = pkgs.runCommand "fonts-0.0.0" {} "mkdir -p $out";
|
||||
in {
|
||||
fonts = {
|
||||
enableFontDir = true;
|
||||
fonts = [ pkgs.dejavu_fonts ];
|
||||
};
|
||||
|
||||
test = ''
|
||||
echo checking installed fonts >&2
|
||||
grep -o "fontrestore default -n" ${config.out}/activate
|
||||
grep -o "ln -fn '/run/current-system/sw/share/fonts/DejaVuSans.ttf' '/Library/Fonts/DejaVuSans.ttf'" ${config.out}/activate
|
||||
'';
|
||||
}
|
||||
|
Loading…
Add table
Reference in a new issue