pkgresolve

module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2026 License: Apache-2.0

README

pkgresolve

Pure-Go dependency resolvers for Debian and RPM repositories. Given repository metadata and a list of seed packages, each resolver returns the exact set of packages an install would pull in. Neither needs apt, dpkg, dnf, rpm or libsolv, so it runs on any platform Go supports, for example to build container root filesystems or lock files.

Package Input Matches
deb Packages indexes, parsed with pault.ag/go/debian/control apt-get install
rpm repodata primary.xml dnf install

Usage

Debian
f, _ := os.Open("/usr/share/keyrings/debian-archive-keyring.pgp")
keyring, err := openpgp.ReadKeyRing(f)
if err != nil {
	return err
}
pkgs, err := deb.Fetch(ctx, http.DefaultClient, keyring,
	"https://snapshot.debian.org/archive/debian/20261101T000000Z", "trixie", []string{"main"}, []string{"amd64", "i386"})
if err != nil {
	return err
}
ix := deb.NewIndex(pkgs, "amd64", "i386") // native, then foreign architectures as with dpkg --add-architecture
got, err := ix.Resolve([]string{"curl", "libc6:i386"}, false) // false: skip Recommends
if err != nil {
	return err
}
for _, p := range got {
	fmt.Println(ix.Key(p), p.Version, p.Filename) // curl:amd64 8.14.1-2 pool/main/c/curl/...
}
  • Fetch verifies InRelease against the keyring and each Packages index (.xz, .gz or plain) against the SHA256 that InRelease lists. It returns the stanzas of every component and architecture.
  • NewIndex also takes stanzas parsed by the caller with control.ParseBinaryIndex.
  • The result always includes the Essential packages of the native architecture, like a fresh debootstrap.
  • Seeds are name (native) or name:arch.
  • Multi-Arch follows the Debian Multiarch spec: same, foreign and allowed, plus the :any, :native and :<arch> qualifiers. Architecture: all packages count as native.
  • With only a native architecture, the result is the single-architecture closure.
RPM
f, _ := os.Open("RPM-GPG-KEY-fedora-43-primary")
keyring, err := openpgp.ReadArmoredKeyRing(f)
if err != nil {
	return err
}
base := "https://dl.fedoraproject.org/pub/fedora/linux/releases/43/Everything/x86_64/os/"
// Fedora metalinks list repomd.xml sha256 sums; passing them after arch pins the snapshot: Fetch(..., "x86_64", sums...)
pkgs, err := rpm.Fetch(ctx, http.DefaultClient, keyring, base, "x86_64") // a nil keyring skips repomd.xml.asc
if err != nil {
	return err
}
ix := rpm.NewIndex(pkgs, rpm.Options{
	Prefer: []string{"glibc-minimal-langpack"}, // wins any choice between providers
	Weak:   false,                              // true also installs Recommends
	Choice: func(dep, picked string, n int) { log.Printf("%s: picked %s of %d providers", dep, picked, n) },
})
got, err := ix.Resolve([]string{"curl"})
if err != nil {
	return err
}
for _, p := range got {
	fmt.Println(p.Name, p.EVR(), p.Repo()+p.Href.Href)
}
  • Fetch reads repodata/repomd.xml, checks its detached signature repomd.xml.asc when a keyring is given, and reads the primary metadata (.gz, .xz or .zst) by the sha256 that repomd.xml lists. Fedora and UBI do not publish repomd.xml.asc; there the packages carry the signatures, so pass a nil keyring and check each rpm on download.
  • Merge the results of several repositories into one slice before NewIndex.
  • Requires may be rich dependencies (and, or, if, unless, with, without); conditionals are rechecked until the set is stable.
  • File requires resolve against the file lists in primary.xml.
  • Choice reports each requirement where several packages qualify and the resolver had to guess.

Testing

go test ./... resolves the seed sets under deb/testdata and rpm/testdata offline and compares the result with what apt or dnf picked for the same metadata.

Distribution Metadata Seed sets Result
Debian trixie snapshot.debian.org 20261101T000000Z, main 7 identical to apt
Ubuntu noble snapshot.ubuntu.com 20261101T000000Z, main and universe, noble and noble-updates 7 identical to apt
Fedora 43 releases/43/Everything 7 identical to dnf with Prefer

The seed sets cover curl (with and without Recommends), openjdk/java 21, python3, build-essential, systemd, glibc-langpack-en and git with openssh. To regenerate the data, run go test -tags gen -run TestGenerate ./deb (or ./rpm); it needs podman and network access. The generator keeps only the metadata reachable from the seeds.

UBI 9 metadata is not redistributed. PKGRESOLVE_NETWORK=1 go test -run TestLiveUBI9 ./rpm fetches the live UBI 9 baseos and appstream repos with rpm.Fetch and compares package names, without versions, against the names dnf picked (rpm/testdata/ubi9/names.json, with Prefer and minus Supplements). The repos move, so a dnf choice that changes upstream can break this test; regenerate the names with the generator.

Limits

  • No backtracking. Both resolvers pick greedily in queue order and never revisit a pick. When a later requirement cannot be met next to an earlier pick, Resolve fails with the unmet dependency in the error. Name the alternative you want in the seeds (or in Prefer for rpm) and resolve again.
  • No maintainer scripts or triggers. The resolvers choose packages. They neither unpack nor configure them.
  • No package download. Fetch reads metadata only. Each result carries the pool path and checksum to fetch and verify a package with.
  • Newest version only. Each index keeps the highest version of each package (per architecture for deb). Pins, apt preferences, dnf module streams and excludes are not modelled; filter the metadata before indexing instead.
  • Provider choice is a heuristic; Prefer settles it. deb picks the provider with the highest Priority, then by name, which matched apt on every golden set. rpm picks, in order: a Prefer entry, a provider that a picked package Recommends, the package named like the requirement, then the shortest name. libsolv, which dnf uses, has further rules that this resolver does not copy. Where they decide the outcome, list the provider you want in Prefer, and use Options.Choice to find such guesses. For example, dnf picks glibc-minimal-langpack for glibc-langpack on Fedora 43 and UBI 9, and openssl-fips-provider for fips-provider-so on UBI 9; the golden tests set both in Prefer.
  • No Supplements or Enhances (rpm). dnf with weak dependencies on also installs packages that supplement the transaction, such as gawk-all-langpacks on UBI 9. Resolve does not.
  • Suggests are ignored, as by apt and dnf by default.
  • deb: versioned Provides only satisfy versioned dependencies with =, as Debian policy defines. Conflicts and Breaks are checked when a candidate is picked, so a candidate that clashes is skipped for the next one.
  • rpm: one architecture plus noarch per index; multilib is not modelled. A provider that conflicts with or obsoletes a picked package is skipped; a clash left once the closure is complete fails the resolve.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL