Creating the same alias for a container and a VM

I know that it must be possible to have the same alias for a container image and a VM image simultaneously, because the public images: server does this:

$ incus image list images: ubuntu/22.04/cloud
+-----------------------------------+--------------+--------+-------------------------------------+--------------+-----------------+-----------+----------------------+
|               ALIAS               | FINGERPRINT  | PUBLIC |             DESCRIPTION             | ARCHITECTURE |      TYPE       |   SIZE    |     UPLOAD DATE      |
+-----------------------------------+--------------+--------+-------------------------------------+--------------+-----------------+-----------+----------------------+
| ubuntu/jammy/cloud (3 more)       | 0e2ef69d7367 | yes    | Ubuntu jammy amd64 (20240328_09:31) | x86_64       | CONTAINER       | 137.29MiB | 2024/03/28 00:00 UTC |
+-----------------------------------+--------------+--------+-------------------------------------+--------------+-----------------+-----------+----------------------+
| ubuntu/jammy/cloud (3 more)       | e8f4af613cd6 | yes    | Ubuntu jammy amd64 (20240328_09:31) | x86_64       | VIRTUAL-MACHINE | 293.96MiB | 2024/03/28 00:00 UTC |
+-----------------------------------+--------------+--------+-------------------------------------+--------------+-----------------+-----------+-------
...

But I can’t work out how to do this locally.

$ incus image list
+----------+--------------+--------+---------------------------------------------+--------------+-----------------+------------+----------------------+
|  ALIAS   | FINGERPRINT  | PUBLIC |                 DESCRIPTION                 | ARCHITECTURE |      TYPE       |    SIZE    |     UPLOAD DATE      |
+----------+--------------+--------+---------------------------------------------+--------------+-----------------+------------+----------------------+
| nmm-base | 65f695728219 | yes    | Ubuntu jammy amd64 (cloud) (20240328_09:31) | x86_64       | CONTAINER       | 296.21MiB  | 2024/03/28 21:08 UTC |
+----------+--------------+--------+---------------------------------------------+--------------+-----------------+------------+----------------------+
| nsrc-nmm | 07a0e7cd6107 | yes    |                                             | x86_64       | VIRTUAL-MACHINE | 2116.18MiB | 2024/03/29 08:34 UTC |
+----------+--------------+--------+---------------------------------------------+--------------+-----------------+------------+----------------------+

$ incus image alias create foobar 65f695728219
$ incus image alias create foobar 07a0e7cd6107 --vm
Error: unknown flag: --vm
$ incus image alias create foobar 07a0e7cd6107
Error: Alias "foobar" already exists

What am I missing?

The corresponding code is here. I suppose the issue is that it’s not really a duplicate alias if one is for the container and the other is for a VM.

The images: images were probably not created through incus image.

err = tx.CreateImageAlias(ctx, projectName, alias.Name, imgID, alias.Description)

I guess the image itself (from imgID) knows whether it’s a --vm image or not.

The images: images were probably not created through incus image .

Perhaps not, but I don’t think that’s relevant here; I’m only concerned about creating aliases to images, not the images themselves.

You can replicate this problem using incus’ own images:

$ incus image copy images:ubuntu/22.04/cloud local:
$ incus image copy images:ubuntu/22.04/cloud local: --vm
$ incus image info images:ubuntu/22.04/cloud | grep ^Fingerprint:
Fingerprint: 0e2ef69d73679dbfee3a21ae1c3707d644af437951e937cab876178202cfa92b
$ $ incus image info images:ubuntu/22.04/cloud --vm | grep ^Fingerprint:
Fingerprint: e8f4af613cd6adc7529af4f2b3df4fe7bca545f13a2cd01814431a6acd8630c0

Now I want to create local aliases which are named the same as the remote ones:

$ incus alias add ubuntu/22.04/cloud 0e2ef69d7367
$ incus alias add ubuntu/22.04/cloud e8f4af613cd6
Error: Alias ubuntu/22.04/cloud already exists

It’s not possible for an Incus server to have an image alias point to two different images.
It is however possible for a simplestreams server to do that.