Best practices porting classic applications

I am trying to snap a cryptocoin Qt wallet as an exercise. The application doesn’t matter but I’ll use it as an example since it’s not “snap aware”.

When you bootstrap the wallet you choose your data directory (where it will download the blockchain to):

  • [X] Use the default data directory <-- default, doesn't work, outside of the snap tree
  • [ ] Use a custom data directory <-- works, inside the snap directory

The default option would only work by having the snap in classic confinement. This means I have two options: a classic snap or a snap that’s half working and you need to RTFM before using it. The first has the best UX, the second follows the “snap rules” and has the confinement advantages.

What is the best course of action here? Is there a way of showing a message at first boot explaining the default option will not work?

Where does it actually try to write the default data directory? Is it hard-wired somehow to put it in a hidden directory in your home?

I’ve had some success by setting $HOME in the environment stanza for the application. Cryptocurrencies specifically it’s worth coercing because the blockchain can be a chunky amount of data. The default $HOME for a snap is in the versioned $SNAP_USER_DATA (/home/user/snap/snapname/current) but might be better placed in the unversioned $SNAP_USER_COMMON (/home/user/snap/snapname/common).

    command: somebinary

Often this is sufficient to make the app put its data in the right place.

Might be worth looking at the source for the application and see how it derives the “default data directory”. If it’s trying to be ‘clever’ and put it in the host $HOME/.somefolder then that will fail. Might need patching either locally or as a contribution to the upstream project (in the best case).


Thanks @popey! This pointed me in the right direction, I can specify the data directory as a parameter:

command: desktop-launch $SNAP/bin/wallet -datadir=$SNAP_USER_COMMON/.wallet

This almost works but the the .wallet directory doesn’t exist yet when I run the application the first time and it doesn’t like that.

Is there a way to create a subfolder in the common directory? I tried via override-prime to create a subfolder but that doesn’t seem to do it.

You could create a launcher script which checks for the existence of the directory and if it doesn’t exist, makes it.

1 Like