Package-repositories fail when building with LXD or multipass

Hello everyone,

I recently had a use-case to add package-repositories to a snap I maintain (specifically, to add the LLVM apt repo so I could use a recent clang as a build-package). However, this fails when I just run snapcraft (i.e. when multipass is used):

$ snapcraft --enable-experimental-package-repositories
*EXPERIMENTAL* package-repositories in use
Launching a VM.
*EXPERIMENTAL* package-repositories in use                                      
Hit:2 xenial InRelease                    
Get:3 xenial-updates InRelease [109 kB]                             
Get:4 xenial-security InRelease [109 kB]                           
Reading package lists... Done                              
E: The method driver /usr/lib/apt/methods/https could not be found.
N: Is the package apt-transport-https installed?
Failed to update the package cache: Some files could not be downloaded:

failed to run apt update

Check that the sources on your host are configured correctly.

And it fails in a different way when run with --use-lxd:

$ snapcraft --use-lxd --enable-experimental-package-repositories
*EXPERIMENTAL* package-repositories in use
Launching a container.
Waiting for container to be ready
Waiting for network to be ready...
*EXPERIMENTAL* package-repositories in use
Hit:2 xenial InRelease                    
Get:3 xenial-updates InRelease [109 kB]   
Get:4 xenial-security InRelease [109 kB]         
Get:5 xenial-updates/main Sources [349 kB]
Hit:1 llvm-toolchain-xenial InRelease
Get:6 xenial-updates/main amd64 Packages [1179 kB]                     
Get:7 xenial-updates/main Translation-en [442 kB]                      
Get:8 xenial-updates/universe amd64 Packages [801 kB]  
Get:9 xenial-updates/universe Translation-en [335 kB]
Get:10 xenial-security/main Sources [167 kB]              
Get:11 xenial-security/main amd64 Packages [903 kB]              
Get:12 xenial-security/main Translation-en [336 kB]
Get:13 xenial-security/universe amd64 Packages [496 kB]
Get:14 xenial-security/universe Translation-en [204 kB]
Fetched 5428 kB in 1s (2953 kB/s)                                       
Reading package lists... Done
Could not find a required package in 'build-packages': clang-9

This is despite the fact that the clang-9 package does exist: things proceed just fine with a --destructive-mode build.

The particular lines added to snapcraft.yml are:

  - type: apt
    deb-types: [deb]
    suites: [llvm-toolchain-$SNAPCRAFT_APT_RELEASE]
    components: [main]
    key-id: 6084F3CF814B57C1CF12EFD515CF4D18AF4F7421

… so note that this is not an https URL! Rather, it seems that the URL is automatically switched to https:// when snapcraft is run via multipass or LXD, but only inside LXD is apt https support auto-installed. Something else must be going wrong in the latter case, because there is no reason why clang-9 should not be found (perhaps there is a silent failure to read from the apt repo instead?).

I appreciate the feature is still experimental, so no worries if this is just the way things are right now. But I’m sharing this just in case the issues haven’t been observed before, and also because it would be fun to find out what’s going on here. Can anyone shed any light?

Thanks and best wishes,

  -- Joe

I think you have the wrong suite if you want to install clang-9.

suites: [llvm-toolchain-$SNAPCRAFT_APT_RELEASE-9] should work for you.

As far as the Multipass error, this is another case where the LXD and Multipass base images appear to diverge. The LLVM apt http URL redirects (301) to https, so apt-transport-https is required.

I just put up a PR to ensure that apt-transport-https is installed for all images: