nixpkgs icon indicating copy to clipboard operation
nixpkgs copied to clipboard

Standardize User-Agent format for all fetchers in nixpkgs

Open MiniHarinn opened this issue 7 months ago • 3 comments

Problem

Fetchers in nixpkgs currently lack a centralized/standardized User-Agent format. This leads to inconsistent identification across fetchers and makes nixpkgs traffic invisible to registry and mirror operators.

Only fetchurl (and the many fetchers layered on top of it) identify themselves as nixpkgs. The lockfile-aware ecosystem fetchers do not, which means traffic to upstreams' registry from nixpkgs builders is indistinguishable from generic library traffic on the operator side.

The following lockfile-aware fetchers currently do not identify themselves as originating from nixpkgs (Of course there could be more; I only managed to find these for now.):

Fetcher Target HTTP Client User-Agent Sent
fetchCargoVendor crates.io Python requests python-requests/X.X.X
fetchNpmDeps npm registry Rust isahc isahc/X.X.X
fetchYarnDeps npm registry Node.js https Node.js default
fetchPypiLegacy PyPI (legacy API) Python urllib Python-urllib/3.X
fetchipfs IPFS gateways curl (no --user-agent) curl/X.X.X

We already have some problems regarding user agents. Recently, crates.io started enforcing a policy that blocks common default user agents such as python-requests, causing mass breakage across Rust packages in nixpkgs. See #512735 and the upstream issue at https://github.com/rust-lang/crates.io/issues/13482 for more information.

Motivation

Upstream registries and mirror operators (crates.io, npmjs, etc.) use the User-Agent header to recognize clients for rate limiting, abuse handling, allowlisting, and capacity planning. Today, nixpkgs traffic to these services is indistinguishable from generic library traffic, so operators cannot coordinate with us or give us dedicated quotas even when they want to. This is a consistency fix, not a new policy.

Proposal

Set a standardized User-Agent on any HTTP request originating from fetchers in nixpkgs, in a global/recognizable format aligned with RFC 9110 Section 10.1.5.

This could be something like:

nixpkgs/<lib.version> <fetcherName>/<fetcherVersion> (https://github.com/NixOS/nixpkgs/; <contact-point-information>)

Per RFC 9110 Section 5.5 and Section 10.1.5, this parses as:

  • Product nixpkgs, version => nixpkgs version
  • Product <fetcherName>, version => <fetcherVersion>
  • Comment on product <fetcherName>, value => contents of (...)

The <contact-point-information> field is important because issues in nixpkgs can easily go unnoticed if no one responsible is pinged directly (this concern is discussed in https://github.com/NixOS/nixpkgs/pull/512735#discussion_r3131155996). Routing operator reports to a known point of contact (e.g. an issue) ensures they reach whoever is currently active on fetcher maintenance rather than depending on any single maintainer's availability.

Note

I'm not certain that this kind of change is doable in nixpkgs, so I am opening this issue for discussion. If you feel that something is off or have additional comments or suggestions, feel free to leave them as comments directly in this issue (🎉).

MiniHarinn avatar Apr 24 '26 06:04 MiniHarinn

(https://github.com/NixOS/nixpkgs/; <contact-point-information>)

I think we can just do (https://github.com/NixOS/nixpkgs/issues/…), which is short and can point to a meta‐issue for interested parties to subscribe to. No need for both.

emilazy avatar Apr 26 '26 01:04 emilazy

By the way, fetchurl already uses curl/‹version› Nixpkgs/‹version›.

emilazy avatar Apr 26 '26 01:04 emilazy

By the way, fetchurl already uses curl/‹version› Nixpkgs/‹version›.

Yep, also fetchItchIo already has a user agent in the format Python/<py-version> Nixpkgs/<nixpkgsVersion>, but standardizing this across nixpkgs is probably better for consistency.

MiniHarinn avatar Apr 26 '26 05:04 MiniHarinn