soumya92/barista

User units for the systemd module

qaristote opened this issue · 8 comments

I'm using barista along with home-manager. home-manager is basically a way to have your home/ directory be generated from configurations files. In particular, you can do things such as programs.emacs = enable and home-manager automatically creates a systemd unit for the Emacs server.

But if i want to access this unit inside barista through the systemd module, I get an error saying the unit is unknown. This is because the unit generated by home-manager is not listed by systemctl list-units, but instead by systemctl --user list-units. I don't know much about systemd but I assume this is because home-manager creates user-specific unit-files but the systemd module in barista can only access root unit-files.

Is there a way to access the units listed only by systemctl --user list-units using barista's systemd module ? If not, could it be extended so that this becomes possible ?

Thanks !

This seems feasible. Right now it connects only to the system dbus, but I expect it should be possible to extend it to support connecting to the current user's dbus as well.

If you want to try making that work go for it, otherwise I might get to it at a less busy time

Hi there! From what I understand, changing the dbusType to session dbus could potentially fix the problem. Including an option to specify the dbusType when creating the module could be a viable solution. Is that correct?

That was my expectation, so I think the PR's general logic is sound. Thanks for attempting this!

As #374 got merged i've decided to give them a try ...

@KarolosLykos (or @soumya92 ) may i ask what OS are you running and how does the systemd.service file has looked during the development?
I'm on ubuntu 22.04 and i tried using a systemd user-config.

I've already have something to see if the docker systemd unit is running fine. This works without any issues
but for some reasons, if i use the same for a UserService i only get the "status" on a first run.
Toggle the user service on/off works fine but i don't get the state updated.

	greenclip := systemd.UserService("greenclip").
		Output(func(si systemd.ServiceInfo) bar.Output {

			out := outputs.Group()
			out.OnClick(click.Left(func() {
				si.Stop()
			}))
			if si.State == systemd.StateActive {
				out.Append(
					outputs.Pango(
						pango.Icon("mdi-clipboard").Color(colors.Hex("#34eb55")),
					))
			} else {
				out.Append(
					outputs.Pango(
						pango.Icon("mdi-clipboard-off").Color(colors.Hex("#eb4034")),
					))
			}

			return out
		})

and the systemd user file (/home/mario/.config/systemd/user/greenclip.service) looks like:

[Unit]
Description=Recycle your clipboard selections with greenclip and don't waste your time anymore to reselect things over and over.

[Service]
ExecStart=/home/mario/bin/greenclip daemon

[Install]
WantedBy=default.target

I don't actually have any user units, so I can't test this. Based on your description my first guess would be that the watcher is actually still watching system bus, so that would be the place to start. If you want to explore go for it, otherwise I'll try to look at this when I have time.

@bavarianbidi I haven't had extensive experience with the greenclip.service, so I installed it and conducted some debugging. During this process, I observed that there is no event being emitted to the dbus. Additionally, I verified that the watcher is indeed monitoring the session dbus. However, I want to clarify that my knowledge of dbus is somewhat limited, so please take my observations with a grain of salt. I'm using Arch Linux btw with i3wm, and there seem to be some related issues (https://github.com/erebe/greenclip/issues/70) based on my understanding.

This works for me, thanks for implementing this @KarolosLykos ! I do have some dbus watcher problems but for system services as well so I'll open another issue.

I'm having the same issue as #294 (comment) with the emacs server service.