1 { config, lib, pkgs, ... }:
4 cfg = config.services.code-server;
5 defaultUser = "code-server";
6 defaultGroup = defaultUser;
9 services.code-server = {
10 enable = lib.mkEnableOption "code-server";
12 package = lib.mkPackageOption pkgs "code-server" {
14 pkgs.vscode-with-extensions.override {
15 vscode = pkgs.code-server;
16 vscodeExtensions = with pkgs.vscode-extensions; [
18 dracula-theme.theme-dracula
24 extraPackages = lib.mkOption {
27 Additional packages to add to the code-server {env}`PATH`.
29 example = lib.literalExpression "[ pkgs.go ]";
30 type = lib.types.listOf lib.types.package;
33 extraEnvironment = lib.mkOption {
34 type = lib.types.attrsOf lib.types.str;
36 Additional environment variables to pass to code-server.
39 example = { PKG_CONFIG_PATH = "/run/current-system/sw/lib/pkgconfig"; };
42 extraArguments = lib.mkOption {
45 Additional arguments to pass to code-server.
47 example = lib.literalExpression ''[ "--log=info" ]'';
48 type = lib.types.listOf lib.types.str;
52 default = "localhost";
54 The host name or IP address the server should listen to.
62 The port the server should listen to.
64 type = lib.types.port;
70 The type of authentication to use.
72 type = lib.types.enum [ "none" "password" ];
75 hashedPassword = lib.mkOption {
78 Create the password with: `echo -n 'thisismypassword' | npx argon2-cli -e`.
84 default = defaultUser;
87 The user to run code-server as.
88 By default, a user named `${defaultUser}` will be created.
93 group = lib.mkOption {
94 default = defaultGroup;
95 example = "yourGroup";
97 The group to run code-server under.
98 By default, a group named `${defaultGroup}` will be created.
100 type = lib.types.str;
103 extraGroups = lib.mkOption {
106 An array of additional groups for the `${defaultUser}` user.
108 example = [ "docker" ];
109 type = lib.types.listOf lib.types.str;
112 socket = lib.mkOption {
114 example = "/run/code-server/socket";
116 Path to a socket (bind-addr will be ignored).
118 type = lib.types.nullOr lib.types.str;
121 socketMode = lib.mkOption {
124 File mode of the socket.
126 type = lib.types.nullOr lib.types.str;
129 userDataDir = lib.mkOption {
132 Path to the user data directory.
134 type = lib.types.nullOr lib.types.str;
137 extensionsDir = lib.mkOption {
140 Path to the extensions directory.
142 type = lib.types.nullOr lib.types.str;
145 proxyDomain = lib.mkOption {
147 example = "code-server.lan";
149 Domain used for proxying ports.
151 type = lib.types.nullOr lib.types.str;
154 disableTelemetry = lib.mkOption {
160 type = lib.types.bool;
163 disableUpdateCheck = lib.mkOption {
167 Disable update check.
168 Without this flag, code-server checks every 6 hours against the latest github release and
169 then notifies you once every week that a new release is available.
171 type = lib.types.bool;
174 disableFileDownloads = lib.mkOption {
178 Disable file downloads from Code.
180 type = lib.types.bool;
183 disableWorkspaceTrust = lib.mkOption {
187 Disable Workspace Trust feature.
189 type = lib.types.bool;
192 disableGettingStartedOverride = lib.mkOption {
196 Disable the coder/coder override in the Help: Getting Started page.
198 type = lib.types.bool;
204 config = lib.mkIf cfg.enable {
205 systemd.services.code-server = {
206 description = "Code server";
207 wantedBy = [ "multi-user.target" ];
208 wants = [ "network-online.target" ];
209 after = [ "network-online.target" ];
210 path = cfg.extraPackages;
212 HASHED_PASSWORD = cfg.hashedPassword;
213 } // cfg.extraEnvironment;
216 ${lib.getExe cfg.package} \
218 --bind-addr=${cfg.host}:${toString cfg.port} \
219 '' + lib.optionalString (cfg.socket != null) ''
220 --socket=${cfg.socket} \
221 '' + lib.optionalString (cfg.userDataDir != null) ''
222 --user-data-dir=${cfg.userDataDir} \
223 '' + lib.optionalString (cfg.extensionsDir != null) ''
224 --extensions-dir=${cfg.extensionsDir} \
225 '' + lib.optionalString (cfg.disableTelemetry == true) ''
226 --disable-telemetry \
227 '' + lib.optionalString (cfg.disableUpdateCheck == true) ''
228 --disable-update-check \
229 '' + lib.optionalString (cfg.disableFileDownloads == true) ''
230 --disable-file-downloads \
231 '' + lib.optionalString (cfg.disableWorkspaceTrust == true) ''
232 --disable-workspace-trust \
233 '' + lib.optionalString (cfg.disableGettingStartedOverride == true) ''
234 --disable-getting-started-override \
235 '' + lib.escapeShellArgs cfg.extraArguments;
236 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
237 RuntimeDirectory = cfg.user;
240 Restart = "on-failure";
244 users.users."${cfg.user}" = lib.mkMerge [
245 (lib.mkIf (cfg.user == defaultUser) {
247 description = "code-server user";
251 packages = cfg.extraPackages;
252 inherit (cfg) extraGroups;
256 users.groups."${defaultGroup}" = lib.mkIf (cfg.group == defaultGroup) { };
259 meta.maintainers = [ lib.maintainers.stackshadow ];