Launch Flatpak Apps With Custom Args and Environment Variables

Launch Flatpak Apps With Custom Args and Environment Variables

In this guide you will learn how to launch flatpak applications with custom arguments and environment variables.

Find your application

First, you need to find the application id of the app you want. To do that run the command below in the terminal.

$ flatpak list

screenshot of flatpak install command output

Find the Application ID and save it somewhere, it's going to be important later on.

If you want to test the env variables or arguments you can use the temporary solution below. Otherwise, use the permanent solution.

Temporary solution

Run the command below in a terminal. Make sure replace Application ID with the id you saved in the earlier section and remove the brackets <>.

Note: Angled brackets <> in command references means that the argument is mandatory, while square brackets [] means that the argument is optional. you will see this a lot in manual pages (man command).

$ flatpak run [--env=VARIABLE=VALUE] <Application ID> [--custom-argument-here]

Example

Recently I had a problem with Discord lagging when mouse hovered over the server list. On my system discord is installed as a flatpak. I solved this issue by adding--enable-gpu-rasterization argument as below

$ flatpak run --command discord com.discordapp.Discord --enable-gpu-rasterization

discord needs the --command flag. Your app probably doesn't need it but if you have any problems you can reach out to me in the comments.

However, this is a one-off solution. To make it permanent follow the section below.

Permanent solution

If you only want to add some custom env variables there is an easy method. We use the override command of flatpak for it. This method doesn't work for custom arguments (See issue #2913 on flatpak repo) so if you want to add custom arguments please follow create custom desktop entry section.

Create override

$ flatpak override --user < --env=VARIABLE_NAME=VARIABLE_VALUE > <Application ID>

This will make your env variable permanent.

Note: you can remove the --user flag if you want the override to be applied system-wide. I only wanted it applied for my user so I'm using the flag here.

To make custom arguments permanent we just have to get a little more involved.

Create custom desktop entry

By default installed flatpak application with desktop entries export their .desktop files in ~/.local/share/flatpak/exports/share/applications. What do these .desktop files do? Well, these files contain information about the application's desktop icon, what kind of a program it is and the command used to launch the app. Which is just what we need.

We will first copy this desktop file so that the original file is intact

$ cp ~/.local/share/flatpak/exports/share/applications/<Application id>.desktop \
    ~/.local/share/applications

After this open the <Application ID>.desktop file at ~/.local/share/applications in your editor.

Example

screenshot of my desktop file example

Some lines in your file might be different.

As you can already see in my edited file, we are going to directly modify the flatpak run command in the Exec field. This is similar to what we did in the [temporary solution](#heading-temporary solution) but this time it will run every time the app is launched.

You just need to modify the Exec field. Here is a reference, you can also use the screenshot above.

Exec=/usr/bin/flatpak run [--env=VARIABLE=VALUE] com.discordapp.Discord [--custom-argument]

References

That's it for now! Please reach out if you face any issues. If this helped you please consider supporting me. Thank you!

Did you find this article valuable?

Support Arda Sevinç by becoming a sponsor. Any amount is appreciated!