1 { config, lib, pkgs, ... }:
4 cfg = config.services.openvscode-server;
5 defaultUser = "openvscode-server";
6 defaultGroup = defaultUser;
10 services.openvscode-server = {
11 enable = lib.mkEnableOption "openvscode-server";
13 package = lib.mkPackageOption pkgs "openvscode-server" { };
15 extraPackages = lib.mkOption {
18 Additional packages to add to the openvscode-server {env}`PATH`.
20 example = lib.literalExpression "[ pkgs.go ]";
21 type = lib.types.listOf lib.types.package;
24 extraEnvironment = lib.mkOption {
25 type = lib.types.attrsOf lib.types.str;
27 Additional environment variables to pass to openvscode-server.
30 example = { PKG_CONFIG_PATH = "/run/current-system/sw/lib/pkgconfig"; };
33 extraArguments = lib.mkOption {
36 Additional arguments to pass to openvscode-server.
38 example = lib.literalExpression ''[ "--log=info" ]'';
39 type = lib.types.listOf lib.types.str;
43 default = "localhost";
45 The host name or IP address the server should listen to.
53 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.
55 type = lib.types.port;
59 default = defaultUser;
62 The user to run openvscode-server as.
63 By default, a user named `${defaultUser}` will be created.
68 group = lib.mkOption {
69 default = defaultGroup;
70 example = "yourGroup";
72 The group to run openvscode-server under.
73 By default, a group named `${defaultGroup}` will be created.
78 extraGroups = lib.mkOption {
81 An array of additional groups for the `${defaultUser}` user.
83 example = [ "docker" ];
84 type = lib.types.listOf lib.types.str;
87 withoutConnectionToken = lib.mkOption {
90 Run without a connection token. Only use this if the connection is secured by other means.
93 type = lib.types.bool;
96 socketPath = lib.mkOption {
98 example = "/run/openvscode/socket";
100 The path to a socket file for the server to listen to.
102 type = lib.types.nullOr lib.types.str;
105 userDataDir = lib.mkOption {
108 Specifies the directory that user data is kept in. Can be used to open multiple distinct instances of Code.
110 type = lib.types.nullOr lib.types.str;
113 serverDataDir = lib.mkOption {
116 Specifies the directory that server data is kept in.
118 type = lib.types.nullOr lib.types.str;
121 extensionsDir = lib.mkOption {
124 Set the root path for extensions.
126 type = lib.types.nullOr lib.types.str;
129 telemetryLevel = lib.mkOption {
133 Sets the initial telemetry level. Valid levels are: 'off', 'crash', 'error' and 'all'.
135 type = lib.types.nullOr (lib.types.enum [ "off" "crash" "error" "all" ]);
138 connectionToken = lib.mkOption {
140 example = "secret-token";
142 A secret that must be included with all requests.
144 type = lib.types.nullOr lib.types.str;
147 connectionTokenFile = lib.mkOption {
150 Path to a file that contains the connection token.
152 type = lib.types.nullOr lib.types.str;
158 config = lib.mkIf cfg.enable {
159 systemd.services.openvscode-server = {
160 description = "OpenVSCode server";
161 wantedBy = [ "multi-user.target" ];
162 wants = [ "network-online.target" ];
163 after = [ "network-online.target" ];
164 path = cfg.extraPackages;
165 environment = cfg.extraEnvironment;
168 ${lib.getExe cfg.package} \
169 --accept-server-license-terms \
171 --port=${toString cfg.port} \
172 '' + lib.optionalString (cfg.telemetryLevel != null) ''
173 --telemetry-level=${cfg.telemetryLevel} \
174 '' + lib.optionalString (cfg.withoutConnectionToken) ''
175 --without-connection-token \
176 '' + lib.optionalString (cfg.socketPath != null) ''
177 --socket-path=${cfg.socketPath} \
178 '' + lib.optionalString (cfg.userDataDir != null) ''
179 --user-data-dir=${cfg.userDataDir} \
180 '' + lib.optionalString (cfg.serverDataDir != null) ''
181 --server-data-dir=${cfg.serverDataDir} \
182 '' + lib.optionalString (cfg.extensionsDir != null) ''
183 --extensions-dir=${cfg.extensionsDir} \
184 '' + lib.optionalString (cfg.connectionToken != null) ''
185 --connection-token=${cfg.connectionToken} \
186 '' + lib.optionalString (cfg.connectionTokenFile != null) ''
187 --connection-token-file=${cfg.connectionTokenFile} \
188 '' + lib.escapeShellArgs cfg.extraArguments;
189 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
190 RuntimeDirectory = cfg.user;
193 Restart = "on-failure";
197 users.users."${cfg.user}" = lib.mkMerge [
198 (lib.mkIf (cfg.user == defaultUser) {
200 description = "openvscode-server user";
204 packages = cfg.extraPackages;
205 inherit (cfg) extraGroups;
209 users.groups."${defaultGroup}" = lib.mkIf (cfg.group == defaultGroup) { };
212 meta.maintainers = [ lib.maintainers.drupol ];