Handle flatpak from Salt

Original forum link
https://forum.qubes-os.org/t/30157
Original poster
Solène R
Created at
2024-11-13 07:00:17
Last wiki edit
2024-11-16 09:12:25
Revisions
1 revision
Posts count
20
Likes count
9

Introduction

Manage flatpak from salt. This guide requires to have some Salt knowledge.

A few months ago, I had most of my setup managed by salt, but then I got lazy and with the introduction of flatpak I didn't even look at using salt to handle it. Here is a simple method that "just" works, which:

Setup (Fedora)

In a Salt state file, add this:

{% set flatpak_packages = [
    "org.libreoffice.Libreoffice",
    "org.mozilla.firefox",
    "org.videolan.VLC"
] %}

flatpak_setup:
  cmd.script:
    - source: salt://scripts/flatpak-setup.sh
    - template: jinja
    - context:
        flatpak_packages: {{ ' '.join(flatpak_packages) }}


/etc/qubes/post-install.d/05-flatpak-update.sh:
  file.managed:
    - user: root
    - group: wheel
    - mode: 555
    - contents: |
        #!/bin/sh
        if [ $(qubesdb-read /type) = "TemplateVM" ]
        then
          all_proxy=http://127.0.0.1:8082 flatpak upgrade -y --noninteractive
        fi

And in /srv/user_salt/scripts/flatpak-setup.sh:

#!/bin/sh
export all_proxy=http://127.0.0.1:8082/

flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo

# list programs that should be installed
flatpak install -y --noninteractive flathub {{ flatpak_packages }}

# make flatpak programs available in menus
find /var/lib/flatpak/exports/share/applications/ -type l -name "*.desktop" -exec ln -s {} /usr/share/applications/ \;

# delete dead links, in case a flatpak program was deleted
find /usr/share/applications/ -xtype l -delete

/etc/qubes/post-install.d/10-qubes-core-agent-appmenus.sh