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/...
}
FetchverifiesInReleaseagainst the keyring and eachPackagesindex (.xz,.gzor plain) against the SHA256 thatInReleaselists. It returns the stanzas of every component and architecture.NewIndexalso takes stanzas parsed by the caller withcontrol.ParseBinaryIndex.- The result always includes the Essential packages of the native architecture, like a fresh
debootstrap. - Seeds are
name(native) orname:arch. - Multi-Arch follows the Debian Multiarch spec:
same,foreignandallowed, plus the:any,:nativeand:<arch>qualifiers.Architecture: allpackages 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)
}
Fetchreadsrepodata/repomd.xml, checks its detached signaturerepomd.xml.ascwhen a keyring is given, and reads the primary metadata (.gz,.xzor.zst) by the sha256 thatrepomd.xmllists. Fedora and UBI do not publishrepomd.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. Choicereports 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,
Resolvefails with the unmet dependency in the error. Name the alternative you want in the seeds (or inPreferfor rpm) and resolve again. - No maintainer scripts or triggers. The resolvers choose packages. They neither unpack nor configure them.
- No package download.
Fetchreads 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;
Prefersettles it. deb picks the provider with the highestPriority, then by name, which matched apt on every golden set. rpm picks, in order: aPreferentry, 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 inPrefer, and useOptions.Choiceto find such guesses. For example, dnf picksglibc-minimal-langpackforglibc-langpackon Fedora 43 and UBI 9, andopenssl-fips-providerforfips-provider-soon UBI 9; the golden tests set both inPrefer. - No Supplements or Enhances (rpm). dnf with weak dependencies on also installs packages that supplement the
transaction, such as
gawk-all-langpackson UBI 9.Resolvedoes 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
noarchper 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.