DEV Community

Ashen Chathuranga
Ashen Chathuranga

Posted on

Making Raspberry Pi Imager from AUR Work on Hyprland + Wofi

Raspberry Pi Imager is the official tool for writing Raspberry Pi OS images (and other images) to SD cards or USB drives. While it works smoothly on traditional desktop environments, running it on Hyprland — a Wayland compositor — can be tricky, especially if installed via the AUR. Here’s a deep dive into the issue and how to fix it.


The Problem

On Arch Linux, you have two main ways to install Raspberry Pi Imager:

  1. Pacman (official repo): sudo pacman -S rpi-imager
  2. AUR (latest version): yay -S rpi-imager-latest

When using the AUR version:

  • Launching the app from wofi shows no response — the GUI doesn’t open.
  • Running from terminal works only with sudo -E rpi-imager.

Meanwhile, the Pacman version works normally from the menu.


Why This Happens

  1. Root Privileges Needed
  • Raspberry Pi Imager requires access to devices (SD cards/USB drives), which normal users cannot access.
  • Therefore, it must run as root, usually via pkexec or sudo.
  1. Wayland Environment
  • On Hyprland (Wayland), pkexec often fails silently if the environment variables (DISPLAY, WAYLAND_DISPLAY, XAUTHORITY) aren’t set properly.
  • The desktop file provided by the AUR package typically uses:
   Exec=pkexec --disable-internal-agent /usr/bin/rpi-imager %u
Enter fullscreen mode Exit fullscreen mode
  • On Wayland, this does not carry over the environment, so the GUI never appears.
  1. Desktop File Difference
  • The Pacman version (/usr/share/applications/org.raspberrypi.rpi-imager.desktop) works because its environment and paths are standard.
  • The AUR version may install to a slightly different path or not account for Wayland, causing the menu launcher to fail.

The Solution

The fix involves creating a wrapper script that preserves the Wayland environment and modifying the desktop file to use it.


Step 1: Create a Wayland-safe Wrapper

Create a new script at /usr/local/bin/rpi-imager-launch:

sudo nano /usr/local/bin/rpi-imager-launch
Enter fullscreen mode Exit fullscreen mode

Paste the following:

#!/bin/bash
# Wayland-safe wrapper for Raspberry Pi Imager

export DISPLAY=$DISPLAY
export WAYLAND_DISPLAY=$WAYLAND_DISPLAY
export XAUTHORITY=$XAUTHORITY

# Launch Raspberry Pi Imager with pkexec
pkexec env DISPLAY=$DISPLAY WAYLAND_DISPLAY=$WAYLAND_DISPLAY XAUTHORITY=$XAUTHORITY /usr/bin/rpi-imager
Enter fullscreen mode Exit fullscreen mode

Make it executable:

sudo chmod +x /usr/local/bin/rpi-imager-launch
Enter fullscreen mode Exit fullscreen mode

Step 2: Modify the Desktop File

Edit the AUR-installed desktop file (likely /usr/share/applications/com.raspberrypi.rpi-imager.desktop):

sudo nano /usr/share/applications/com.raspberrypi.rpi-imager.desktop
Enter fullscreen mode Exit fullscreen mode

Change the Exec line to:

Exec=/usr/local/bin/rpi-imager-launch %u
Enter fullscreen mode Exit fullscreen mode

This ensures that when you click the app in wofi, the wrapper script runs, preserving the environment variables necessary for Wayland.


Step 3: Refresh the Menu

If necessary, refresh your desktop database:

update-desktop-database
Enter fullscreen mode Exit fullscreen mode

Now, launching Raspberry Pi Imager from wofi works as expected — it will prompt for your password via GUI and open the application.


Why This Works

  • The wrapper ensures DISPLAY, WAYLAND_DISPLAY, and XAUTHORITY are correctly passed to pkexec, which is required on Wayland.
  • Modifying the desktop file allows the menu launcher to call the wrapper instead of the original binary directly.
  • This approach works for any root-required GUI application on Wayland that fails to launch from a menu.

Optional Enhancements

  • Passwordless Launch: You can configure sudoers to allow your user to run /usr/bin/rpi-imager without a password. This makes one-click launching possible but slightly reduces security.
  • Icon Customization: If the AUR version lacks an icon, you can download a PNG and set Icon=/path/to/icon.png in the desktop file.

Conclusion

Running AUR-installed Raspberry Pi Imager on Hyprland can fail silently due to Wayland environment issues with pkexec. The solution is simple:

  1. Create a wrapper script that preserves environment variables.
  2. Edit the desktop file to point to the wrapper.

This ensures wofi or any other menu launcher can start the app reliably, bridging the gap between Arch’s flexibility, Wayland, and applications requiring root access.

Top comments (0)