Skip to content

Instantly share code, notes, and snippets.

@filips123
Forked from JJRcop/firefoxpwa-runtime-overlayfs.service
Last active May 26, 2024 08:18
Show Gist options
  • Save filips123/29fb511a01ee8016a927a614f32979d3 to your computer and use it in GitHub Desktop.
Save filips123/29fb511a01ee8016a927a614f32979d3 to your computer and use it in GitHub Desktop.
Systemd service to use PWAsForFirefox with OverlayFS for runtime

Using PWAsForFirefox with FUSE OverlayFS

This document describes how to use FUSE OverlayFS to link your global Firefox installation with the PWAsForFirefox runtime.

Systemd OS

Prerequisites

  • Your OS uses systemd.
  • Firefox is installed (without Snap or Flatpak).
  • fuse-overlayfs is installed (instructions below).

Debian/Ubuntu

sudo apt-get install fuse-overlayfs

Arch/Manjaro

sudo pacman -S fuse-overlayfs

Fedora

sudo dnf -y install fuse-overlayfs

CentOS

sudo yum -y install fuse-overlayfs

openSUSE

sudo zypper install fuse-overlayfs

Installation

  1. Copy the provided firefoxpwa-runtime-overlayfs.service to $HOME/.config/systemd/user.

    With CURL:

    mkdir -p $HOME/.config/systemd/user
    curl https://gist.githubusercontent.com/filips123/29fb511a01ee8016a927a614f32979d3/raw/0987fde6dd9b15283014f22a3d9b3f90a36431fc/firefoxpwa-runtime-overlayfs.service -o $HOME/.config/systemd/user/firefoxpwa-runtime-overlayfs.service

    With Wget:

    mkdir -p $HOME/.config/systemd/user
    wget https://gist.githubusercontent.com/filips123/29fb511a01ee8016a927a614f32979d3/raw/0987fde6dd9b15283014f22a3d9b3f90a36431fc/firefoxpwa-runtime-overlayfs.service -O $HOME/.config/systemd/user/firefoxpwa-runtime-overlayfs.service
  2. Modify AssertPathIsDirectory= and lowerdir= paths to point to your normal Firefox runtime. This is commonly /usr/lib/firefox:

    export FIREFOX_RUNTIME=/usr/lib/firefox
    sed -i -e "s|%RUNTIME-PATH%|$FIREFOX_RUNTIME|" $HOME/.config/systemd/user/firefoxpwa-runtime-overlayfs.service
  3. Create an empty runtime directory:

    mkdir -p $HOME/.local/share/firefoxpwa/runtime
  4. Install and enable the service:

    systemctl --user enable --now firefoxpwa-runtime-overlayfs.service
  5. Check that the runtime overlay was installed correctly.

  6. Enable "Always patch runtime and profile" in the extension settings.

Non-systemd OS

You can make an equivalent script which runs when you log in (a form that is run as the logged in user is preferred). This section will try to be POSIX-compliant to help the most people.

When preparing the script, make sure to:

  1. Create an empty runtime directory:

    mkdir -p $HOME/.local/share/firefoxpwa/runtime
  2. Enable "Always patch runtime and profile" in the extension settings.

When logging in, your script should:

  1. Create upper/ and work/ directories under $XDG_RUNTIME_DIR/firefoxpwa/overlayfs. $XDG_RUNTIME_DIR may be substituted for any tmpfs, ramdisk, or equivalent ephemeral directory if /run/user/$(id -u) is not used by your OS.
  2. Run fuse-overlayfs -f -o squash_to_uid=$(id -u),squash_to_gid=$(id -g),lowerdir=%RUNTIME-PATH%,upperdir=$XDG_RUNTIME_DIR/firefoxpwa/overlayfs/upper,workdir=$XDG_RUNTIME_DIR/firefoxpwa/overlayfs/work $HOME/.local/share/firefoxpwa/runtime, replacing %RUNTIME-PATH% with the path to your normal Firefox runtime.

When logging out, your script should:

  1. Run fusermount -u $HOME/.local/share/firefoxpwa/runtime to unmount the runtime overlayfs.
  2. Destroy the upper/ and work/ directories, or leave them if your OS destroys them for you.

Go back to the documentation website.

[Unit]
Description=Service to use PWAsForFirefox with OverlayFS for runtime
AssertPathIsDirectory=%RUNTIME-PATH%
[Service]
Type=simple
ExecStart=fuse-overlayfs -f -o squash_to_uid=%U,squash_to_gid=%G,lowerdir=%RUNTIME-PATH%,upperdir=%t/firefoxpwa/overlayfs/upper,workdir=%t/firefoxpwa/overlayfs/work %h/.local/share/firefoxpwa/runtime/
ExecStop=fusermount -u %h/.local/share/firefoxpwa/runtime/
RuntimeDirectory=firefoxpwa/overlayfs firefoxpwa/overlayfs/upper firefoxpwa/overlayfs/work
[Install]
WantedBy=default.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment