forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiB64a9351Ivan Molodetskikh2 years ago1319 commits

Example-systemd-Setup.md75 lines, 3.4 KiBHistoryRawDownload
1When starting niri from a display manager like GDM, or otherwise through the `niri-session` binary, it runs as a systemd service.
2This provides the necessary systemd integration to run programs like `mako` and services like `xdg-desktop-portal` bound to the graphical session.
3
4Here's an example on how you might set up [`mako`]https://github.com/emersion/mako, [`waybar`]https://github.com/Alexays/Waybar, [`swaybg`]https://github.com/swaywm/swaybg and [`swayidle`]https://github.com/swaywm/swayidle to run as systemd services with niri.
5In contrast to the `spawn-at-startup` config option, this lets you easily monitor their status and output, and restart or reload them.
6
71. Install them, i.e. `sudo dnf install mako waybar swaybg swayidle`
82. Create a `niri.service.wants` folder: `mkdir -p ~/.config/systemd/user/niri.service.wants`
9
10 This is a special systemd folder.
11 Any services linked there will be started together with `niri.service` (which is a systemd unit used by niri when running as a session).
12
133. `mako` and `waybar` provide systemd units out of the box, so you can simply symlink them into the `niri.service.wants` folder:
14
15 ```
16 ln -s /usr/lib/systemd/user/mako.service ~/.config/systemd/user/niri.service.wants/
17 ln -s /usr/lib/systemd/user/waybar.service ~/.config/systemd/user/niri.service.wants/
18 ```
19
204. `swaybg` does not provide a systemd unit, since you need to pass the background image as a command-line argument.
21 So we will make our own.
22 Put the following into `~/.config/systemd/user/swaybg.service`:
23
24 ```
25 [Unit]
26 PartOf=graphical-session.target
27 After=graphical-session.target
28 Requisite=graphical-session.target
29
30 [Service]
31 ExecStart=/usr/bin/swaybg -m fill -i "%h/Pictures/LakeSide.png"
32 Restart=on-failure
33 ```
34
35 Replace the image path with the one you want.
36 `%h` is expanded to your home directory.
37
38 After editing `swaybg.service`, run `systemctl --user daemon-reload` so systemd picks up the changes in the file.
39
40 Now, also symlink this to `niri.service.wants`:
41
42 ```
43 ln -s ~/.config/systemd/user/swaybg.service ~/.config/systemd/user/niri.service.wants/
44 ```
45
465. `swayidle` similarly does not provide a service so we will also make our own. Put the following into `~/.config/systemd/user/swayidle.service`:
47
48 ```
49 [Unit]
50 PartOf=graphical-session.target
51 After=graphical-session.target
52 Requisite=graphical-session.target
53
54 [Service]
55 ExecStart=/usr/bin/swayidle -w timeout 601 'niri msg action power-off-monitors' timeout 600 'swaylock -f' before-sleep 'swaylock -f'
56 Restart=on-failure
57 ```
58
59 Then, run `systemctl --user daemon-reload` and symlink this file to `niri.service.wants`:
60
61 ```
62 ln -s ~/.config/systemd/user/swayidle.service ~/.config/systemd/user/niri.service.wants/
63 ```
64
65That's it!
66Now these three utilities will be started together with the niri session and stopped when it exits.
67You can also restart them with a command like `systemctl --user restart waybar.service`, for example after editing their config files.
68
69### Running Programs Across Logout
70
71When running niri as a session, exiting it (logging out) will kill all programs that you've started within. However, sometimes you want a program, like `tmux`, `dtach` or similar, to persist in this case. To do this, run it in a transient systemd scope:
72
73```
74systemd-run --user --scope tmux new-session
75```