Although there is an offical way to start Hyprland using systemd, it does so by relying on the Universal Wayland Session Manager (UWSM). This may work for many people, but I couldn’t get it to start Hyprland in my own bootc image, so I had to look for alternatives.

At first, I just put a simple script into the drop-in directory of the profile in /etc/profile.d folder:

if [[ $(ps aux | grep hyprland | wc -l) -eq 1 ]]; then \
    cd $HOME && \
    echo "launch hyprland?" && \
    read && \
    systemd-run --user --service-type=exec --unit=hyprland --description="hyprland start service" hyprland; \
fi

This meant that I simply had to log into the TTY and then just confirm the read to automatically start Hyprland.

The solution worked well and since I don’t mind the TTY, there weren’t any problems.

After a while I decided that although the script worked fine I would very much like to replace it with something else, ideally starting Hyprland using systemd since I’d be getting logging, security and resource control for free then.

Since you are not supposed to start Hyprland as root, it only really makes sense to start the service as the individual user.

Now I could have just dropped in a unit file into ~/.config/systemd/user/ and called it a day, but I wanted to fix it for every other potential user of the bootc image too, so I had to figure out how to configure the service following the official systemd rules.

First, the directory. I chose /usr/lib/systemd/user/hyprland.service since it’s part of the read only part of the bootc image, so that the service is adequately protected.

A second issue was working out how to automatically start the service once a user logs in. I couldn’t quite find anything about how to do that at first, but following a trail of other mentions I took a look at the active targets using systemctl list-units --user --type target, which lead me to discover the default.target (although now that I search for it specifically, there appears to be documentation on the arch linux wiki and in the systemd man pages.

Knowing all this, I was able to successfully compose a systemd service to autostart Hyprland after logging in:

[Unit]
Description=Start Hyprland as User

[Service]
Type=exec
ExecStartPre=/usr/bin/hyprland --verify-config
ExecStart=/usr/bin/hyprland

[Install]
WantedBy=default.target

Now I can also start locking things down, slowly eroding away at the permissions it has until systemd-analyze security --user hyprland.service is happy (the above config scores 9.8!).