···
1
+
{ config, lib, pkgs, ... }:
4
+
cfg = config.services.openvscode-server;
5
+
defaultUser = "openvscode-server";
6
+
defaultGroup = defaultUser;
9
+
services.openvscode-server = {
10
+
enable = lib.mkEnableOption (lib.mdDoc "openvscode-server");
12
+
package = lib.mkPackageOptionMD pkgs "openvscode-server" { };
14
+
extraPackages = lib.mkOption {
16
+
description = lib.mdDoc ''
17
+
Additional packages to add to the openvscode-server {env}`PATH`.
19
+
example = lib.literalExpression "[ pkgs.go ]";
20
+
type = lib.types.listOf lib.types.package;
23
+
extraEnvironment = lib.mkOption {
24
+
type = lib.types.attrsOf lib.types.str;
25
+
description = lib.mdDoc ''
26
+
Additional environment variables to pass to openvscode-server.
29
+
example = { PKG_CONFIG_PATH = "/run/current-system/sw/lib/pkgconfig"; };
32
+
extraArguments = lib.mkOption {
34
+
description = lib.mdDoc ''
35
+
Additional arguments to pass to openvscode-server.
37
+
example = lib.literalExpression ''[ "--log=info" ]'';
38
+
type = lib.types.listOf lib.types.str;
41
+
host = lib.mkOption {
42
+
default = "localhost";
43
+
description = lib.mdDoc ''
44
+
The host name or IP address the server should listen to.
46
+
type = lib.types.str;
49
+
port = lib.mkOption {
51
+
description = lib.mdDoc ''
52
+
The port the server should listen to. If 0 is passed a random free port is picked. If a range in the format num-num is passed, a free port from the range (end inclusive) is selected.
54
+
type = lib.types.port;
57
+
user = lib.mkOption {
58
+
default = defaultUser;
59
+
example = "yourUser";
60
+
description = lib.mdDoc ''
61
+
The user to run openvscode-server as.
62
+
By default, a user named `${defaultUser}` will be created.
64
+
type = lib.types.str;
67
+
group = lib.mkOption {
68
+
default = defaultGroup;
69
+
example = "yourGroup";
70
+
description = lib.mdDoc ''
71
+
The group to run openvscode-server under.
72
+
By default, a group named `${defaultGroup}` will be created.
74
+
type = lib.types.str;
77
+
extraGroups = lib.mkOption {
79
+
description = lib.mdDoc ''
80
+
An array of additional groups for the `${defaultUser}` user.
82
+
example = [ "docker" ];
83
+
type = lib.types.listOf lib.types.str;
86
+
withoutConnectionToken = lib.mkOption {
88
+
description = lib.mdDoc ''
89
+
Run without a connection token. Only use this if the connection is secured by other means.
92
+
type = lib.types.bool;
95
+
socketPath = lib.mkOption {
97
+
example = "/run/openvscode/socket";
98
+
description = lib.mdDoc ''
99
+
The path to a socket file for the server to listen to.
101
+
type = lib.types.nullOr lib.types.str;
104
+
userDataDir = lib.mkOption {
106
+
description = lib.mdDoc ''
107
+
Specifies the directory that user data is kept in. Can be used to open multiple distinct instances of Code.
109
+
type = lib.types.nullOr lib.types.str;
112
+
serverDataDir = lib.mkOption {
114
+
description = lib.mdDoc ''
115
+
Specifies the directory that server data is kept in.
117
+
type = lib.types.nullOr lib.types.str;
120
+
extensionsDir = lib.mkOption {
122
+
description = lib.mdDoc ''
123
+
Set the root path for extensions.
125
+
type = lib.types.nullOr lib.types.str;
128
+
telemetryLevel = lib.mkOption {
131
+
description = lib.mdDoc ''
132
+
Sets the initial telemetry level. Valid levels are: 'off', 'crash', 'error' and 'all'.
134
+
type = lib.types.str;
137
+
connectionToken = lib.mkOption {
139
+
example = "secret-token";
140
+
description = lib.mdDoc ''
141
+
A secret that must be included with all requests.
143
+
type = lib.types.nullOr lib.types.str;
146
+
connectionTokenFile = lib.mkOption {
148
+
description = lib.mdDoc ''
149
+
Path to a file that contains the connection token.
151
+
type = lib.types.nullOr lib.types.str;
157
+
config = lib.mkIf cfg.enable {
158
+
systemd.services.openvscode-server = {
159
+
description = "OpenVSCode server";
160
+
wantedBy = [ "multi-user.target" ];
161
+
after = [ "network-online.target" ];
162
+
path = cfg.extraPackages;
163
+
environment = cfg.extraEnvironment;
166
+
${lib.getExe cfg.package} \
167
+
--accept-server-license-terms \
168
+
--host=${cfg.host} \
169
+
--port=${toString cfg.port} \
170
+
'' + lib.optionalString (cfg.telemetryLevel == true) ''
171
+
--telemetry-level=${cfg.telemetryLevel} \
172
+
'' + lib.optionalString (cfg.withoutConnectionToken == true) ''
173
+
--without-connection-token \
174
+
'' + lib.optionalString (cfg.socketPath != null) ''
175
+
--socket-path=${cfg.socketPath} \
176
+
'' + lib.optionalString (cfg.userDataDir != null) ''
177
+
--user-data-dir=${cfg.userDataDir} \
178
+
'' + lib.optionalString (cfg.serverDataDir != null) ''
179
+
--server-data-dir=${cfg.serverDataDir} \
180
+
'' + lib.optionalString (cfg.extensionsDir != null) ''
181
+
--extensions-dir=${cfg.extensionsDir} \
182
+
'' + lib.optionalString (cfg.connectionToken != null) ''
183
+
--connection-token=${cfg.connectionToken} \
184
+
'' + lib.optionalString (cfg.connectionTokenFile != null) ''
185
+
--connection-token-file=${cfg.connectionTokenFile} \
186
+
'' + lib.escapeShellArgs cfg.extraArguments;
187
+
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
188
+
RuntimeDirectory = cfg.user;
191
+
Restart = "on-failure";
195
+
users.users."${cfg.user}" = lib.mkMerge [
196
+
(lib.mkIf (cfg.user == defaultUser) {
197
+
isNormalUser = true;
198
+
description = "openvscode-server user";
199
+
inherit (cfg) group;
202
+
packages = cfg.extraPackages;
203
+
inherit (cfg) extraGroups;
207
+
users.groups."${defaultGroup}" = lib.mkIf (cfg.group == defaultGroup) { };
210
+
meta.maintainers = [ lib.maintainers.drupol ];