# Fetching a Package

_Peios / Developing for Peios / Packaging Software_

> Copy a package from another artifact directory or from a repository served over HTTP with ppk fetch, what it checks on the way, and what happens when the package is already present.

Fetching resolves a package and everything it needs from another artifact
directory, or from a repository served over HTTP, then copies the chosen
packages into yours and checks them on the way. Do this to use a package that
was packed somewhere else, such as on a build machine whose artifact directory
you can read, or one a repository publishes.

## Before you start

- Install `ppk`.
- Have read access to the source: an artifact directory, as a local path, or
  a repository's URL.
- Have write access to your artifact directory. The default is
  `/system/artifacts`; to use a directory of your own, pass
  `--artifact-dir`.
- Know the package's name, such as `org.figlet.figlet`.

## Fetch the package

Run `ppk fetch` with the name and the source:

```sh
ppk fetch org.figlet.figlet --from shared --artifact-dir artifacts
```

`ppk` chooses the newest version that satisfies the request, follows its
dependencies and requirements, and fetches every chosen package. It prints
one identity per package fetched, in package-name order:

```text
sha256:73a137f612f39b8ee1ffcbb7f51b7b9dc370b8662323d72b9e6b73b9d54413f8
```

To constrain the version, quote the name and constraint, for example
`'org.figlet.figlet >= 2.2'`. A full ID such as
`'org.figlet.figlet@2.2.5-1?arch=x86_64'` pins that exact package, including
the version's spelling. Its dependencies are still resolved. Unqualified
requests choose for ppk's own architecture; `--arch` selects another. All
packages in one resolution must be for the same architecture. A full ID
with an explicit architecture can select that architecture on its own.

Resolution is greedy, as `ppk resolve` is. Missing dependencies, missing
capability providers and conflicting constraints fail with an error naming
what is needed, before copying starts.

To copy exactly one package without resolving anything it needs, pass
`--no-deps` and a full ID. This mode accepts IDs, with an optional
`?arch=…`, rather than bare names or constraints:

```sh
ppk fetch --no-deps 'dev.peios.hello@1.0-1?arch=noarch' --from shared --artifact-dir artifacts
```

`--from` also takes the URL of a repository served over HTTP, such as
`https://pkgs.peios.org/`. `--from` takes no identity, so `ppk` checks every
file against its hash but can't check who signed the repository. To check
that too, add the repository with its identity, using `ppk repo add`.

## Check the result

Compare the identity with the one `ppk pack` printed where the package was
made. Because the identity is the hash of the manifest, and the manifest
names every file by its hash, the same identity means the same package,
byte for byte.

## Fetch from configured repositories

A machine keeps a list of the repositories it fetches from, each a file in
`/conf/ppk/repositories/`. Add one with `ppk repo add`, giving the identity
its pointer file must be signed under, and the channel it follows:

```sh
ppk repo add peios /mnt/peios-repo --identity pkgs.peios.org --track stable
```

`ppk` accepts the signature only if a root it was built with vouches for
the chain that made it. A repository whose publisher has no such chain signs
under a top-level certificate of its own, which you enable on the machine
first. Add that repository with `--unrooted`, and optionally with
`--anchor` and the top-level's hash, to accept that top-level and no
other:

```sh
ppk repo add tools https://pkgs.example.com/ --identity pkgs.example.com --unrooted
```

That writes `/lcl/conf/ppk/repositories/peios.toml`, which `/conf/ppk` merges
with whatever the system ships. Then fetch without `--from`:

```sh
ppk fetch se.curl.curl
```

A repository served over HTTP is added by its URL instead of a path. Give
more than one URL to try them in order, such as a cache on your network
first and the repository's own server after it:

```sh
ppk repo add peios http://cache.lan/peios/ https://pkgs.peios.org/ \
    --identity pkgs.peios.org --track stable
```

If a URL can't be reached or doesn't have a file, `ppk` tries the next one.
`ppk` keeps the tree nodes and manifests it reads from a repository served
over HTTP in `/var/cache/ppk`, so it reads each of them only once. Pass
`--cache-dir` to keep them somewhere else.

A request for a bare name, or a name with a constraint, follows the channel
its repository tracks, so this fetches the version `stable` holds, and what
it needs from `stable` too. Naming an index, as in `se.curl.curl#leading`, or
an exact version, takes that instead.

Each package name belongs to one repository. If two of them publish one, for
something you asked for or something it needs, `ppk` refuses rather than
choose. A repository's pointer file goes up in sequence each time it's
published, and `ppk` keeps the highest it has seen of each in
`/var/state/ppk`, refusing a repository that offers an older one. A mirror
might still be behind; `ppk repo list` shows when each was signed:

```text
peios /mnt/peios-repo #stable (sequence 42, signed 2026-11-13T13:11:46Z, signature checked)
```

## What fetch checks

`ppk fetch` trusts nothing it reads from the source:

- **The manifest** must hash to the identity in the source's ref.
- **Its form** must be exactly what `ppk pack` writes, naming the package
  you asked for, with every path relative and inside the package's root.
- **Each file's content** must hash to the name the manifest gives it.

If a check fails, `ppk fetch` stops with an error and doesn't record the
package. Only the files missing from your artifact directory are copied, so
fetching a new version transfers only what changed.

These checks prove that the package is the one the source's ref names. They
don't prove who published it, so fetch only from sources you trust. A
configured repository with an identity proves that too: a package must be in
the catalog its signed pointer file leads to, at the identity the catalog
gives, so a package it didn't publish, or a ref changed since, is refused.

A repository served over HTTP has no refs that `ppk` can list, so its
catalog says which packages it has. To choose packages, `ppk` reads only the
catalog's entries for the names it needs and each version's summary: the
start of its manifest, which says what the package needs and provides but
not what files it holds. A catalog also lists what provides each
capability, so finding a library by its soname reads no more than that.
`ppk` reads a manifest only when it fetches the package, and refuses one
that doesn't begin with the summary it chose the package by.

`ppk` checks every file it reads from
the repository against its hash before using it, and checks the pointer
file's signature. A file that fails its check is an error: `ppk` doesn't try
the next URL, because a server that sends the wrong file is broken or
hostile. A file that fails its check is never stored.

A repository can keep its blobs compressed, as an export does, and its
pointer file says so. `ppk` decompresses each blob as it fetches it and
checks what it decompresses to, so your artifact directory always holds the
files uncompressed.

## When the package is already present

By default, a chosen package already present with the same identity is
skipped without writes or output. Its dependencies are still resolved and
fetched if missing. With `--no-deps`, fetching it checks the package, copies
any missing files, and prints its identity as before. If your artifact
directory has a different package under the same name, version, and
architecture, `ppk fetch` refuses to replace it:

```text
ppk: dev.peios.hello@1.0-1?arch=noarch: already present as sha256:73a137f612f39b8ee1ffcbb7f51b7b9dc370b8662323d72b9e6b73b9d54413f8, but other has sha256:453a10dad4cb1902912919527452fa61c6420ae9152c1f02b57c1421a6d9d57b
```

A packed version never changes, so two different packages under one version
mean the two artifact directories disagree. Find out which one is right
before you use the package.

## Replace a package in a bootstrap's directory

A bootstrap builds its first packages with another system's tools, then
rebuilds them with its own at the same versions. Its artifact directory isn't
published until every package has been rebuilt, so nothing relies on the
first builds yet. To replace one, pass `--replace --no-deps` with its ID:

```sh
ppk fetch 'dev.peios.hello@1.0-1?arch=noarch' --from rebuilt --artifact-dir bootstrap --replace --no-deps
```

The ref then names the fetched package. The replaced manifest and its files
stay in the directory. Replacement requires `--no-deps` so that it affects
only the named package. Every check above still applies. Don't use
`--replace` on an artifact directory anything has fetched from: that breaks
the rule that a version never changes.

Related content:

- [Packages](/peios/developing-for-peios/packaging/packages.md)
- [Creating a Package](/peios/developing-for-peios/packaging/creating-a-package.md)
