nixhttp

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Package nixhttp serves the native Nix HTTP binary-cache protocol under /artifactory/api/nix/{repoKey}: nix-cache-info, narinfo files and the NAR archives they name for GET and HEAD, publication and deletion of each with PUT and DELETE, and a rebuild of the repository's index with POST reindex. A hosted repository signs each narinfo it serves with its Ed25519 key pair, and a remote one verifies upstream signatures against its own. It also serves channels for nix-channel: channels/<name> redirects to the channel's newest snapshot, whose folder answers a page and holds nixexprs.tar.xz, and a PUT to a snapshot's folder publishes it. Metadata and archive rules are the format package's (artifacts/ecosystem/nix); this package answers HTTP with them.

Role

artifacts module, ecosystem layer: the native Nix HTTP binary-cache protocol of the Nix slice. It is named nixhttp so that it does not shadow net/http. Outside tests, only its own http subtree, the module's http adapters and app may import it (decision 0044, dependency rule 9).

Inputs

  • Driving: the server, which mounts Protocol through the router kit (pkgroute) for repositories of package type nix, local, federated, virtual or remote.
  • Driven: the router kit (pkgroute.Kit), which resolves the repository and the caller, checks permissions, reads, stores and deletes items and writes errors; the access contracts in Options (access/api): the authorizer, which evaluates the caller's permissions again just before a hosted or virtual repository's narinfo or archive is served, and the key pairs, which sign a hosted narinfo and verify a remote's; the remote source service (Options.RemoteSources), which fetches upstream narinfo and archives into the remote cache, and a remote's channels from the NixOS Channel Registry and its releases (Options.Channels and Options.Releases); and the format package.

Outputs

  • Protocol and Options: the routes, the source of each repository class and the Artifactory error profile.
  • Answers: nix-cache-info; a narinfo, signed when a local or federated repository names a primary key pair, with its archive URL rewritten to nar/<store hash>/<file> so that every archive download passes its narinfo's checks; the archive; and 201 for a publication, 204 for a deletion and 200 for a reindex.
  • Storage: a hosted repository stores the narinfo the client PUTs to <hash>.narinfo, and the NAR it names, in the store path's folder, binary-cache/<hash>/, as 7.x does. The NAR, which Nix uploads first to nar/<file> and which names no store path, is held there until the narinfo arrives, then stored in the folder from that upload, or from the same file stored for another store path. DELETE of <hash>.narinfo and nar/<hash>/<file> removes the stored files.
  • Channels: 302 from channels/<name> to the newest snapshot <flavor>/<snapshot> the caller may read, relative so the client's host and path prefix carry over; 200 with a page linking the tarball for the snapshot's folder; the tarball itself; and 201 for a snapshot's upload. A hosted channel's newest snapshot is the one uploaded last, a remote's is the one the registry names now, and a virtual's is its first member's in order that has one.

Invariants

  • A narinfo and its archive are served only to a caller who may read both, and only after the repository's configuration and the caller's permissions (or, for a remote, the source's authority) are checked again just before delivery.
  • A configured signing key that cannot be read, is not Ed25519, or whose key material or alias is invalid fails closed with 503.
  • A remote's narinfo must carry a valid signature by one of its configured key pairs; with none configured, upstream signatures are kept for the client's own trusted-public-keys check. Its archive must match the narinfo's hashes and sizes, and every upstream URL and redirect must stay beneath the remote's URL, on its origin.
  • The download policy (decision 0032) is checked after Read permission, at the file the client asked for alone, where the repository stores it: nix-cache-info; a narinfo or a NAR in a hosted repository's binary-cache folder, so that patterns written for 7.x match; and in a remote's cache at <hash>.narinfo and nar/<file>. A virtual repository checks its own at a hosted repository's paths [I]. A blacked-out repository or a path its patterns reject answers 404 with the policy's message. Patterns rejecting only a NAR leave its narinfo served, and a NAR is not refused at the narinfo it is found through. A virtual repository checks its own patterns at that path ("No repository found to serve the request") and passes over a member whose policy refuses it, a remote member's included.
  • A channel and a snapshot's page are computed, so Read permission comes first and then only the blackout refuses them, at the path asked for; a snapshot's tarball is refused by the blackout and patterns at its own path. A remote resolves a channel only at the channel registry and fetches its tarball only from the releases origin, never with the remote's credentials, and serves only the snapshot the registry names now.
  • A request with a query string is refused, publication needs a local or federated repository, and a virtual repository cannot be reindexed.
  • Statuses and error texts stay byte-identical.

References

Status

Implemented P9c, which delivered the plan's P33 group (issues #782 to #788). Moved here in P9d. Channels added by #1263, the binary-cache layout by #1296.

Testing

  • nix_test.go: publication, signing and the lifecycle; denials and malformed publications; federated and ordered virtual repositories; remote integrity, caching and offline reads; untrusted upstream metadata and bad archives; and a virtual repository's member order evaluated again on each read.
  • fault_test.go: a remote source's authority, hosted signing failures, path and virtual policy, exact-path permissions and revocation, faults that must not answer as a miss, and the request and delivery fences.
  • policy_test.go: the download policy at the path asked for on hosted and remote repositories, Read permission first, and a virtual repository's own patterns and its pass-over of refusing local and remote members.
  • binary_cache_test.go: a publication's files in the store path's folder, a NAR shared by two store paths, the permissions a publication needs, deletion by the client's URLs, and faults while placing the NAR.
  • channel_test.go: channel publication and following, refused uploads, the answers kept outside channel paths, permission and policy, and virtual channels.
  • remote_channel_test.go: a remote's channels from the registry, bad upstream answers, following a moved channel and offline reads, policy, and a virtual over a remote member.
  • channel_fault_test.go: paged listings, readable snapshots only, a folder in a tarball's place, store faults and a remote source's authority.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Protocol

func Protocol(o Options) pkgroute.Protocol

Protocol mounts the Nix binary-cache and channel routes for local, federated and virtual repositories, and for remote ones when o.RemoteSources is set.

Types

type Options

type Options struct {
	// RemoteSources serves remote repositories; nil answers them 501.
	RemoteSources *source.Service
	// Authorizer re-evaluates the caller's permissions against current
	// state just before a hosted or virtual repository's narinfo or archive
	// is served. Serving those requires it.
	Authorizer accessapi.Authorizer
	// KeyPairs reads the Ed25519 key pairs a repository names: a hosted
	// repository signs the narinfo it serves with its primary pair, and a
	// remote repository verifies upstream signatures against its pairs. A
	// repository that names a key pair requires it.
	KeyPairs accessapi.Keys
	// Channels is the NixOS Channel Registry a remote repository resolves
	// an official channel name against, and Releases the base the registry
	// redirects a channel to, whose tarball the remote caches. Nil means
	// https://channels.nixos.org and https://releases.nixos.org; tests
	// point both at a fixture.
	Channels, Releases *url.URL
}

Options configures the Nix binary-cache protocol. Its access contracts read through the request's context, so a server binds them over the store the router kit serves.

Jump to

Keyboard shortcuts

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