-
-
Notifications
You must be signed in to change notification settings - Fork 14.1k
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
mkFont derivation for unified font packaging #91518
base: master
Are you sure you want to change the base?
Conversation
I created diffs for all derivations, from For each derivation I output the file contents (just |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/guidelines-on-packaging-fonts/7683/3 |
find -iname '*.ttc' -print0 | xargs -0 -r install -v -m644 --target $out/share/fonts/truetype/ -D | ||
find -iname '*.ttf' -print0 | xargs -0 -r install -v -m644 --target $out/share/fonts/truetype/ -D | ||
find -iname '*.otf' -print0 | xargs -0 -r install -v -m644 --target $out/share/fonts/opentype/ -D | ||
find -iname '*.bdf' -print0 | xargs -0 -r install -v -m644 --target $out/share/fonts/misc/ -D | ||
find -iname '*.otb' -print0 | xargs -0 -r install -v -m644 --target $out/share/fonts/misc/ -D | ||
find -iname '*.psf' -print0 | xargs -0 -r install -v -m644 --target $out/share/consolefonts/ -D |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you replace this with a function to make the install command?
It likely will have to be in bash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean to have a function installFont "*.ttc" $out/share/fonts/truetype
instead of the lines here in the end? Or just one overall?
I left things simple and in one place to keep everything as approachable as possible, at least for development and an initial round of feedback. We can definitely extract some stuff, but we should also keep in mind that more magic also means less self-documenting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean to have a function installFont "*.ttc" $out/share/fonts/truetype
Yeah, that sounds right to me, but just in the installPhase.
Personally, I'm seeing the same command copy pasted 6 times with only two things changed.
hasMultipleSources = lib.hasAttr "srcs" args; | ||
in | ||
stdenvNoCC.mkDerivation ({ | ||
dontPatch = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn’t it make sense to instead provide defaults that can be overridden here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything can be overridden via the // args
below, and I do that in a couple of derivations (e.g. dontBuild = false;
and provide a build phase on some). Did you have another mechanism for that in mind?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're correct, thanks for the clarification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but this is inconsistent with other builders so people might be confusing when e.g. patches do not work. It fits more in with trivial builders. Perhaps it should be named installFontFiles
and be part of trivial builders.
There is a problem in that |
That's exactly the type of input I've been looking for, thanks! Coincidentally, there was a comment on that thread yesterday saying it was fixed. Let's stay tuned on whether that's actually true. Provided the bug is fixed, do you still think multiple outputs would be useful? I can think of a couple arguments for and against (short on time right now, gonna pick this up later). |
Yes, they could still be useful. For example, there is |
Is this meant just for installing already built font files – I mean it does not make sense for fonts that have |
It's not. It is essentially a specialized version of
Right. At the moment, there are lots of derivations that package their woffs, eots, svgs, depending on which other derivation they were cargo-culted from. There are also txts or pdfs with various content, I even saw an xlsx in there. The point here is to allow us to make decisions about font packaging ("where do ttfs go?", "what chmod should font files have?", "how is fontconfig called?", "should woffs go in a separate output?") as a policy, that can be encoded in I don't particularly care what those policies are, but the more consistent we can be, the more stable assumptions can be made by packagers as well as users :) See also the related discourse thread. |
''; | ||
*/ | ||
|
||
installPhase = '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This version of installPhase
doesn't install .eot
fonts (Your diff/gist shows at least one package where the .eot
files are no longer there. The commented out installPhase
above does include .eot
, so I assume this is an accidental omission).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not, actually :) eot
files are supported in Internet Explorer 6 to 11, but no other browser whatsoever. IE9 (released 9 years ago) and upwards support OTF, TTF, and WOFF, so the only reason to ever ship eot files is compatibility with IE6 to IE8. I suspect that the packages that include eot
files don't do so out of careful consideration.
I propose we omit eot
files from nix packaging.
(Of course, decisions such as this should be annotated in mkFont
to make it easy to discover for packagers who look up how things work, and also in the manual. The "needs documentation" tag definitely applies to PR, I'll try to get around to it so we have a better basis for discussion soon ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like .woff
and .woff2
fonts aren't handled either.
Incidentally I had something very similar in my local repo (because I love using legible fonts)- would you mind adding a parameter, say-
This is because fontconfig is really bad in determining which fonts from within a family take prececdence (by default). For example, I use the following for Delicious font; if you don't use the
Btw, this must have been such a herculean undertaking- our collective eyes will thank you when we can use more legible fonts :). |
What would this mean for people who actually want to use Delicious SmallCaps or Delicious Heavy? Would you put them in a completely separate package? I was wondering whether a font package could have multiple-outputs, e.g. However, I think only installing some of the styles available is at best a workaround. Ideally we should try to fix the actual issue. I found this, which is an interesting exploration of some of the complexities of fontconfig font matching. Maybe we can work out why fontconfig is choosing the wrong style from the delicious family and either patch the delicious files to correct the metadata (if that is the issue), or add something to |
This is not a Nix specific problem, I used to face this in Arch too. Fontconfig has a lot of problems. Specially so if you want to use non-latin fonts. There is no consistent theme underlying fontconfig configuration language is what I've concluded after I've spent a lot of hours on fontconfig, the best bet is to just get do what is needed and spend time doing work. |
In this case, I think you could argue that it is an "upstream" problem/bug. Based on the appearance of the individual styles in the family, it looks like Delicious-Roman.otf should be the "normal"/regular/default variant, but the style data in the font files is as follows:
It doesn't seem unreasonable that fontconfig favours the heavy and smallcaps styles, as they claim to be "Regular" fonts, which are in the "Delicious" family. Delicious-Roman, on the other hand, claims to be a "Roman" style, which nobody asked for. I believe there are a few possible workarounds/fixes:
As you can probably tell, I'm leaning towards the last option, though I haven't tried to implement it yet, and I don't know how common fonts with messed-up metadata are yet. |
I agree with your argument |
Hello, how I can help you progress this PR? |
"little" sad that somebody changed 189 files and rather than helping push this PR, people comments irrelevant comments about code style. Now this PR is dead. Good job everyone. (some of the usual suspects obviously) |
I marked this as stale due to inactivity. → More info |
Hi! I think this PR is very interesting, do you think you could refresh it so we can give it a review? |
Motivation for this change
Font package derivations in nixpkgs aren't particularly organized: They fall into just a handful of patterns, but in a cargo culted rather than organized fashion. Several decisions that should be subject to policy are pretty much taken at random, e.g. whether license files should be packaged, whether woff/woff2/eot/svg files should be packaged, what path to use for each particular font type, etc.
Things done
This PR introduces a
mkFont
derivation, which specifies a generic installPhase that fits for the majority of font packages. @puzzlewolf and I migrated some ~190 font packages over to it, and most of them are now trivial derivations that contain onlypname+version+src+meta
. We also did a general cleanup for consistency. Between all those files we dropped some 1k lines of code :)Obviously we picked the low hanging fruit here, and the remaining font derivations are slightly more complicated to rewrite for
mkFont
.Open questions
This PR is a draft currently, and there are still some open questions. In particular I'd appreciate some thoughts on the following points:
mkFont
can consistently apply those kinds of policies for whatever font packages it's used for :)installPhase
could be made more complicated to offer more features, such asincludeOnly
orrenameFiles
directives. I decided to keep it simple for now, derivations can always override whatever they want (or just usemkDerivation
, of course).Anyways, overall I think this is a significant improvement wrt font packaging consistency 🎉