2021-12-06 16:07:01 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.code-server;
|
|
|
|
defaultUser = "code-server";
|
|
|
|
defaultGroup = defaultUser;
|
|
|
|
in {
|
|
|
|
options = {
|
|
|
|
services.code-server = {
|
2024-04-21 15:54:59 +00:00
|
|
|
enable = lib.mkEnableOption "code-server";
|
2021-12-06 16:07:01 +00:00
|
|
|
|
2024-07-01 15:47:52 +00:00
|
|
|
package = lib.mkPackageOption pkgs "code-server" {
|
2023-07-15 17:15:38 +00:00
|
|
|
example = ''
|
|
|
|
pkgs.vscode-with-extensions.override {
|
|
|
|
vscode = pkgs.code-server;
|
|
|
|
vscodeExtensions = with pkgs.vscode-extensions; [
|
|
|
|
bbenoist.nix
|
|
|
|
dracula-theme.theme-dracula
|
|
|
|
];
|
|
|
|
}
|
|
|
|
'';
|
2021-12-06 16:07:01 +00:00
|
|
|
};
|
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
extraPackages = lib.mkOption {
|
2021-12-06 16:07:01 +00:00
|
|
|
default = [ ];
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-07-15 17:15:38 +00:00
|
|
|
Additional packages to add to the code-server {env}`PATH`.
|
|
|
|
'';
|
|
|
|
example = lib.literalExpression "[ pkgs.go ]";
|
|
|
|
type = lib.types.listOf lib.types.package;
|
2021-12-06 16:07:01 +00:00
|
|
|
};
|
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
extraEnvironment = lib.mkOption {
|
|
|
|
type = lib.types.attrsOf lib.types.str;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-07-15 17:15:38 +00:00
|
|
|
Additional environment variables to pass to code-server.
|
|
|
|
'';
|
2021-12-06 16:07:01 +00:00
|
|
|
default = { };
|
|
|
|
example = { PKG_CONFIG_PATH = "/run/current-system/sw/lib/pkgconfig"; };
|
|
|
|
};
|
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
extraArguments = lib.mkOption {
|
|
|
|
default = [ ];
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-07-15 17:15:38 +00:00
|
|
|
Additional arguments to pass to code-server.
|
|
|
|
'';
|
|
|
|
example = lib.literalExpression ''[ "--log=info" ]'';
|
|
|
|
type = lib.types.listOf lib.types.str;
|
2021-12-06 16:07:01 +00:00
|
|
|
};
|
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
host = lib.mkOption {
|
|
|
|
default = "localhost";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-07-15 17:15:38 +00:00
|
|
|
The host name or IP address the server should listen to.
|
|
|
|
'';
|
|
|
|
type = lib.types.str;
|
2021-12-06 16:07:01 +00:00
|
|
|
};
|
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
port = lib.mkOption {
|
2021-12-06 16:07:01 +00:00
|
|
|
default = 4444;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-07-15 17:15:38 +00:00
|
|
|
The port the server should listen to.
|
|
|
|
'';
|
|
|
|
type = lib.types.port;
|
2021-12-06 16:07:01 +00:00
|
|
|
};
|
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
auth = lib.mkOption {
|
2021-12-06 16:07:01 +00:00
|
|
|
default = "password";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-07-15 17:15:38 +00:00
|
|
|
The type of authentication to use.
|
|
|
|
'';
|
|
|
|
type = lib.types.enum [ "none" "password" ];
|
2021-12-06 16:07:01 +00:00
|
|
|
};
|
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
hashedPassword = lib.mkOption {
|
2021-12-06 16:07:01 +00:00
|
|
|
default = "";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-07-15 17:15:38 +00:00
|
|
|
Create the password with: `echo -n 'thisismypassword' | npx argon2-cli -e`.
|
|
|
|
'';
|
|
|
|
type = lib.types.str;
|
2021-12-06 16:07:01 +00:00
|
|
|
};
|
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
user = lib.mkOption {
|
2021-12-06 16:07:01 +00:00
|
|
|
default = defaultUser;
|
|
|
|
example = "yourUser";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2021-12-06 16:07:01 +00:00
|
|
|
The user to run code-server as.
|
2022-08-12 12:06:08 +00:00
|
|
|
By default, a user named `${defaultUser}` will be created.
|
2021-12-06 16:07:01 +00:00
|
|
|
'';
|
2023-07-15 17:15:38 +00:00
|
|
|
type = lib.types.str;
|
2021-12-06 16:07:01 +00:00
|
|
|
};
|
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
group = lib.mkOption {
|
2021-12-06 16:07:01 +00:00
|
|
|
default = defaultGroup;
|
|
|
|
example = "yourGroup";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2021-12-06 16:07:01 +00:00
|
|
|
The group to run code-server under.
|
2022-08-12 12:06:08 +00:00
|
|
|
By default, a group named `${defaultGroup}` will be created.
|
2021-12-06 16:07:01 +00:00
|
|
|
'';
|
2023-07-15 17:15:38 +00:00
|
|
|
type = lib.types.str;
|
2021-12-06 16:07:01 +00:00
|
|
|
};
|
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
extraGroups = lib.mkOption {
|
2021-12-06 16:07:01 +00:00
|
|
|
default = [ ];
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-07-15 17:15:38 +00:00
|
|
|
An array of additional groups for the `${defaultUser}` user.
|
|
|
|
'';
|
2021-12-06 16:07:01 +00:00
|
|
|
example = [ "docker" ];
|
2023-07-15 17:15:38 +00:00
|
|
|
type = lib.types.listOf lib.types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
socket = lib.mkOption {
|
|
|
|
default = null;
|
|
|
|
example = "/run/code-server/socket";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-07-15 17:15:38 +00:00
|
|
|
Path to a socket (bind-addr will be ignored).
|
|
|
|
'';
|
|
|
|
type = lib.types.nullOr lib.types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
socketMode = lib.mkOption {
|
|
|
|
default = null;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-07-15 17:15:38 +00:00
|
|
|
File mode of the socket.
|
|
|
|
'';
|
|
|
|
type = lib.types.nullOr lib.types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
userDataDir = lib.mkOption {
|
|
|
|
default = null;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-07-15 17:15:38 +00:00
|
|
|
Path to the user data directory.
|
|
|
|
'';
|
|
|
|
type = lib.types.nullOr lib.types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
extensionsDir = lib.mkOption {
|
|
|
|
default = null;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-07-15 17:15:38 +00:00
|
|
|
Path to the extensions directory.
|
|
|
|
'';
|
|
|
|
type = lib.types.nullOr lib.types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
proxyDomain = lib.mkOption {
|
|
|
|
default = null;
|
|
|
|
example = "code-server.lan";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-07-15 17:15:38 +00:00
|
|
|
Domain used for proxying ports.
|
|
|
|
'';
|
|
|
|
type = lib.types.nullOr lib.types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
disableTelemetry = lib.mkOption {
|
|
|
|
default = false;
|
|
|
|
example = true;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-07-15 17:15:38 +00:00
|
|
|
Disable telemetry.
|
|
|
|
'';
|
|
|
|
type = lib.types.bool;
|
|
|
|
};
|
|
|
|
|
|
|
|
disableUpdateCheck = lib.mkOption {
|
|
|
|
default = false;
|
|
|
|
example = true;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-07-15 17:15:38 +00:00
|
|
|
Disable update check.
|
|
|
|
Without this flag, code-server checks every 6 hours against the latest github release and
|
|
|
|
then notifies you once every week that a new release is available.
|
|
|
|
'';
|
|
|
|
type = lib.types.bool;
|
|
|
|
};
|
|
|
|
|
|
|
|
disableFileDownloads = lib.mkOption {
|
|
|
|
default = false;
|
|
|
|
example = true;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-07-15 17:15:38 +00:00
|
|
|
Disable file downloads from Code.
|
|
|
|
'';
|
|
|
|
type = lib.types.bool;
|
|
|
|
};
|
|
|
|
|
|
|
|
disableWorkspaceTrust = lib.mkOption {
|
|
|
|
default = false;
|
|
|
|
example = true;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-07-15 17:15:38 +00:00
|
|
|
Disable Workspace Trust feature.
|
|
|
|
'';
|
|
|
|
type = lib.types.bool;
|
|
|
|
};
|
|
|
|
|
|
|
|
disableGettingStartedOverride = lib.mkOption {
|
|
|
|
default = false;
|
|
|
|
example = true;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-07-15 17:15:38 +00:00
|
|
|
Disable the coder/coder override in the Help: Getting Started page.
|
|
|
|
'';
|
|
|
|
type = lib.types.bool;
|
2021-12-06 16:07:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
config = lib.mkIf cfg.enable {
|
2021-12-06 16:07:01 +00:00
|
|
|
systemd.services.code-server = {
|
2023-07-15 17:15:38 +00:00
|
|
|
description = "Code server";
|
2021-12-06 16:07:01 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2024-01-25 14:12:00 +00:00
|
|
|
wants = [ "network-online.target" ];
|
2021-12-06 16:07:01 +00:00
|
|
|
after = [ "network-online.target" ];
|
|
|
|
path = cfg.extraPackages;
|
|
|
|
environment = {
|
|
|
|
HASHED_PASSWORD = cfg.hashedPassword;
|
|
|
|
} // cfg.extraEnvironment;
|
|
|
|
serviceConfig = {
|
2023-07-15 17:15:38 +00:00
|
|
|
ExecStart = ''
|
|
|
|
${lib.getExe cfg.package} \
|
|
|
|
--auth=${cfg.auth} \
|
|
|
|
--bind-addr=${cfg.host}:${toString cfg.port} \
|
|
|
|
'' + lib.optionalString (cfg.socket != null) ''
|
|
|
|
--socket=${cfg.socket} \
|
|
|
|
'' + lib.optionalString (cfg.userDataDir != null) ''
|
|
|
|
--user-data-dir=${cfg.userDataDir} \
|
|
|
|
'' + lib.optionalString (cfg.extensionsDir != null) ''
|
|
|
|
--extensions-dir=${cfg.extensionsDir} \
|
|
|
|
'' + lib.optionalString (cfg.disableTelemetry == true) ''
|
|
|
|
--disable-telemetry \
|
|
|
|
'' + lib.optionalString (cfg.disableUpdateCheck == true) ''
|
|
|
|
--disable-update-check \
|
|
|
|
'' + lib.optionalString (cfg.disableFileDownloads == true) ''
|
|
|
|
--disable-file-downloads \
|
|
|
|
'' + lib.optionalString (cfg.disableWorkspaceTrust == true) ''
|
|
|
|
--disable-workspace-trust \
|
|
|
|
'' + lib.optionalString (cfg.disableGettingStartedOverride == true) ''
|
|
|
|
--disable-getting-started-override \
|
|
|
|
'' + lib.escapeShellArgs cfg.extraArguments;
|
2021-12-06 16:07:01 +00:00
|
|
|
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
|
|
|
RuntimeDirectory = cfg.user;
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
Restart = "on-failure";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
users.users."${cfg.user}" = lib.mkMerge [
|
|
|
|
(lib.mkIf (cfg.user == defaultUser) {
|
2021-12-06 16:07:01 +00:00
|
|
|
isNormalUser = true;
|
|
|
|
description = "code-server user";
|
|
|
|
inherit (cfg) group;
|
|
|
|
})
|
|
|
|
{
|
|
|
|
packages = cfg.extraPackages;
|
|
|
|
inherit (cfg) extraGroups;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
users.groups."${defaultGroup}" = lib.mkIf (cfg.group == defaultGroup) { };
|
2021-12-06 16:07:01 +00:00
|
|
|
};
|
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
meta.maintainers = [ lib.maintainers.stackshadow ];
|
2021-12-06 16:07:01 +00:00
|
|
|
}
|