@@ -5,41 +5,41 @@ modules for managing the Polykey Agent using `systemd`. These modules were
55introduced as part of a broader effort to improve automation, reliability, and
66user experience across both user-level and system-wide contexts.
77
8- ---
9-
108## Background
119
1210The Polykey Agent is a long-lived background process that facilitates secure
1311secret management and distributed key infrastructure. Traditionally, users had
1412to manually start the agent from the terminal. To streamline this, two modules
1513were introduced:
1614
17- - ` programs ` : Configures ** user-level services** for personal development and
15+ - ** programs: ** Configures user-level services for personal development and
1816 desktop use.
19- - ` services ` : Configures ** system-level services** for shared machines and
20- server environments.
17+ - ** services: ** Configures system-level services for shared machines and server
18+ environments.
2119
2220These modules utilize ` systemd ` , a service manager used in most Linux
2321distributions.
22+ git st
23+ :::note Note
24+ On NixOS, Polykey is not configured through .service files, but
25+ instead through the Home Manager or Nix configuration. See the NixOS integration
26+ section below.
27+ :::
2428
25- ---
26-
27- ## What is ` systemd ` ?
29+ ## What is systemd?
2830
29- ` systemd ` is the default init and service manager in most Linux distros. It
30- allows you to:
31+ systemd is the default init and service manager in most Linux distros. It allows
32+ you to:
3133
3234- Start, stop, and restart background services.
3335- Automatically launch services at boot or login.
3436- View logs and monitor service health.
3537
3638` systemd ` uses unit files (like ` .service ` ) to define how services behave.
3739
38- ---
39-
40- ## Key Concepts
40+ ### Key Concepts
4141
42- ### User vs System Services
42+ ** User vs System Services**
4343
4444| Mode | Controlled By | Suitable For | Config Path |
4545| ---------- | ------------- | ------------------------------- | ------------------------- |
@@ -48,75 +48,69 @@ allows you to:
4848
4949The new modules are designed to target both these contexts.
5050
51- ---
52-
53- ## Programs Module (User Services)
51+ #### Programs Module (User Services)
5452
5553The ` programs ` module sets up a user-level ` systemd ` service that:
5654
5755- Starts the agent on login.
5856- Runs the agent under the current user.
59- - Stores logs in the user' s journal.
57+ - Stores logs in the user’ s journal.
6058
6159### Setup Instructions (User Mode)
6260
63611 . Ensure the Polykey binary is installed and accessible via ` $PATH ` .
64622 . Copy the service file to:
6563
66- ``` sh
67- mkdir -p ~ /.config/systemd/user
68- cp polykey-agent.service ~ /.config/systemd/user/
69- ```
64+ ``` sh
65+ mkdir -p ~ /.config/systemd/user
66+ cp polykey-agent.service ~ /.config/systemd/user/
67+ ```
7068
71693 . Enable and start the service:
7270
73- ``` sh
74- systemctl --user daemon-reload
75- systemctl --user enable polykey-agent
76- systemctl --user start polykey-agent
77- ```
78-
79- 4 . Verify it's running:
71+ ``` shell
72+ systemctl --user daemon-reload
73+ systemctl --user enable polykey-agent
74+ systemctl --user start polykey-agent
75+ ```
8076
81- ``` sh
82- systemctl --user status polykey-agent
83- journalctl --user -u polykey-agent
84- ```
77+ 4 . Verify it’s running:
8578
86- ---
79+ ``` shell
80+ systemctl --user status polykey-agent
81+ journalctl --user -u polykey-agent
82+ ```
8783
88- ## Services Module (System Services)
84+ #### Services Module (System Services)
8985
90- The ` services ` module sets up a root-owned service that:
86+ The services module sets up a root-owned service that:
9187
9288- Runs globally for all users.
9389- Is launched at boot.
9490- Is managed from ` /etc/systemd/system/ ` .
9591
96- ### Setup Instructions (System Mode)
92+ ##### Setup Instructions (System Mode)
9793
98941 . Copy the service file to:
9995
100- ``` sh
101- sudo cp polykey-agent.service /etc/systemd/system/
102- ```
96+ ``` shell
97+ sudo cp polykey-agent.service /etc/systemd/system/
98+ ```
10399
1041002 . Enable and start the service:
105101
106- ``` sh
107- sudo systemctl daemon-reload
108- sudo systemctl enable polykey-agent
109- sudo systemctl start polykey-agent
110- ```
102+ ``` shell
103+ sudo systemctl daemon-reload
104+ sudo systemctl enable polykey-agent
105+ sudo systemctl start polykey-agent
106+ ```
111107
1121083 . Check status:
113109
114- ``` sh
115- sudo systemctl status polykey-agent
116- sudo journalctl -u polykey-agent
117- ```
118-
119- ---
110+ ``` shell
111+ sudo systemctl status polykey-agent
112+ sudo journalctl -u polykey-agent
113+ ```
120114
121115## Configuration Details
122116
@@ -128,66 +122,69 @@ The service files can be customized:
128122
129123To override a system service without editing the base file:
130124
131- ``` sh
125+ ``` shell
132126sudo systemctl edit polykey-agent
133127```
134128
135- ---
129+ ** Note for NixOS users:** These overrides are not applicable. See the next
130+ section.
136131
137- ## Handling Secrets & Recovery Codes
132+ ### Handling Secrets & Recovery Codes
138133
139134The new modules support secure handling of recovery codes and agent secrets:
140135
141136- Set environment variables or use configuration files in the home directory.
142137- Avoid running agents as root unless necessary.
143138- For system mode, ensure secrets are stored in restricted root-only paths.
144139
145- ---
140+ #### Troubleshooting
146141
147- ## Troubleshooting
142+ - ** “Service not found”: **
148143
149- - ** "Service not found" ** :
144+ * Run ` daemon-reload ` after copying or editing unit files. (Not needed in NixOS)
150145
151- - Run ` daemon-reload ` after copying or editing unit files.
146+ - ** “Permission denied”: **
152147
153- - ** "Permission denied" ** :
148+ * Ensure system-level services are started with ` sudo ` .
154149
155- - Ensure system-level services are started with ` sudo ` .
150+ - ** Service not starting: **
156151
157- - ** Service not starting ** :
152+ * Run ` journalctl -u polykey-agent ` for logs.
158153
159- - Run ` journalctl -u polykey-agent ` for logs.
154+ - ** User services not auto-starting: **
160155
161- - ** User services not auto-starting ** :
156+ * Check that ` linger ` is enabled for the user :
162157
163- - Check that ` linger ` is enabled for the user:
164-
165- ``` sh
166- sudo loginctl enable-linger $USER
167- ```
168-
169- ---
158+ ``` shell
159+ sudo loginctl enable-linger $USER
160+ ```
170161
171- # # Use Cases
162+ ### NixOS Integration
172163
173- - ** Developers** : Enable ` programs` to automatically start the agent at login.
174- - ** Sysadmins** : Deploy ` services` module for always-on availability of the
175- agent across all users.
176- - ** Security-sensitive installations** : Customize environment securely and
177- inspect logs via ` journalctl` .
164+ On NixOS, service setup is handled via Home Manager or system configuration, not
165+ .service files. Here’s a basic example of configuring Polykey in home.nix:
178166
179- ---
167+ ``` nix
168+ polykey = rec {
169+ enable = true;
170+ passwordFilePath = "/home/user/.polykeypass";
171+ recoveryCodeOutPath = "/home/user/.polykeyrecovery";
172+ };
173+ ```
180174
181- # # Next Steps
175+ - enable will activate the service.
176+ - passwordFilePath provides the path to read the vault password.
177+ - recoveryCodeOutPath sets the location to write recovery codes.
182178
183- - Finalize documentation with visual diagrams (systemd flow, unit layering).
184- - Incorporate examples of overriding default behavior.
185- - Validate this guide on different distros (e.g. Ubuntu, Fedora, Arch).
179+ ** More references:**
186180
187- ---
181+ - Polykey Nixpkg (private)
182+ - Home Manager Infra Docs
188183
189- # # Related References
184+ ** Use Cases **
190185
191- - [systemd documentation](https://www.freedesktop.org/wiki/Software/systemd/)
192- - [Polykey PR # 138](https://github.com/MatrixAI/Polykey-CLI/pull/138)
193- - [CLI Installation Guide](./installation.md)
186+ - Developers: Enable ` programs ` to automatically start the agent at login.
187+ - Sysadmins: Deploy ` services ` module for always-on availability of the agent
188+ across all users.
189+ - Security-sensitive installations: Customize environment securely and inspect
190+ logs via ` journalctl ` .
0 commit comments