How to set up APT preferences in the presence of apt-cacher-ng?

The problem is the following: there are a number of nodes that use apt-cacher-ng. The all apt URLs are in the form:

deb http://192.168.1.2:3142/archive.ubuntu.com/ubuntu/ jammy-updates main restricted
deb [arch=amd64] http://192.168.1.2:3142/HTTPS///packages.microsoft.com/ubuntu/22.04/prod jammy main
deb http://192.168.1.2:3142/HTTPS///developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/ /

Now setting up APT preferences in the following form has no effect whatsoever. E.g. the following content in files in directory /etc/apt/preferences.d

Package: dotnet* aspnet* netstandard*
Pin: origin *microsoft.com
Pin-Priority: 500

Package: dotnet* aspnet* netstandard*
Pin: origin *ubuntu.com
Pin-Priority: 1

How should one configure APT preferences when using apt-cacher-ng? Pin: origin does not seem to work, so there must be some other trick how to achieve that. I could not find it with reasonable search.

It is necessary to use preferences, because e.g. dotnet packages from Ubuntu and Microsoft and nvidia CUDA packages from NVidia and Ubuntu have similar names on top level, but dependency names vary and cause the SDKs to be unusable when mixed. Cacher is used for obvious reason, just xN less network traffic to pull updates.

Asked By: jpe

||

Instead of pinning by server address, you can pin using information contained in each repository. In particular, you can use the “Origin” field in each repository’s Release file:

Pin: release o=Ubuntu

for Ubuntu repositories,

Pin: release o=microsoft-ubuntu-jammy-prod

for the Microsoft repository,

Pin: release o=NVIDIA

for the NVIDIA repository.

To determine which value to use, retrieve the relevant Release file (e.g. https://packages.microsoft.com/ubuntu/22.04/prod/dists/jammy/Release) and look for the “Origin” entry at the top of the file.

Answered By: Stephen Kitt
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.