rgwood / systemctl-tui

A fast, simple TUI for interacting with systemd services and their logs
MIT License
235 stars 5 forks source link

NixOS: `--scope global` panics after exactly 5 seconds with user level privileges. #14

Closed siph closed 4 months ago

siph commented 7 months ago

Hi. I maintain systemctl-tui in nixpkgs and I have been having some interesting problems while trying to update to 0.3.1.

First, I'm a bit confused about what flags should be used when running systemctl-tui without elevated privileges and while testing I found that --scope global seems to be the only one that can find the services (shouldn't --scope user work?). In prior versions, systemctl-tui could be ran without any flags or elevated privileges and I just wanted to confirm that this is intentionally no longer the case?

However, this amusing bug is the main reason I opened this: Screenshot_20240130_130552

Running systemctl-tui --scope global will launch properly and show the services, but consistently panics after 5 seconds. I haven't noticed any problems when running as superuser.

I also tried building against the latest revision (00b5fcf63a0241bb4cf8df54f69cb5be3ce2078a) and got the same results.

Thanks!

rgwood commented 7 months ago

Thanks for the bug report! You should definitely be able to run without elevated privileges, no flags needed. By default systemctl-tui tries to load both global+user services (same as --scope all).

Running systemctl-tui --scope global will launch properly and show the services, but consistently panics after 5 seconds.

That's strange - it sounds like systemctl-tui is able to get a list of services from systemd on initial startup, but fails when it's trying to refresh the list of services.

I'm not able to reproduce this unfortunately (it works as expected for me on Ubuntu 23.10 and Debian/Raspbian 11). I wonder if it's a Nix issue... can you reproduce the issue with any of the following?

  1. The published release binaries
  2. Plain old cargo run outside of a Nix setup?
rgwood commented 7 months ago

Also, what version+distro of Linux are you running?

siph commented 7 months ago

I'm on NixOS. I did some testing yesterday before I ran out of time and It definitely seems to be a NixOS problem (not nix). Something to do with how NixOS handles user-systemd units? I didn't bisect but this is the almost certainly where it happened (https://github.com/rgwood/systemctl-tui/commit/7c92092a5d8c4357f1cb9a131ca149af073ef2cf).

To be clear this used to work like expected and the current version in nixpkgs (0.2.4) works with NixOS. 0.3.1 does partially work, just not without elevated privileges.

NixOS

Caused by: org.freedesktop.DBus.Error.Spawn.ChildExited: Process org.freedesktop.systemd1 exited with status 1


- `cargo run` on Ubuntu:latest (same machine with distrobox):
```bash
Error: Unable to get services. Check that systemd is running and try running this tool with sudo.

Caused by:
    0: I/O error: No such file or directory (os error 2)
    1: No such file or directory (os error 2)

Ubuntu

I didn't test any pre-built binaries because it's kind of tedious on NixOS and the cargo-built binaries returned the same errors so I assume it isn't build-time related.

Thanks, again!

rgwood commented 7 months ago

Appreciate the extra detail.

I don't have a NixOS machine/VM right now and probably won't anytime soon, so if someone else has the motivation to figure this out (or just more info on how NixOS handles user services) I'd appreciate it.

As a quick+dirty fix, I suppose I could make it so that a failure to retrieve user services logs an error without panicking. Just feels a little icky because that's something that should never happen and I don't want to mask such a major error on non-NixOS systems. Hmm!

siph commented 7 months ago

I agree. I'm sure there's a reasonable fix. I'm not an expert but I'm happy to take a deeper look when I have some time or when I'm trying to procrastinate.

siph commented 4 months ago

I haven't had a chance to look at this but was testing 0.3.5 and --scope global seems to work without crashing. user and all are still failing on my main machine:

Error: Unable to get services. Check that systemd is running and try running this tool with sudo.

Caused by:
    org.freedesktop.DBus.Error.Spawn.ChildExited: Process org.freedesktop.systemd1 exited with status 1

However, I failed to reproduce any of these errors on a different NixOS machine. All scopes worked with user permissions.

My best guess is that something is wrong on my end and because I got perfect functionality from systemctl-tui on a NixOS machine I will go ahead and close this.

Thanks!