You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Multiple, configurable data dirs and package repositories #1982
Alternative package repos could be helpful, e.g., for private repos or reliability in case of github problems (e.g. it has happened that I was blocked for some time, probably because too many people connected to github in short time from the same university network).
Alternative data Dirs are currently possible by setting XDG_DATA_DIR. However, I might want to have multiple data dirs. For example, there might be multiple package roots within one modular project repository. In TeX, I can set TEXINPUTS or even set the search paths from within TeX code. Another example would be, having packages pinned by another package manger like Nix, e.g. if my project has also non-typst dependencies, I want particular git commits or the package versions I want depend on the typst version that I install via nix. Additionally, I have a project-local package directory for the packages I locally develop in this project. Then, I already need two data dirs. This is currently doable for only two directories, by abusing the cache dir.
Footnotes
e.g. options at compile time, on commandline, in env variables or in a config file ↩↩2
Reacted by sbatial, Pēteris Pakalns , Léana, Léo Colombaro, Ross Smyth, red thing, Matthew RONCHETTO, Gabgobie, Rasmus Kirk, Willi Eggeling and 4 more
A flake which patches flake to have an override for the package source.
I plan to hopefully contribute it as well if desired but I didn't know what the best (official) way would be to do such an override (env var, config file, cli flag, etc.) so I just created this flake for now.
For our use case we have private typst templates that i need to distribute to multiple persons that are working on these documents and creating new ones. It is hard to always remind them to locally put template directories at the root of the project or how to put them in local cache directory. As these files are used for our specific use case, we want to rapidly create new versions, we do not want to put them in public repository.
It would be very nice if typst would support defining new package namespaces that fetches packages from specified address.
let url = format!("https://packages.typst.org/preview/{}-{}.tar.gz",
spec.name, spec.version
);
It would be nice if i could do this:
#package_repository("my_private_repositry","https://myproject.org/typst_packages/")// Or even add authentication data
#package_repository("my_private_repositry","https://user:[email protected]/typst_packages/")
And then i would be able to do this:
#import "@my_private_repository/{name}:{version}"
Which would download files from
"{repository_url}/{name}-{version}.tar.gz"
And it looks like to host package repository, i need to make similar repository as typst/packages, run bundler and just host static files on a server.
That sounds doable, in principle, my main concern is with the namespaces. We intentionally put everything in preview right now in order to make a decision how to do namespacing later. I know that you can already create whatever local namespace you want, but adding more first-class support for fetching from arbitrary namespaces reduces our flexibility to, for instance, assign namespaces to users later.
Moreover, repository configuration should not be in the Typst file in my opinion. I would not want to give a Typst file without further external configuration (be it env vars, TOML files, whatever) the power to fetch arbitrary URLs. There was recently discussion about supporting typst.toml for projects (to specify dependency versions just once or add git/path dependencies). Something like:
This still wouldn't fully cover your use case for a completely custom registry, but we should have a coherent vision for the whole thing. The TOML is also just one approach of course. We could also go for the Deno route where there's a dependency file that is also a Typst file that re-exports things.
Reacted by Pēteris Pakalns , sbatial, JCGoran, rbq and Gabgobie
I think it would be a good start if at least some packages could be imported from some private source, like git repository.
In this situation at least in our use case custom repository is not needed. It would simplify distribution of new package version to all users.
It would be nice if specific package version is not required in toml file so that it can be specified in each document seperately. (I do not need to update all documents in project if versions are incompatible, i do not need to instruct writers of the document to edit toml file, they can fully work in specific document that they are interested in, i would only need to say that new version is available. (We have multiple documents in the same project root directory))
I want to know if my use case is a different feature request or the same.
I want to download to my specific local Typst project root dir at /path/to/my/project/ a Typst package. I can obtain it from a git repository, but it's not yet a published package/version.
So I move a dir with package to this root dir and then import it like:
#import"./package"// or#import"./package/version"
But this is currently impossible, and the error tells me "failed to load file" (because I've pointed to the root dir of a package).
then it can complain about absolute paths in the package files. Like #import "/src/file.typ" in a file /src/another.typ (instead of #import "file.typ").
Now I have 2 main options:
manually convert absolute paths to relative ones
make typst treat the "dir-local" package as any other @local/@preview package, instead of as a simple directory with Typst files.
I thought that maybe typst just need to check if inside ./package/version there is a typst.toml file and then treat this path as a normal Typst package. Or make some sort of TYPST_PACKAGES_PATH that you can tweak if needed and the default value either empty or $HOME/.local/share/typst/packages/local (or using the $XDG_DATA_HOME if set). If I have several places where I had dir-local packages then I can do
Moreover, repository configuration should not be in the Typst file in my opinion. I would not want to give a Typst file without further external configuration (be it env vars, TOML files, whatever) the power to fetch arbitrary URLs.
What is the reason for this? It doesn't sound inherently less safe than having arbitrary URLs in a typst.toml file in the same project.
The difference is that typst.toml can only contain static strings while dynamic imports within Typst code could embed files from your computer into URLs, e.g. via query parameters. And even if the strings would be required to be static, one could perform timing attacks based on file contents.
Private registries have been a requested feature for quite some time now and I was looking for a (temporary) solution that might satisfy everyone, at least to a certain degree.
If we were to change the first definition as follows, installs using cargo install --locked typst-cli would be customizable while your binary distributions are unaffected.
/// The Typst registry to use.pubconstDEFAULT_REGISTRY:&str = env!("TYPST_REGISTRY_URL","TYPST_REGISTRY_URL undefined, use \"https://packages.typst.org\" if unsure.");
While I didn't see anything noteworthy about DEFAULT_PACKAGES_SUBDIR, DEFAULT_NAMESPACE may pose an issue as it is used to prevent Typst from trying to download any package that isn't in that namespace.
So far, I thought of two approaches to cover this issue.
Only run this check if DEFAULT_REGISTRY == "https://packages.typst.org" and otherwise try to download for any namespace if no cached package was found, making it up to the local registry to allow or refuse namespaces.
Use a similar approach to the registry by providing ALLOWED_ONLINE_NAMESPACES as a compile-time env var. The main issue with this is that you would have a csv &str instead of an array, at least I wouldn't know how you could deserialize this at compile-time.
The main requirement around this system would be that anyone making use of this setting is both compiling Typst from source and hosting their own registry, reducing the number of support tickets as these are usually technical people.
I didn't look too deep into the registry but the bundler is already open-source and could probably be part of a git deploy workflow.
As for private registries, to my understanding they don't need to be too much more than a webserver/cache that the bundler can deploy to, that reply with an error for packages that were not found and maybe forward requests for packages in the @preview namespace to the official Typst registry, caching the result. This should reduce the traffic hitting your servers as a nice side-effect, although I can't say for certain if that is by any meaningful amount. Since the official registry already exists, I suppose the only feature missing for local deployments would be allowing/disallowing namespaces and forwarding + caching.
The main benefits of this approach are that
it is a drop-in solution that requires little work, assuming a minimal implementation
no policy changes are necessary around namespacing. The docs suggest using a @local namespace for system-local packages. Acknowledging @private for private registries would be sufficient to avoid namespacing confusion.
With everything continuing to be decided at compile-time, the security concerns about typst files fetching arbitrary URLs are covered.
A small side note: in the process of implementing this (or even as a prerequisite), I think the error message for "package not found" should be detailed further in several cases.
Currently
@preview package exists but version does not
@local package exists with the right version but its typst.toml is missing
have good error messages, respectively
package found, but version x.y.z does not exist (latest is x.y.a)
file not found (searched at /home/{user}/.local/share/typst/packages/{namespace}/{package}/{version}/typst.toml)
(second could be improved my mentioning why we need typst.toml, but it gets the message across if you know what you're doing)
As for
@local package exists with the right version but its typst.toml is malformed
it has at least a passable error message
package manifest is malformed (missing field {field})
(could be improved by mentioning the file)
However...
@preview package does not exist,
@local namespace does not exist,
@local package does not exist,
@local package exists but not with the right version.
all have the same exact error message:
"error: package not found (searched for @{namespace}/{package}:{version})".
No mention of which directories were searched, and in the case that this issue on Ubuntu is hit, no indication that the reason the package was not found is that Typst was denied access to its folder.
I think it would be not very difficult, helpful right now, and vital if a more complex package management ever sees the light that the compiler is clear about what directories it searched and what went wrong.
Hello everyone. I hadn't seen this discussion before, and I also tried to suggest a simple solution for configuring package registry mirrors from the TYPST_REGISTRY_URL environment variable in #7596, but it was rejected.
I want to organize scripts within a project in the same way as a package. All scripts should share a common root directory and be able to import functionality from each other using consistent package-style import paths.
To achieve this, I create a package directory within my project and configure it using --package-path.
This works well for organizing project-specific functionality. However, it currently means that I lose access to other local packages.
Benefits
Support for modular project structures.
Easier development and testing of unpublished packages.
Multiple independent local package repositories.
Backward compatibility with the existing package resolution mechanism.
Possible implementations
I see two possible approaches to achieve this:
Option A: Introduce an additional CLI parameter
Introduce a new parameter such as --package-search-path that allows users to specify additional package directories. Multiple directories should be supported and searched in the order specified.
Option B: Extend the existing package resolution
Alternatively, Typst could automatically check for a package directory within the project root (as defined by --root).
Activity
sbatial commentedon Oct 1, 2023
I did a little thing: https://gitlab.com/sbatial/typst-flake-env
A flake which patches flake to have an override for the package source.
I plan to hopefully contribute it as well if desired but I didn't know what the best (official) way would be to do such an override (env var, config file, cli flag, etc.) so I just created this flake for now.
PPakalns commentedon Oct 6, 2023
For our use case we have private typst templates that i need to distribute to multiple persons that are working on these documents and creating new ones. It is hard to always remind them to locally put template directories at the root of the project or how to put them in local cache directory. As these files are used for our specific use case, we want to rapidly create new versions, we do not want to put them in public repository.
It would be very nice if typst would support defining new package namespaces that fetches packages from specified address.
For example:
Fetches package from:
https://github.com/typst/typst/blob/df4beb6e15b40d22807e25e41546da698038fed9/crates/typst-cli/src/package.rs#L49C10-L49C45
It would be nice if i could do this:
And then i would be able to do this:
#import "@my_private_repository/{name}:{version}"Which would download files from
And it looks like to host package repository, i need to make similar repository as
typst/packages, run bundler and just host static files on a server.laurmaedje commentedon Oct 6, 2023
That sounds doable, in principle, my main concern is with the namespaces. We intentionally put everything in
previewright now in order to make a decision how to do namespacing later. I know that you can already create whatever local namespace you want, but adding more first-class support for fetching from arbitrary namespaces reduces our flexibility to, for instance, assign namespaces to users later.Moreover, repository configuration should not be in the Typst file in my opinion. I would not want to give a Typst file without further external configuration (be it env vars, TOML files, whatever) the power to fetch arbitrary URLs. There was recently discussion about supporting
typst.tomlfor projects (to specify dependency versions just once or add git/path dependencies). Something like:This still wouldn't fully cover your use case for a completely custom registry, but we should have a coherent vision for the whole thing. The TOML is also just one approach of course. We could also go for the Deno route where there's a dependency file that is also a Typst file that re-exports things.
PPakalns commentedon Oct 6, 2023
I think it would be a good start if at least some packages could be imported from some private source, like git repository.
In this situation at least in our use case custom repository is not needed. It would simplify distribution of new package version to all users.
It would be nice if specific package version is not required in toml file so that it can be specified in each document seperately. (I do not need to update all documents in project if versions are incompatible, i do not need to instruct writers of the document to edit toml file, they can fully work in specific document that they are interested in, i would only need to say that new version is available. (We have multiple documents in the same project root directory))
Andrew15-5 commentedon Dec 3, 2023
I want to know if my use case is a different feature request or the same.
I want to download to my specific local Typst project root dir at
/path/to/my/project/a Typst package. I can obtain it from a git repository, but it's not yet a published package/version.So I move a dir with package to this root dir and then import it like:
But this is currently impossible, and the error tells me "failed to load file" (because I've pointed to the root dir of a package).
If I simply do
then it can complain about absolute paths in the package files. Like
#import "/src/file.typ"in a file/src/another.typ(instead of#import "file.typ").Now I have 2 main options:
typsttreat the "dir-local" package as any other@local/@previewpackage, instead of as a simple directory with Typst files.I thought that maybe typst just need to check if inside
./package/versionthere is atypst.tomlfile and then treat this path as a normal Typst package. Or make some sort ofTYPST_PACKAGES_PATHthat you can tweak if needed and the default value either empty or$HOME/.local/share/typst/packages/local(or using the$XDG_DATA_HOMEif set). If I have several places where I had dir-local packages then I can doMeaning that relative paths should be accepted (for ease of use).
This is all just thoughts and nothing concrete, but the problem is real.
kdkasad commentedon Mar 19, 2024
What is the reason for this? It doesn't sound inherently less safe than having arbitrary URLs in a
typst.tomlfile in the same project.laurmaedje commentedon Mar 19, 2024
The difference is that typst.toml can only contain static strings while dynamic imports within Typst code could embed files from your computer into URLs, e.g. via query parameters. And even if the strings would be required to be static, one could perform timing attacks based on file contents.
kdkasad commentedon Mar 19, 2024
Ah okay; that makes sense.
Gabgobie commentedon May 5, 2025
Private registries have been a requested feature for quite some time now and I was looking for a (temporary) solution that might satisfy everyone, at least to a certain degree.
Currently, the package source is hardcoded in
typst/crates/typst-kit/src/package.rs
Lines 15 to 22 in 14241ec
If we were to change the first definition as follows, installs using
cargo install --locked typst-cliwould be customizable while your binary distributions are unaffected.While I didn't see anything noteworthy about
DEFAULT_PACKAGES_SUBDIR,DEFAULT_NAMESPACEmay pose an issue as it is used to prevent Typst from trying to download any package that isn't in that namespace.So far, I thought of two approaches to cover this issue.
DEFAULT_REGISTRY == "https://packages.typst.org"and otherwise try to download for any namespace if no cached package was found, making it up to the local registry to allow or refuse namespaces.ALLOWED_ONLINE_NAMESPACESas a compile-time env var. The main issue with this is that you would have a csv &str instead of an array, at least I wouldn't know how you could deserialize this at compile-time.The main requirement around this system would be that anyone making use of this setting is both compiling Typst from source and hosting their own registry, reducing the number of support tickets as these are usually technical people.
I didn't look too deep into the registry but the bundler is already open-source and could probably be part of a git deploy workflow.
As for private registries, to my understanding they don't need to be too much more than a webserver/cache that the bundler can deploy to, that reply with an error for packages that were not found and maybe forward requests for packages in the
@previewnamespace to the official Typst registry, caching the result. This should reduce the traffic hitting your servers as a nice side-effect, although I can't say for certain if that is by any meaningful amount. Since the official registry already exists, I suppose the only feature missing for local deployments would be allowing/disallowing namespaces and forwarding + caching.The main benefits of this approach are that
@localnamespace for system-local packages. Acknowledging@privatefor private registries would be sufficient to avoid namespacing confusion.Best,
Gab
Vanille-N commentedon Jun 11, 2025
A small side note: in the process of implementing this (or even as a prerequisite), I think the error message for "package not found" should be detailed further in several cases.
Currently
@previewpackage exists but version does not@localpackage exists with the right version but itstypst.tomlis missinghave good error messages, respectively
(second could be improved my mentioning why we need
typst.toml, but it gets the message across if you know what you're doing)As for
@localpackage exists with the right version but itstypst.tomlis malformedit has at least a passable error message
(could be improved by mentioning the file)
However...
@previewpackage does not exist,@localnamespace does not exist,@localpackage does not exist,@localpackage exists but not with the right version.all have the same exact error message:
No mention of which directories were searched, and in the case that this issue on Ubuntu is hit, no indication that the reason the package was not found is that Typst was denied access to its folder.
I think it would be not very difficult, helpful right now, and vital if a more complex package management ever sees the light that the compiler is clear about what directories it searched and what went wrong.
laurmaedje commentedon Jun 11, 2025
@Vanille-N PRs to improve diagnostics in this area would be appreciated!
podsvirov commentedon Dec 18, 2025
Hello everyone. I hadn't seen this discussion before, and I also tried to suggest a simple solution for configuring package registry mirrors from the
TYPST_REGISTRY_URLenvironment variable in #7596, but it was rejected.hsynkrtl commentedon Nov 9, 2026
My use case
I want to organize scripts within a project in the same way as a package. All scripts should share a common root directory and be able to import functionality from each other using consistent package-style import paths.
To achieve this, I create a package directory within my project and configure it using
--package-path.This works well for organizing project-specific functionality. However, it currently means that I lose access to other local packages.
Benefits
Possible implementations
I see two possible approaches to achieve this:
Option A: Introduce an additional CLI parameter
Introduce a new parameter such as
--package-search-paththat allows users to specify additional package directories. Multiple directories should be supported and searched in the order specified.Option B: Extend the existing package resolution
Alternatively, Typst could automatically check for a
packagedirectory within the project root (as defined by--root).For example:
This directory would act as an additional local package source.
I would prefer Option B because it provides a simple, project-local convention without requiring additional CLI configuration.