6

dear power users and devolopers,

i am encountering some problems, adjusting to the way snap works. i always embraced all the possibilities that a GNU/Linux distribution offers me. however, i feel that snap packages are keeping these possibilities from me. not deliberatly of course. but... well, i cannot change things that need to be changed.. system configs files and applications config files, environment variables.

my distribution: ubuntu desktop 20.04 amd64

what i would like to do:

install a (snap) program that supports pulseaudio and depending on the value i set for the environment variable PULSE_SERVER, the program starts using a certain pulseaudio server or socket. i want to be able to always choose between using the local instance of pulseaudio or an instance of pulseaudio running on another machine.

i can neither find a way to successfully pass an environment variable to the command, nor to set the environment variables of the snap packages in general. (also i cannot find any real documentation or ways to adjust the snap interfaces "audio-playback","audio-record", and the deprecated "pulseaudio" ... (i just had these interfaces connected to a snap in order to test them and disconnected them afterwards)

so, a program installed with snap seems to be bound to connect to the pulseaudio socket of the host, that is beeing created by pulseaudio with the default configuration (e.g. /run/user/1000/pulse/native if started by user with UID 1000)

please can you help me finding a solution? (preferably a way to successfully set/pass the PULSE_SERVER variable, but other solutions would also be interesting)

thanks in advance

coffeekid
  • 91
  • 3

2 Answers2

1

This is a bit of a hack, but here is how you can pass an env variable to a snap, using chromium as an example:

echo "PULSE_SERVER=$PULSE_SERVER; chromium.launcher" | snap run --shell chromium

It works by taking the $PULSE_SERVER set on your host and piping it into the shell inside the snap, that is then used to kick-off the main process.

AiB
  • 11
  • 2
0

Don't know if it was always like this, but currently (Ubuntu 22.04 in my case) passing custom environment variables to a snap application is the same as to any other application:

#Only to show that it is a snap version of firefox
$ which firefox
/snap/bin/firefox

#Passing a variable
$ MOZ_ENABLE_WAYLAND=1 firefox

In my case I can see that it works with my eyes (firefox no longer blurry on XWayland). But if you need a "scientific" way to check:

$ JUST_A_TEST=hello snap run --shell firefox
#The next comman is inside a snap shell
$ env | grep hello
JUST_A_TEST=hello
#To exit snap shell
$ exit
Yoory N.
  • 101
  • 3