Packaging an existing Apt package into snap?

Hello everyone :grin: I’m a complete snap newb. I’m trying to wrap my head around this… especially since I’m looking into using immutable ubuntu and the only way to get apps is via snaps from what I understand.
Issue for us is if an app we need isn’t alrady a snap we have to make it… Problem is I haven’t found a single tutorial that takes you through the steps of creating a snap from an apt-package (if it’s possible). I’ve been looking up forums and reddits with absolutely zero luck.
Say if I wanted to take Microsoft Edge and make it a snap (as an example, since we do happen to require it in our environment)?
Any help or pointers would be gretly appreciated :grin::sunglasses:

Not possible.

Must install it, then get the files and use: Pre-built apps | Snapcraft documentation

I like the link @Dadu042 provided, that’s a good starter for repacking an existing package into a snap.

You could also take advantage of the stage-packages keyword to download and unpack apt packages into your stage directory.

I will say that snapping a browser as a confined snap is not an easy introduction, as they are usually complex to package as a snap.

1 Like

Not true.

Is so possible, many snaps published in the store do it.

I made a confined snap of Microsoft Edge 88.0.673.0-1 back in October 2020. It ‘just’ dumped the deb from this repo into the snap, added a few dependencies and a launcher script. It’s not hard at all, and there’s a ton of snaps that do it.

The other way to do it is add a package-repository to your yaml, and specify what you want to build as a build-package. That’s what the Steam snap does (among a bazillion other things).

2 Likes

Here’s an example of installing a regular deb package: snap/snap/snapcraft.yaml at main · localsend/snap · GitHub

Here’s an example of installing a deb from a repo: librewolf-snap/snap/snapcraft.yaml at main · thatLeaflet/librewolf-snap · GitHub

1 Like

Ok, done. It’s not finished, but it launches with snap run microsoft-edge. It’s mostly a copy/paste of the Chromium snap config, with huge bits left out because this is MVP proof of concept, not intended for production use. Have fun with it. If you break it, you get to keep the pieces.

snapcraft.yaml

name: microsoft-edge
version: "127.0.2651.105-1"
summary: Microsoft Edge
description: Microsoft Edge is a cross-platform web browser developed by Microsoft. It was first released for Windows 10 and Xbox One in 2015, then for Android and iOS in 2017, for macOS in 2019, and as a preview
for Linux in October 2020.
grade: stable
confinement: strict
base: core22
assumes:
  - snapd2.55 # >=2.55 needed for the cups interface
compression: lzo

parts:
  edge:
    plugin: dump
    source: https://packages.microsoft.com/repos/edge/pool/main/m/microsoft-edge-stable/microsoft-edge-stable_${SNAPCRAFT_PROJECT_VERSION}_amd64.deb
    stage-packages:
      - libnss3
      - libxss1

  # Stage packages required for the "man" binary, which is invoked when
  # MS-Edge / chromium is called with the "-h" (or "--help") argument
  # (see https://launchpad.net/bugs/1848083).
  manpage:
    plugin: nil
    stage-packages:
      - groff-base
      - libgdbm6
      - libpipeline1
      - man-db
    prime:
      - -etc
      - -usr/lib/tmpfiles.d
      - -usr/share/bug
      - -usr/share/calendar
      - -usr/share/doc
      - -usr/share/doc-base
      - -usr/share/lintian
      - -usr/share/man
      - -usr/share/man-db
      - -var

apps:
  microsoft-edge:
    extensions: [gnome]
    command: opt/microsoft/msedge/microsoft-edge
    environment:
      CHROME_CONFIG_HOME: $SNAP_USER_COMMON
      GTK_USE_PORTAL: 1
    plugs:
      - audio-playback
      - audio-record
      - bluez # for Web Bluetooth (https://launchpad.net/bugs/1887201)
      - camera
      - cups
      - hardware-observe
      - home
      - joystick
      - mount-observe
      - network
      - network-manager
      - password-manager-service
      - pcscd
      - raw-usb # for WebUSB (https://launchpad.net/bugs/1780678)
      - removable-media
      - screen-inhibit-control
      - system-packages-doc
      - u2f-devices
      - unity7 # required for xdg-open to work
      - upower-observe

plugs:
  # This is not used or needed for anything other than to trigger automatic
  # installation of the cups snap via "default-provider: cups"
  foo-install-cups:
    interface: content
    content: foo
    default-provider: cups
    target: $SNAP_DATA/foo
  browser-sandbox:
    interface: browser-support
    allow-sandbox: true
  dot-local-share-applications:
    interface: personal-files
    write: [$HOME/.local/share/applications]
  dot-local-share-icons:
    interface: personal-files
    write: [$HOME/.local/share/icons]
  microsoft-edge-config:
    interface: personal-files
    read: [$HOME/.config/microsoft-edge]

README.md

# Microsoft Edge

snapcraft --use-lxd

snap install microsoft-edge_127.0.2651.105-1_amd64.snap --dangerous

for f in microsoft-edge:audio-record microsoft-edge:bluez microsoft-edge:browser-sandbox microsoft-edge:camera  microsoft-edge:foo-install-cups microsoft-edge:hardware-observe microsoft-edge:joystick microsoft-edge:mount-observe  microsoft-edge:network-manager  microsoft-edge:password-manager-service  microsoft-edge:pcscd microsoft-edge:dot-local-share-applications microsoft-edge:dot-local-share-icons  microsoft-edge:microsoft-edge-config microsoft-edge:raw-usb microsoft-edge:removable-media microsoft-edge:system-packages-doc  microsoft-edge:u2f-devices ; do sudo snap connect $f; done

snap run microsoft-edge
1 Like

This was unexpected lol!!! I was going through your youtube tutorial… Wow… there are so many facets to putting something like this together… The stage packages, prime, the plugins … how you even start to piece them together is just… I was picturing (or hoping) it was a situation more similar to the old “make it portable” apps that would capture an installation and repackage it with everything required for it to run… Like Cameyo or even thinapp… Those old skool windows apps that would record the installation and repackage it… wow

This is going to have a learning curve all right lol!! Thank you all!!

I Am Not Worthy GIFs | Tenor

2 Likes