Skip to content

Multiple, configurable data dirs and package repositories #1982

Open

Description

@jorsn

Description

Currently, as I understand, there is one data dir, one cache dir, and one hardcoded package repository.
I propose to

  1. make the package repository configurable1 and possibly allow multiple alternative ones
  2. allow multiple data dirs, in a configurable1 way

Use Case

  1. 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).
  2. 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

  1. e.g. options at compile time, on commandline, in env variables or in a config file ↩ ↩2

Activity

  1. added
    feature request
    on Aug 23, 2023
  2. added
    cli
    packages
    on Sep 4, 2023
  3. sbatial commented on Oct 1, 2023

    @sbatial
    Contributor

    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.

  4. PPakalns commented on Oct 6, 2023

    @PPakalns

    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:

    #import "@preview/{name}:{version}".

    Fetches package from:
    https://github.com/typst/typst/blob/df4beb6e15b40d22807e25e41546da698038fed9/crates/typst-cli/src/package.rs#L49C10-L49C45

        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.

  5. laurmaedje commented on Oct 6, 2023

    @laurmaedje
    Member

    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:

    [dependencies]
    "@preview/blah" = "0.3.0"
    "@foo/bar" = { git = "..", tag = ".." }
    "@baz/brr" = { path = ".." }
    

    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.

  6. PPakalns commented on Oct 6, 2023

    @PPakalns

    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))

  7. Andrew15-5 commented on Dec 3, 2023

    @Andrew15-5
    Contributor

    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).

    If I simply do

    #import "./package/version/entrypoint.typ" as package-name

    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

    export TYPST_PACKAGES_PATH=".:./over/here:$TYPST_PACKAGES_PATH"

    Meaning that relative paths should be accepted (for ease of use).

    This is all just thoughts and nothing concrete, but the problem is real.

  8. kdkasad commented on Mar 19, 2024

    @kdkasad

    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.

  9. laurmaedje commented on Mar 19, 2024

    @laurmaedje
    Member

    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.

  10. kdkasad commented on Mar 19, 2024

    @kdkasad

    Ah okay; that makes sense.

  11. Gabgobie commented on May 5, 2025

    @Gabgobie

    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

    /// The default Typst registry.
    pub const DEFAULT_REGISTRY: &str = "https://packages.typst.org";
    /// The public namespace in the default Typst registry.
    pub const DEFAULT_NAMESPACE: &str = "preview";
    /// The default packages sub directory within the package and package cache paths.
    pub const DEFAULT_PACKAGES_SUBDIR: &str = "typst/packages";

    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.
    pub const DEFAULT_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.

    1. 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.
    2. 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.

    Best,
    Gab

  12. Vanille-N commented on Jun 11, 2025

    @Vanille-N

    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.

  13. laurmaedje commented on Jun 11, 2025

    @laurmaedje
    Member

    @Vanille-N PRs to improve diagnostics in this area would be appreciated!

  14. podsvirov commented on Dec 18, 2025

    @podsvirov

    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.

  15. hsynkrtl commented on Nov 9, 2026

    @hsynkrtl

    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

    • 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).

    For example:

    project/
    ├── package/
    │   ├── local/
    │   │   └── my-library/
    │   │       └── 0.1.0/
    │   └── internal/
    │       └── another-library/
    │           └── 0.1.0/
    ├── scripts/
    │   ├── main.typ
    │   └── helper.typ
    └── typst.toml
    

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    clifeature requestpackages

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions