mirror of
https://github.com/LnL7/nix-darwin.git
synced 2025-03-16 05:18:17 +00:00
Merge pull request #754 from emilazy/fonts-use-subdir
fonts: reimplement and rename to `fonts.packages`
This commit is contained in:
commit
801f8ab2bc
2 changed files with 43 additions and 64 deletions
|
@ -1,37 +1,26 @@
|
||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
with lib;
|
|
||||||
|
|
||||||
let
|
let
|
||||||
cfg = config.fonts;
|
cfg = config.fonts;
|
||||||
in
|
in
|
||||||
|
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
(mkRenamedOptionModule [ "fonts" "enableFontDir" ] [ "fonts" "fontDir" "enable" ])
|
(lib.mkRemovedOptionModule [ "fonts" "enableFontDir" ] "No nix-darwin equivalent to this NixOS option. This is not required to install fonts.")
|
||||||
|
(lib.mkRemovedOptionModule [ "fonts" "fontDir" "enable" ] "No nix-darwin equivalent to this NixOS option. This is not required to install fonts.")
|
||||||
|
(lib.mkRemovedOptionModule [ "fonts" "fonts" ] ''
|
||||||
|
This option has been renamed to `fonts.packages' for consistency with NixOS.
|
||||||
|
|
||||||
|
Note that the implementation now keeps fonts in `/Library/Fonts/Nix Fonts' to allow them to coexist with fonts not managed by nix-darwin; existing fonts will be left directly in `/Library/Fonts' without getting updates and should be manually removed.'')
|
||||||
];
|
];
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
fonts.fontDir.enable = mkOption {
|
fonts.packages = lib.mkOption {
|
||||||
type = types.bool;
|
type = lib.types.listOf lib.types.path;
|
||||||
default = false;
|
|
||||||
description = ''
|
|
||||||
Whether to enable font management and install configured fonts to
|
|
||||||
{file}`/Library/Fonts`.
|
|
||||||
|
|
||||||
NOTE: removes any manually-added fonts.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
fonts.fonts = mkOption {
|
|
||||||
type = types.listOf types.path;
|
|
||||||
default = [ ];
|
default = [ ];
|
||||||
example = literalExpression "[ pkgs.dejavu_fonts ]";
|
example = lib.literalExpression "[ pkgs.dejavu_fonts ]";
|
||||||
description = ''
|
description = ''
|
||||||
List of fonts to install.
|
List of fonts to install into {file}`/Library/Fonts/Nix Fonts`.
|
||||||
|
|
||||||
Fonts present in later entries override those with the same filenames
|
|
||||||
in previous ones.
|
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -42,43 +31,36 @@ in
|
||||||
{ preferLocalBuild = true; }
|
{ preferLocalBuild = true; }
|
||||||
''
|
''
|
||||||
mkdir -p $out/Library/Fonts
|
mkdir -p $out/Library/Fonts
|
||||||
font_regexp='.*\.\(ttf\|ttc\|otf\|dfont\)'
|
store_dir=${lib.escapeShellArg builtins.storeDir}
|
||||||
find -L ${toString cfg.fonts} -regex "$font_regexp" -type f -print0 | while IFS= read -rd "" f; do
|
while IFS= read -rd "" f; do
|
||||||
ln -sf "$f" $out/Library/Fonts
|
dest="$out/Library/Fonts/Nix Fonts/''${f#"$store_dir/"}"
|
||||||
done
|
mkdir -p "''${dest%/*}"
|
||||||
|
ln -sf "$f" "$dest"
|
||||||
|
done < <(
|
||||||
|
find -L ${lib.escapeShellArgs cfg.packages} \
|
||||||
|
-type f \
|
||||||
|
-regex '.*\.\(ttf\|ttc\|otf\|dfont\)' \
|
||||||
|
-print0
|
||||||
|
)
|
||||||
'';
|
'';
|
||||||
|
|
||||||
system.activationScripts.fonts.text = optionalString cfg.fontDir.enable ''
|
system.activationScripts.fonts.text = ''
|
||||||
# Set up fonts.
|
printf >&2 'setting up /Library/Fonts/Nix Fonts...\n'
|
||||||
echo "configuring fonts..." >&2
|
|
||||||
find -L "$systemConfig/Library/Fonts" -type f -print0 | while IFS= read -rd "" l; do
|
|
||||||
font=''${l##*/}
|
|
||||||
f=$(readlink -f "$l")
|
|
||||||
if [ ! -e "/Library/Fonts/$font" ]; then
|
|
||||||
echo "updating font $font..." >&2
|
|
||||||
ln -fn -- "$f" /Library/Fonts 2>/dev/null || {
|
|
||||||
echo "Could not create hard link. Nix is probably on another filesystem. Copying the font instead..." >&2
|
|
||||||
rsync -az --inplace "$f" /Library/Fonts
|
|
||||||
}
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [[ "`sw_vers -productVersion`" < "13.0" ]]; then
|
# rsync uses the mtime + size of files to determine whether they
|
||||||
fontrestore default -n 2>&1 | while read -r f; do
|
# need to be copied by default. This is inadequate for Nix store
|
||||||
case $f in
|
# paths, but we don't want to use `--checksum` as it makes
|
||||||
/Library/Fonts/*)
|
# activation consistently slow when you have large fonts
|
||||||
font=''${f##*/}
|
# installed. Instead, we ensure that fonts are linked according to
|
||||||
if [ ! -e "$systemConfig/Library/Fonts/$font" ]; then
|
# their full store paths in `system.build.fonts`, so that any
|
||||||
echo "removing font $font..." >&2
|
# given font path should only ever have one possible content.
|
||||||
rm "/Library/Fonts/$font"
|
${pkgs.rsync}/bin/rsync \
|
||||||
fi
|
--archive \
|
||||||
;;
|
--copy-links \
|
||||||
/*)
|
--delete-during \
|
||||||
# ignoring unexpected fonts
|
--delete-missing-args \
|
||||||
;;
|
"$systemConfig/Library/Fonts/Nix Fonts" \
|
||||||
esac
|
'/Library/Fonts/'
|
||||||
done
|
|
||||||
fi
|
|
||||||
'';
|
'';
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,22 +2,19 @@
|
||||||
|
|
||||||
let
|
let
|
||||||
font = pkgs.runCommand "font-0.0.0" {} ''
|
font = pkgs.runCommand "font-0.0.0" {} ''
|
||||||
mkdir -p $out/share/fonts
|
mkdir -p $out
|
||||||
touch $out/share/fonts/Font.ttf
|
touch $out/Font.ttf
|
||||||
'';
|
'';
|
||||||
in
|
in
|
||||||
|
|
||||||
{
|
{
|
||||||
fonts.fontDir.enable = true;
|
fonts.packages = [ font ];
|
||||||
fonts.fonts = [ font ];
|
|
||||||
|
|
||||||
test = ''
|
test = ''
|
||||||
echo "checking fonts in /Library/Fonts" >&2
|
echo "checking fonts in /Library/Fonts/Nix Fonts" >&2
|
||||||
test -e ${config.out}/Library/Fonts/Font.ttf
|
test -e "${config.out}/Library/Fonts/Nix Fonts"/*/Font.ttf
|
||||||
|
|
||||||
echo "checking activation of fonts in /activate" >&2
|
echo "checking activation of fonts in /activate" >&2
|
||||||
grep "fontrestore default -n 2>&1" ${config.out}/activate
|
grep '/Library/Fonts/Nix Fonts' ${config.out}/activate
|
||||||
grep 'ln -fn ".*" /Library/Fonts' ${config.out}/activate || grep 'rsync -az --inplace ".*" /Library/Fonts' ${config.out}/activate
|
|
||||||
grep 'rm "/Library/Fonts/.*"' ${config.out}/activate
|
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue