Alternative to layout for classic confinement?

In dev_mode I was using a layout so that erl could fine erlexec without modification:

Erlang is built and installed with --prefix=/usr which is why the layout creates a symlink for /usr/lib/erlang, it is where erl script will look for the erlexec binary.

After learning layout is not supported by classic confinement I’m wondering what is the best alternative for this snap to work?

Can you just use --prefix=/snap/erlang/current/usr instead?

Is that standard practice? I had thought that a bad solution since current is a symlink and could be pointed to a different install. But if running a non-current version is supposed to not work I suppose it would work. Is that the case?

Would setting ERL_LIBS make any difference? It looks like, from a very quick scan of the docs so I might be very wrong, this environment variable sets the library path. Try setting it to $SNAP/usr/lib?

Na, ERL_LIBS is for discovering Erlang libraries that are only loaded after initial boot which requires finding erts.

You can see how the erl script is generated when compiling Erlang and how it references the install directory directly here:

You could manually patch that file before building with the following substitution:

1 Like

The current symlink will always be there and point to a valid install when your snap is installed and enabled (except for bugs of course), so I would say try this and see what happens. It’s possibly you might run into issues down the road installing this snap on distros that don’t use /snap/... and instead have /var/lib/snapd/snap/... but I’m not sure.

Ok. I had done that in my very first snap attempt and it worked for erl at least. I worried there might be other places that reference the install directly and then discovered layouts in the docs so moved on with that.

There must be other snaps that build projects don’t work if where they are told to install with --prefix is different from where they actually are on the filesystem? Is patching the strategy usually used? I couldn’t find anything in the docs for what I thought would be a common issue – well except for layouts docs :frowning:

I’ll move forward with patching the erl script for now.


So the use of patching the script to use $SNAP breaks when the snap is used to build other snaps.

I was creating an Elixir snap using the Erlang snap as a build-snap depedency which lead to:

Building elixir
/root/parts/elixir/install/usr/bin/erl: 29: exec: /snap/snapcraft/4007/usr/lib/erlang/erts-10.6.4/bin/erlexec: not found

Which makes sense, in the case of building a snap the $SNAP path is /snap/snapcraft/<revision>.

So I may have to switch to use /snap/erlang/current for now, until a better solution is known.

Is there at least a environment variable that is set for where snap directory is in case it isn’t in the root at /snap?

Also concerned about how this will work with parallel installs?

Oh wait, duh, if I’m going this direction I might as well just make the path by constructing it from the location of the script itself.

So I’m going to try to use the (path to the script)/../lib/erts-10.6.4/bin.