diff options
| author | Mike Vink <59492084+ivi-vink@users.noreply.github.com> | 2025-01-16 22:22:34 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-16 22:22:34 +0100 |
| commit | 8e7bd91f353caacc0bc4105f573eb3e17f09e03a (patch) | |
| tree | c5059edcbebd9644290cad7c653c49a36d593021 /modules/fonts | |
| parent | 6bd39d420578aacf7c0bab7de3e7027b952115ae (diff) | |
| parent | bd921223ba7cdac346477d7ea5204d6f4736fcc6 (diff) | |
Diffstat (limited to 'modules/fonts')
| -rw-r--r-- | modules/fonts/default.nix | 94 |
1 files changed, 38 insertions, 56 deletions
diff --git a/modules/fonts/default.nix b/modules/fonts/default.nix index 16f0258..b0bd63f 100644 --- a/modules/fonts/default.nix +++ b/modules/fonts/default.nix @@ -1,37 +1,26 @@ { config, lib, pkgs, ... }: -with lib; - let cfg = config.fonts; in { 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 = { - fonts.fontDir.enable = mkOption { - type = types.bool; - default = false; - description = lib.mdDoc '' - 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; + fonts.packages = lib.mkOption { + type = lib.types.listOf lib.types.path; default = [ ]; - example = literalExpression "[ pkgs.dejavu_fonts ]"; - description = lib.mdDoc '' - List of fonts to install. - - Fonts present in later entries override those with the same filenames - in previous ones. + example = lib.literalExpression "[ pkgs.dejavu_fonts ]"; + description = '' + List of fonts to install into {file}`/Library/Fonts/Nix Fonts`. ''; }; }; @@ -42,43 +31,36 @@ in { preferLocalBuild = true; } '' mkdir -p $out/Library/Fonts - font_regexp='.*\.\(ttf\|ttc\|otf\|dfont\)' - find -L ${toString cfg.fonts} -regex "$font_regexp" -type f -print0 | while IFS= read -rd "" f; do - ln -sf "$f" $out/Library/Fonts - done + store_dir=${lib.escapeShellArg builtins.storeDir} + while IFS= read -rd "" f; do + dest="$out/Library/Fonts/Nix Fonts/''${f#"$store_dir/"}" + 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 '' - # Set up fonts. - 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 + system.activationScripts.fonts.text = '' + printf >&2 'setting up /Library/Fonts/Nix Fonts...\n' - if [[ "`sw_vers -productVersion`" < "13.0" ]]; then - fontrestore default -n 2>&1 | while read -r f; do - case $f in - /Library/Fonts/*) - font=''${f##*/} - if [ ! -e "$systemConfig/Library/Fonts/$font" ]; then - echo "removing font $font..." >&2 - rm "/Library/Fonts/$font" - fi - ;; - /*) - # ignoring unexpected fonts - ;; - esac - done - fi + # rsync uses the mtime + size of files to determine whether they + # need to be copied by default. This is inadequate for Nix store + # paths, but we don't want to use `--checksum` as it makes + # activation consistently slow when you have large fonts + # installed. Instead, we ensure that fonts are linked according to + # their full store paths in `system.build.fonts`, so that any + # given font path should only ever have one possible content. + ${pkgs.rsync}/bin/rsync \ + --archive \ + --copy-links \ + --delete-during \ + --delete-missing-args \ + "$systemConfig/Library/Fonts/Nix Fonts" \ + '/Library/Fonts/' ''; }; |
