How to make snap eligible for update-alternatives?

Hi,

I’ve packages alacritty and want to make it the default terminal app (aka x-terminal-emulator) I’ve found a manual way of doing it here.

Is there a way to make it via snapcraft.yml? An interface maybe?

2 Likes

This is on the edge of my knowledge, and I can’t vouch that it works, but I remember coming across this comment regarding a similar thing for the VS Code snap.

1 Like

this would require snapd to be able to manage alternatives outside of the confinement … the problem here is that snapd runs on many distros that do not know what the alternatives system is so adding code for such a feature would be rather complex with a lot of special casing for all the different distros and it would add an incosistency between different installs of the snap making debugging for snap maintainers harder …

2 Likes

In my case, alacritty is going to be an app with classic confinement due to the nature of terminal apps. Is there something like a post-installation hook that allows me to add the app as an x-terminal-emulator alternative?

1 Like

you can surely use an install hook in the case of a classic snap, but note that if the hook fails your snap wont be installable at all so you better add a lot of testing to make sure your snap can be installed on any system without alternatives … i.e. all of the archlinux derivatives (and arch itself) come immediately to mind. update-alternatives isnt any kind of standard except for debian/ubuntu …

… also better make damn sure to clean up properly after you when uninstalling :wink:

1 Like

I’ve also found out that all snap commands are proxies (or soft links) to /usr/bin/snap whereas update-alternatives requires direct binaries/scripts. Snapcraft will probably place all commands as soft links so I’m not sure whether this is doable with snaps. :frowning:

Manually adding an alternative like below doesn’t start alacritty but print snap usage instead:

sudo update-alternatives --install /usr/bin/x-terminal-emulator x-terminal-emulator /snap/bin/alacritty 50
$ x-terminal-emulator                                                                                                                                                                                                                                                                                      [ master ✭ ]
The snap command lets you install, configure, refresh and remove snaps.
Snaps are packages that work across many different Linux distributions,
enabling secure delivery and operation of the latest apps and utilities.

Usage: snap <command> [<options>...]

Commonly used commands can be classified as follows:

         Basics: find, info, install, remove, list
        ...more: refresh, revert, switch, disable, enable, create-cohort
        History: changes, tasks, abort, watch
        Daemons: services, start, stop, restart, logs
    Permissions: connections, interface, connect, disconnect
  Configuration: get, set, unset, wait
    App Aliases: alias, aliases, unalias, prefer
        Account: login, logout, whoami
      Snapshots: saved, save, check-snapshot, restore, forget
         Device: model, reboot, recovery
      ... Other: warnings, okay, known, ack, version
    Development: download, pack, run, try

For more information about a command, run 'snap help <command>'.
For a short summary of all commands, run 'snap help --all'.
1 Like

You can always install a script that is leveraged by update-alternatives

@sergiusens - even if I do that, I’d have to define it as a snap command, wouldn’t I? Let’s say, I’d added alacritty-start.sh as command into the snap. It’d be placed in /snap/bin/alacritty-start pointing to /usr/bin/snap ?

E.g. to have the opportunity to use normal java, javac and etc binaries in case you’ve installed OpenJDK using Snap, you can use this command:

set +H; for exe in java javac javadoc jar jarsigner jlink jpackage; do sudo bash -c "echo -e '#!/usr/bin/env bash\n/snap/bin/openjdk.$exe \"\$@\"\n' > /usr/local/bin/$exe; chmod +x /usr/local/bin/$exe"; done

Snap is using the binary name to detect which application to run…