forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiBb0eb8adIvan Molodetskikh3 months ago2857 commits

Example-systemd-Setup.md76 lines, 3.3 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.
5Unlike [`spawn-at-startup`]./Configuration:-Miscellaneous.md#spawn-at-startup, 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. `mako` and `waybar` provide systemd units out of the box, so you can simply add them to the niri session:
9
10 ```
11 systemctl --user add-wants niri.service mako.service
12 systemctl --user add-wants niri.service waybar.service
13 ```
14
15 This will create links in `~/.config/systemd/user/niri.service.wants/`, a special systemd folder for services that need to start together with `niri.service`.
16
173. `swaybg` does not provide a systemd unit, since you need to pass the background image as a command-line argument.
18 So we will make our own.
19 Create `~/.config/systemd/user/swaybg.service` with the following contents:
20
21 ```systemd
22 [Unit]
23 PartOf=graphical-session.target
24 After=graphical-session.target
25 Requisite=graphical-session.target
26
27 [Service]
28 ExecStart=/usr/bin/swaybg -m fill -i "%h/Pictures/LakeSide.png"
29 Restart=on-failure
30 ```
31
32 Replace the image path with the one you want.
33 `%h` is expanded to your home directory.
34
35 After editing `swaybg.service`, run `systemctl --user daemon-reload` so systemd picks up the changes in the file.
36
37 Now, add it to the niri session:
38
39 ```
40 systemctl --user add-wants niri.service swaybg.service
41 ```
42
434. `swayidle` similarly does not provide a service, so we will also make our own.
44 Create `~/.config/systemd/user/swayidle.service` with the following contents:
45
46 ```systemd
47 [Unit]
48 PartOf=graphical-session.target
49 After=graphical-session.target
50 Requisite=graphical-session.target
51
52 [Service]
53 ExecStart=/usr/bin/swayidle -w timeout 601 'niri msg action power-off-monitors' timeout 600 'swaylock -f' before-sleep 'swaylock -f'
54 Restart=on-failure
55 ```
56
57 Then, run `systemctl --user daemon-reload` and add it to the niri session:
58
59 ```
60 systemctl --user add-wants niri.service swayidle.service
61 ```
62
63That's it!
64Now these three utilities will be started together with the niri session and stopped when it exits.
65You can also restart them with a command like `systemctl --user restart waybar.service`, for example after editing their config files.
66
67To remove a service from niri startup, remove its symbolic link from `~/.config/systemd/user/niri.service.wants/`.
68Then, run `systemctl --user daemon-reload`.
69
70### Running Programs Across Logout
71
72When 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:
73
74```
75systemd-run --user --scope tmux new-session
76```