Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fonts module should use a subdirectory #722

Closed
lilyball opened this issue Jul 8, 2023 · 8 comments
Closed

Fonts module should use a subdirectory #722

lilyball opened this issue Jul 8, 2023 · 8 comments

Comments

@lilyball
Copy link
Contributor

lilyball commented Jul 8, 2023

Looking at the fonts module, it's documented as removing any fonts from /Library/Fonts not managed by nix-darwin. As of macOS 13.0 it doesn't do this anymore, but that appears to be a compromise for a bug, and I imagine that if a workaround is found in the future then the fonts module will start removing unmanaged fonts again.

In a quick experiment with ~/Library/Fonts, it appears that adding a subdirectory and placing a font in that subdirectory works fine. Upon doing so, Font Book immediately showed the new font.

Given this, it seems like a good approach here is to have nix-darwin create a subdirectory in /Library/Fonts where it can place everything. This will allow nix-darwin's fonts to coexist with externally-installed fonts and also make it easy to uninstall fonts that were removed from the nix-darwin configuration on macOS 13 (just rsync the whole folder instead of doing one-by-one font management). This also provides an easy way to uninstall fonts if I disable the fonts module (whereas today disabling the fonts module will leave all currently-installed fonts in place) as the activation script can unconditionally remove the folder if the option is disabled.

@lilyball
Copy link
Contributor Author

lilyball commented Jul 8, 2023

I just tested this out directly, copying all the fonts into /Library/Fonts/Nix Fonts works just fine on my macOS 13 system.

@emilazy
Copy link
Collaborator

emilazy commented Jul 8, 2023

Agreed. There's no reason to use fontrestore either. /Library/Fonts/Nix Fonts could probably just be a symlink directly into the store, unless that breaks something on the macOS end.

@LnL7
Copy link
Owner

LnL7 commented Jul 9, 2023

A subdirectory might work, but if I recall correctly the actual files need to be copied over so symlinks are a problem.

@lilyball
Copy link
Contributor Author

You can use rsync -L to instruct it to copy the symlink referents instead of the symlinks themselves.

@emilazy
Copy link
Collaborator

emilazy commented Jul 10, 2023

Yeah this is very easy to implement. The main question I have is how we should handle migration? We could just leave the old fonts there to rot, but I don't know how macOS will behave when you have an old and new version of the same font in /Library/Fonts. We could purge /Library/Fonts if there's no Nix Fonts subdirectory, but that would break toggling it on and off non-destructively. We could keep the current behaviour until you bump stateVersion, but then we have to keep the current wonky logic around forever. Maybe we could just make font activation on ≤ the current stateVersion error out and tell you to clean it up and bump stateVesion.

@lilyball
Copy link
Contributor Author

Font Book has an option to detect duplicate fonts, but it’s a manual process. Still, I think it’s largely harmless, though I don’t know what happens once the font gets updated.

nix-darwin could delete any fonts that are an exact match for the fonts it’s installing in the subdirectory, but that’s kind of surprising behavior as an ongoing thing. It could perhaps do this only if the subdirectory didn’t exist before, but it’s still a bit odd to do when enabling the module for the first time.

Maybe add a new option for using the subdirectory, default it to false for existing state versions and true for a new state version, and document it. This way users can set it themselves and know to clean up previously-installed fonts. Also perhaps mention this option in the docs for enable just to help make it more visible for folks turning on the module for the first time.

@what-the-functor
Copy link

what-the-functor commented Jul 11, 2023

How about, treat fonts that are already present, similar to the way that home-manager will handle shell profiles that are already present.
Warn that the font exists, and suggest a switch which, when applied will back up the original font, then overwrite it.

@emilazy
Copy link
Collaborator

emilazy commented Jul 11, 2023

The problem is that we shouldn't assume that all fonts in /Library/Fonts are owned by nix-darwin. That was historically meant to be the case with the option, but the point of moving to a subdirectory is to allow the user to install fonts in other ways too, and the removal behaviour has been broken for long enough that people are likely doing it anyway.

I think probably the best solution here is just another good reason for #727: switch wholesale over to the subdirectory and mention in release notes that the user should manually clean up old copies of fonts.

emilazy added a commit to emilazy/nix-darwin that referenced this issue Aug 3, 2023
emilazy added a commit to emilazy/nix-darwin that referenced this issue Aug 3, 2023
emilazy added a commit to emilazy/nix-darwin that referenced this issue Aug 4, 2023
347Online pushed a commit to 347Online/nix-darwin that referenced this issue Jun 16, 2024
kamushadenes pushed a commit to kamushadenes/nix-darwin that referenced this issue Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants