Score:3

What, exactly, does aptitude's ?origin() search term match against?

kr flag

Because it doesn't seem to be the same string as is produced by the %O display format escape, nor the URL from sources.list.d.

In my case, I'm looking for packages which I installed from non-Ubuntu sources and the trouble I'm having can be seen in this example:

$ aptitude search --display-format '%v %p %O#' '?exact-name(syncthing)'
1.23.6         syncthing                            Syncthing:syncthing [amd64]         
$ aptitude search --display-format '%v %p %O#' '?exact-name(syncthing) !?origin(ubuntu)'
$ aptitude search --display-format '%v %p %O#' '?exact-name(syncthing) ?origin(ubuntu)'
1.23.6         syncthing                            Syncthing:syncthing [amd64]         
$ 

When the ?origin term isn't included at all, SyncThing shows up with an origin that doesn't contain "ubuntu", so I expected it to remain when adding !?origin(ubuntu) (i.e. "must not come from an origin matching the pattern 'ubuntu'"). Instead, it disappears unless I change the term to require that it does come from an origin matching "ubuntu"!

Looking at the source list for the origin isn't enlightening, either:

$ cat /etc/apt/sources.list.d/syncthing.list
deb [signed-by=/etc/apt/keyrings/syncthing-release-key.gpg] https://apt.syncthing.net/ syncthing stable

This clearly isn't a case of just "all origins match 'ubuntu'", however — if I look at VS Code instead of SyncThing, it behaves as expected:

$ aptitude search --display-format '%v %p %O#' '?exact-name(code)'
1.81.0-1690980 code                                 code stable:stable [amd64]          
$ aptitude search --display-format '%v %p %O#' '?exact-name(code) !?origin(ubuntu)'
1.81.0-1690980 code                                 code stable:stable [amd64]          
$ aptitude search --display-format '%v %p %O#' '?exact-name(code) ?origin(ubuntu)'
$                                                            

So how does the ?origin search term actually behave? What is it matching against?

Score:5
jp flag

The aptitude search term ?origin matches the Origin value in the repository's Release file.

For example, on a very basic install of 22.04 the output of apt-cache policy lists the following repositories. In this output the search term ?origin compares to the o= value, which is Ubuntu for all of the repositories on this machine.

root@ubuntu:~# apt-cache policy
Package files:
 100 /var/lib/dpkg/status
     release a=now
 500 http://security.ubuntu.com/ubuntu jammy-security/restricted amd64 Packages
     release v=22.04,o=Ubuntu,a=jammy-security,n=jammy,l=Ubuntu,c=restricted,b=amd64
     origin security.ubuntu.com
 500 http://security.ubuntu.com/ubuntu jammy-security/main amd64 Packages
     release v=22.04,o=Ubuntu,a=jammy-security,n=jammy,l=Ubuntu,c=main,b=amd64
     origin security.ubuntu.com
 500 http://archive.ubuntu.com/ubuntu jammy-updates/restricted amd64 Packages
     release v=22.04,o=Ubuntu,a=jammy-updates,n=jammy,l=Ubuntu,c=restricted,b=amd64
     origin archive.ubuntu.com
 500 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 Packages
     release v=22.04,o=Ubuntu,a=jammy-updates,n=jammy,l=Ubuntu,c=main,b=amd64
     origin archive.ubuntu.com
 500 http://archive.ubuntu.com/ubuntu jammy/restricted amd64 Packages
     release v=22.04,o=Ubuntu,a=jammy,n=jammy,l=Ubuntu,c=restricted,b=amd64
     origin archive.ubuntu.com
 500 http://archive.ubuntu.com/ubuntu jammy/main amd64 Packages
     release v=22.04,o=Ubuntu,a=jammy,n=jammy,l=Ubuntu,c=main,b=amd64
     origin archive.ubuntu.com

Browsing the repository's Release file shows corresponding values. E.g. http://us.archive.ubuntu.com/ubuntu/dists/jammy/Release contains

Origin: Ubuntu
Label: Ubuntu
Suite: jammy
Version: 22.04
Codename: jammy

With aptitude you can search the available packages from this Origin with a command like

aptitude search "?origin(Ubuntu)"

You can search for "packages which I installed from non-Ubuntu sources". The ?origin(.*) search term can be added to avoid issues with packages that may not have any origin.

aptitude search "?and(?installed, ?not(?origin(Ubuntu)))"
or
aptitude search "?and(?installed, ?origin(.*), ?not(?origin(Ubuntu)))"

As a more complex example, one of my favorite commands is to find all packages with an update available from the official Ubuntu repositories (including UbuntuESM).

aptitude search "?and(?upgradable, ?narrow(?version(CANDIDATE), ?origin(^Ubuntu~(ESM~){0,1}$)))"

The origin name is particularly confusing because

  • The search term ?origin does not match the display format %O value, as noted in the original question.
  • apt_preferences lets you specify an origin, but that origin matches the repository hostname. E.g. archive.ubuntu.com.
  • unattended-upgrades has configuration for Allowed-Origins that is really a combination of the repository values.

syncthing

If I add the syncthing repository then the syncthing package exists with both Ubuntu and Syncthing origins.

The output of apt-cache policy shows the following information about the repository.

 500 https://apt.syncthing.net syncthing/stable amd64 Packages
     release o=Syncthing,a=syncthing,n=debian,l=Syncthing,c=stable,b=amd64
     origin apt.syncthing.net

The output of apt-cache policy syncthing shows packages available from Syncthing and Ubuntu repositories.

root@ubuntu:~# apt-cache policy syncthing
syncthing:
  Installed: (none)
  Candidate: 1.23.6
  Version table:
     1.23.6 500
        500 https://apt.syncthing.net syncthing/stable amd64 Packages
     1.23.5 500
        500 https://apt.syncthing.net syncthing/stable amd64 Packages
     1.18.0~ds1-3ubuntu0.2 500
        500 http://archive.ubuntu.com/ubuntu jammy-updates/universe amd64 Packages
        500 http://security.ubuntu.com/ubuntu jammy-security/universe amd64 Packages
     1.18.0~ds1-3 500
        500 http://archive.ubuntu.com/ubuntu jammy/universe amd64 Packages

An aptitude search like ?and(?origin(Ubuntu), ?exact-name(syncthing)) will match syncthing because there is a version of that package that matches.

Some tests I tried

root@ubuntu:~# aptitude search "?and(?origin(Ubuntu), ?exact-name(syncthing))" -F "%p,%m#,%O#" | column -t
syncthing,Syncthing  Release  Management  <[email protected]>,Syncthing:syncthing  [amd64]

root@ubuntu:~# aptitude search "?any-version(?and(?origin(Ubuntu), ?exact-name(syncthing)))" -F "%p,%m#,%O#" | column -t
syncthing,Syncthing  Release  Management  <[email protected]>,Syncthing:syncthing  [amd64]

root@ubuntu:~# aptitude search "?all-versions(?and(?origin(Ubuntu), ?exact-name(syncthing)))" -F "%p,%m#,%O#" | column -t

You can try to use search terms like ?narrow to restrict to specific versions of packages. This should show installed packages where the installed version has an Origin that is not Ubuntu.

aptitude search "?narrow(?version(CURRENT),?and(?origin(.*),?not(?origin(^Ubuntu))))"

notes

I wish I had a source I could reference. This just information I have figured out in the past through testing.

Ben Blank avatar
kr flag
Hmm. Digging in to my use case some more, the behavior I'm seeing doesn't seem to match your description. [Syncthing's Release file](https://apt.syncthing.net/dists/syncthing/Release) doesn't contain the string "ubuntu" at all, but matches `?origin(ubuntu)`. [VS Code's release file](https://packages.microsoft.com/ubuntu/23.04/prod/dists/lunar/Release) *does* contain the string "ubuntu" — right in the Origin field, even — but matches the negated `!?origin(ubuntu)` instead.
Andrew Lowther avatar
jp flag
I tested with syncthing and I think because there is an official package in the Ubuntu repository you may be getting unexpected results. I added some more notes about what I see.
Ben Blank avatar
kr flag
Ah! Of course. Syncthing exists in the official repos, but Code does not, so Syncthing appears in the list of "has **any origin** that matches 'ubuntu'" but Code doesn't. I was conflating "Syncthing, the package" with "Syncthing, the repo/origin". Thanks again for your help!
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.