-
-
Notifications
You must be signed in to change notification settings - Fork 15k
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
typst: add initial support for typst packages #369283
base: master
Are you sure you want to change the base?
Conversation
b5ab425
to
0bcf7c9
Compare
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.
Welcome to Nixpkgs! This is truly amazing; I've wanted to build Typst packages for a very long time but never got around to it.
Note that the commits should be split as much as possible. Each new typstPackage
should be added in a separate commit. The changes to the base typst
package to wrap it should also be a separate commit.
407f204
to
b14cd40
Compare
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.
Regarding the actual package set, even though we can't import from Universe directly, it might still be a good idea to scrape it for information and build packages automatically. typst.toml
gives us all of the necessary information to build each package.
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.
Hello,
Thanks for tackling this, I have a few comments, let me know if you have questions.
@jtojnar : I know you're busy these days, but if you could have a look at this, it would be great.
Thanks!
Ah that is great. Didn't know they already have that information included. I'll work on the script when I got time, but it will have to be waited for another week or so. |
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 good to me, just one final open question for anyone who knows about packagesFromDirectoryRecursive
.
e753a45
to
7560346
Compare
Would it be a good idea to have some documentation for this ? |
I can write it, but where should I put it?
Not sure if this change should be considered as significant |
Thanks for the suggestions! Have patched them accordingly |
Now, we have an example of a license not found by its SPDX ID: packages licensed under |
Right the actual case is a bit more complicated. Apparently SPDX could be expressions, which means that it has its own little grammar to construct a logic license through a set of SPDX IDs (specifically, named licenses). Typst packages allow expression strings while it is not possible to perfectly translate the logic expression to Nix, as licenses in Nixpkgs are a list of named licenses (not clear how to diff AND/OR/WITH relations). "+" is also a valid token to represent a single named license id, while the helper functions in nixpkgs do not support parse any of them. The solution for now is simply adhoc --- unparsable SPDX IDs will be replaced to one or more parsable IDs (based on its semantics). This is hardcoded in the maintaining script. The logical relations are simply ignored due to the aforementioned reason in nixpkgs. |
I see the WITH relation is encoded as an independent license in nixpkgs, but the same argument still apply for AND/OR and "+" |
I'll be available to review the script this Tuesday or Wednesday. Feel free to proceed with merging if other people approve all the changes. |
Please let me know if the maintaining script looks fine. I will need to regenerate the toml file before merge. |
Sorry for the delay. I just went through the Python script, and it looks alright. Some questions:
|
BTW, to address the pre-fetching overhead, maybe we could file a feature request to the Typst upstream asking for a checksum-fetching API. I filed an issue in the OpenVSX project and ask if they can add such functionality to their RESTful API (eclipse/openvsx#311) and got positive response. |
Yes. I am running it on a AMD Ryzen 7 7840U machine with 16 hardware threads + 32 GB DDR5 SDRAM, which takes approx. 3 mins. This includes the downloading time of Typst universe git repo (for traversing dependencies).
Peak memory is 1.3 GB. |
This PR adds initial support to build Typst documents with Typst packages. In particular, it adds a Typst package builder and exposes it at the top level to ease the process of defining new Typst packages. It further adds a new function to the Typst derivation for creating a new Typst environment in which the Typst compiler understands a specific set of packages, namely
typst.withPackages
. Moreover, three Typst packages are defined and collected as a single attribution set as an initial demonstration.Only a few Typst packages are included in this PR for a reason. The Typst Universe (the official site for Typst packages) maintains a single git repo that contains all Typst packages. Each package entry does not necessarily map to the same version specified in their respective git repo published by their authors (if there is). This is because the package authors need to manually move their package and copy the source, instead of a pointer, to the Typst Universe repo. Breaking the Typst Universe repo down to per package requires separate places to store each of them, and due to the aforementioned reason, the exact source may disagree with the original git repo 1. This is why, in my opinion, we might want to collect our own set of Typst packages instead of directly pulling from the Typst Universe repo. For gradual adaption,typst.withPackages
also provides a method to override the predefined set of Typst packages, namelytypst.withPackages.override
, making it easier for end users overriding the existing set of Typst packages and integrating new packages into their project.All packages from the Typst Universe are included in this PR, along with a maintenance script. The script simply generates a set of nix expressions for all packages from the Typst Universe. Each individual package is now fetched as a tarball from the Typst Universe instead of their individual repository.
Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Add a 👍 reaction to pull requests you find important.
Footnotes
Assuming the author(s) also publish their package in another repo outside of the Typst Universe repo. ↩