Skip to content

dbus and systemd activation - take 2#7679

Merged
mitchellh merged 12 commits intoghostty-org:mainfrom
jcollie:dbus-and-systemd-2
Jun 26, 2025
Merged

dbus and systemd activation - take 2#7679
mitchellh merged 12 commits intoghostty-org:mainfrom
jcollie:dbus-and-systemd-2

Conversation

@jcollie
Copy link
Copy Markdown
Member

@jcollie jcollie commented Jun 25, 2025

This replaces #7433. The improvements are:

  1. Install the systemd user service in the proper directory depending on if it's a 'user' install or a 'system' install. This is controlled either by using the --system build flag (as most packages will) or by the -Dsystem-package flag.

  2. Add the absolute path to the ghostty binary in the application file, the DBus service, and the systemd user service. This is done so that they do not depend on ghostty being in the PATH of whatever is launching Ghostty. That PATH is not necessarily the same as the PATH in a user shell (especially for DBus activation and systemd user services).

  3. Adjust the DBus bus name that is expected by the system depending on the optimization level that Ghostty is compiled with.

@jcollie jcollie requested a review from a team as a code owner June 25, 2025 04:05
@jcollie
Copy link
Copy Markdown
Member Author

jcollie commented Jun 25, 2025

@alaviss this will probably affect the flatpak

Copy link
Copy Markdown
Contributor

@alaviss alaviss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few notes. This looks good from Flatpak perspective to me.

Comment thread dist/linux/app.desktop Outdated
Comment thread src/build/GhosttyResources.zig Outdated
Copy link
Copy Markdown
Member

@tristan957 tristan957 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced that using the full path is right.

I decided to check out my system to look for precedent:

$ rg -F -I -N --no-heading Exec= /usr/share/applications/ | grep -E 'Exec="?/' | wc -l
44

$ rg -F -I -N --no-heading Exec= /usr/share/applications/  | wc -l
166

~25% use the full path. I'm not as knowledgeable as you in this area, so will defer.

Comment thread src/build/GhosttyResources.zig Outdated
Comment thread dist/linux/app.desktop Outdated
Copy link
Copy Markdown
Contributor

@mitchellh mitchellh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall fine, there's a couple details I'm not super happy with. Happy to dig in myself but I won't be able to get back to this for probably... a day or two.

Comment thread dist/linux/app.desktop Outdated
Comment thread src/build/Config.zig Outdated
Comment thread src/build/GhosttyResources.zig Outdated
@mitchellh
Copy link
Copy Markdown
Contributor

mitchellh commented Jun 25, 2025

I'm not convinced that using the full path is right.

I didn't do a full research on this yesterday to know the right answer, but I did find this which notes that systemd units don't do PATH lookup unless its specified in Environment (or a few other keys). I also found a stack overflow that says that systemd has a default PATH set to things like /usr/bin but it's limited.

https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html

If we can remove the absolute path later I'll take it. For now I think this gets things working, but haven't verified yet.

jcollie and others added 10 commits June 26, 2025 10:28
This replaces ghostty-org#7433. The improvements are:

1) Install the systemd user service in the proper directory depending
on if it's a 'user' install or a 'system' install. This is controlled
either by using the `--system` build flag (as most packages will) or by
the `-Dsystem-package` flag.

2) Add the absolute path to the `ghostty` binary in the application
file, the DBus service, and the systemd user service. This is done so
that they do not depend on `ghostty` being in the `PATH` of whatever
is launching Ghostty. That `PATH` is not necessarily the same as the
`PATH` in a user shell (especially for DBus activation and systemd user
services).

3) Adjust the DBus bus name that is expected by the system depending on
the optimization level that Ghostty is compiled with.
Replaces ghostty-org#7676

When building as a flatpak, don't install the systemd user services
since flatpaks can't use them. Remove references to the systemd service
from the DBus service.

Also, customize the app metadata depending on the debug mode.

Co-authored-by: Leorize <leorize+oss@disroot.org>
@mitchellh mitchellh force-pushed the dbus-and-systemd-2 branch from 5fc9978 to 739b691 Compare June 26, 2025 17:28
@mitchellh
Copy link
Copy Markdown
Contributor

Okay I redid the templating part to use cmake format which lets us take advantage of b.addConfigHeader to produce our files without having to have a custom binary. A bit of a hack, but cmake formatting isn't going away anytime soon so this is pretty safe to do and I'd rather lean on Zig stdlib.

@mitchellh
Copy link
Copy Markdown
Contributor

Oh crap, Zig puts a header at the top that it was generated by the build system and it breaks everything. LOL.

@mitchellh
Copy link
Copy Markdown
Contributor

Okay may have to bring back our dedicated binary (rip). But I want to do it in the style of the other refactors I made so let me come back to this this afternoon. Ball is in my court.

@tristan957
Copy link
Copy Markdown
Member

Okay I redid the templating part to use cmake format which lets us take advantage of b.addConfigHeader to produce our files without having to have a custom binary. A bit of a hack, but cmake formatting isn't going away anytime soon so this is pretty safe to do and I'd rather lean on Zig stdlib.

Let no good idea go unpunished! :'(

@mitchellh
Copy link
Copy Markdown
Contributor

Okay I kept the config header usage and just use tail to strip the first line. The usage of tail here is POSIX-standard only so this should work fine on BSD and Linux systems. It's something we can/should replace eventually but for all our target environments and platforms its pretty safe.

@mitchellh mitchellh enabled auto-merge June 26, 2025 20:15
@mitchellh mitchellh merged commit c12b280 into ghostty-org:main Jun 26, 2025
36 of 38 checks passed
@github-actions github-actions Bot added this to the 1.2.0 milestone Jun 26, 2025
@mitchellh
Copy link
Copy Markdown
Contributor

Did auto-merge merge with failing tests? Computers aren't on my side with this one. Following up now.

@jcollie jcollie deleted the dbus-and-systemd-2 branch June 27, 2025 13:06
jcollie added a commit to jcollie/ghostty that referenced this pull request Jul 1, 2025
The addition of D-Bus activation and systemd user services in ghostty-org#7679
has made the "default" launching of Ghostty a little more complicated.
This PR attempts to document that process works and commands for
managing/controlling that process.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants