How to install snap packages in Cubic

I've been customising my Ubuntu Live ISO by installing various packages through the chroot environment in Cubic. Installing through apt appears to be working just fine but I just can't seem to be able to install through snap. Here's the error I get when I try "snap install vlc"

error: cannot communicate with server: Post http://localhost/v2/snaps/vlc: dial unix /run/snapd.socket: connect: no such file or directory

How do I fix this?


Solution 1:

Services such as snapd do not run in Cubic's Terminal page, so you can not install snap packages using the snap install command.

However, you can "seed" snaps.

Here is an example seeding the Gnome Calculator snap package. I tested this approach on Xubuntu 20.04. These instructions are adapted from this blog post.

Preform the following steps on your host computer...

  1. Create the seed directory structure.

    mkdir seed
    cd seed
    mkdir snaps
    mkdir assertions
    
  2. Download the snaps.

    The following additional snaps are required to install Gnome Calculator:

    • core
    • core18
    • gnome-3-34-1804
    • gtk-common-themes

    Identifying required snap packages can be a trial and error process (as explained in step 12, below).

    The core snap package is required because it is used by the model and account assertions (in step 4, below).

    Depending on the snap package you are installing, you may need core18 (Ubuntu 18.04) or core20 (Ubuntu 20.04) . See this answer for a good explanation of what the core snap packages are and why you may need them. Gnome Calculator requires core18.

    snap download core
    snap download core18
    snap download gnome-3-34-1804
    snap download gnome-calculator
    snap download gtk-common-themes
    
  3. Move the downloaded files to the correct directories.

    mv *snap ./snaps
    mv *assert ./assertions
    
  4. Create model and account assertions.

    You only have to do this step once, even if you download additional snap packages.

    cd ./assertions
    snap known --remote model series=16 model=generic-classic brand-id=generic > generic-classic.model
    ACCOUNT_KEY=`awk '/sign-key-sha3-384/{print $2}' generic-classic.model`
    snap known --remote account-key public-key-sha3-384=${ACCOUNT_KEY} > generic.account-key
    snap known --remote account account-id=generic > generic.account
    
  5. Create a seed.yaml file.

    cd ..
    touch ./seed.yaml
    
  6. List the snaps so you can add them to the seed.yaml file.

    ls -1 snaps
    

    Here is the output for this example.

    core_11167.snap
    core18_2066.snap
    gnome-3-34-1804_72.snap
    gnome-calculator_884.snap
    gtk-common-themes_1515.snap
    
  7. Open the new seed.yaml file in a text editor such as Gedit.

    Add all of the snaps you had downloaded in step 2, using the following structure:

    • The file starts with snaps:
    • Each snap is separated by a line containing the dash (-) character
    • The name is the part of the *.snap file before the underscore (_) character
    • The channel should be stable (unless you downloaded from a different channel)
    • The file is simply the full file name of the *.snap file

    Here is the seed.yaml for this example.

    snaps:
      -
        name: core
        channel: stable
        file: core_11167.snap
      -
        name: core18
        channel: stable
        file: core18_2066.snap
      -
        name: gnome-3-34-1804
        channel: stable
        file: gnome-3-34-1804_72.snap
      -
        name: gnome-calculator
        channel: stable
        file: gnome-calculator_884.snap
      -
        name: gtk-common-themes
        channel: stable
        file: gtk-common-themes_1515.snap
    

Preform the following steps using Cubic...

  1. Launch Cubic.

  2. Navigate to the Terminal page.

    Change the current directory:

    cd /var/lib/snapd
    
  3. Copy the snap seed files.

    Open a file browser such as Nautilus.

    Drag and drop the seed directory you created in step 1 onto the Cubic window in order to copy it into the current directory /var/lib/snapd.

  4. Finish generating the custom ISO and exit Cubic.

Testing and finding errors...

  1. Boot into your customized ISO.

    Open a terminal and execute:

    snap warnings
    

    If the snap packages were installed successfully, you will see the message No warnings. Otherwise, you will see a message explaining the issue. If the snap you tried to seed requires another snap package, the missing snap package will be listed. In that case, add the missing package, as shown in step 2.

    In my test, the Gnome Calculator icon was not initially displayed in the Applications list. However, after I launched the application from the command line, using gnome-calculator, the launcher icon was then added to the Applications list.