2021-12-06 16:07:01 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.code-server;
|
|
|
|
defaultUser = "code-server";
|
|
|
|
defaultGroup = defaultUser;
|
|
|
|
|
|
|
|
in {
|
|
|
|
###### interface
|
|
|
|
options = {
|
|
|
|
services.code-server = {
|
2022-09-09 14:08:57 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "code-server");
|
2021-12-06 16:07:01 +00:00
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
default = pkgs.code-server;
|
|
|
|
defaultText = "pkgs.code-server";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Which code-server derivation to use.";
|
2021-12-06 16:07:01 +00:00
|
|
|
type = types.package;
|
|
|
|
};
|
|
|
|
|
|
|
|
extraPackages = mkOption {
|
|
|
|
default = [ ];
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Packages that are available in the PATH of code-server.";
|
2021-12-06 16:07:01 +00:00
|
|
|
example = "[ pkgs.go ]";
|
|
|
|
type = types.listOf types.package;
|
|
|
|
};
|
|
|
|
|
|
|
|
extraEnvironment = mkOption {
|
|
|
|
type = types.attrsOf types.str;
|
|
|
|
description =
|
2022-08-12 12:06:08 +00:00
|
|
|
lib.mdDoc "Additional environment variables to passed to code-server.";
|
2021-12-06 16:07:01 +00:00
|
|
|
default = { };
|
|
|
|
example = { PKG_CONFIG_PATH = "/run/current-system/sw/lib/pkgconfig"; };
|
|
|
|
};
|
|
|
|
|
|
|
|
extraArguments = mkOption {
|
|
|
|
default = [ "--disable-telemetry" ];
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Additional arguments that passed to code-server";
|
2021-12-06 16:07:01 +00:00
|
|
|
example = ''[ "--verbose" ]'';
|
|
|
|
type = types.listOf types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
host = mkOption {
|
|
|
|
default = "127.0.0.1";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "The host-ip to bind to.";
|
2021-12-06 16:07:01 +00:00
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
default = 4444;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "The port where code-server runs.";
|
2021-12-06 16:07:01 +00:00
|
|
|
type = types.port;
|
|
|
|
};
|
|
|
|
|
|
|
|
auth = mkOption {
|
|
|
|
default = "password";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "The type of authentication to use.";
|
2021-12-06 16:07:01 +00:00
|
|
|
type = types.enum [ "none" "password" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
hashedPassword = mkOption {
|
|
|
|
default = "";
|
|
|
|
description =
|
2022-08-12 12:06:08 +00:00
|
|
|
lib.mdDoc "Create the password with: 'echo -n 'thisismypassword' | npx argon2-cli -e'.";
|
2021-12-06 16:07:01 +00:00
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
default = defaultUser;
|
|
|
|
example = "yourUser";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
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
|
|
|
'';
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
default = defaultGroup;
|
|
|
|
example = "yourGroup";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
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
|
|
|
'';
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
extraGroups = mkOption {
|
|
|
|
default = [ ];
|
|
|
|
description =
|
2022-08-12 12:06:08 +00:00
|
|
|
lib.mdDoc "An array of additional groups for the `${defaultUser}` user.";
|
2021-12-06 16:07:01 +00:00
|
|
|
example = [ "docker" ];
|
|
|
|
type = types.listOf types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.code-server = {
|
|
|
|
description = "VSCode server";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network-online.target" ];
|
|
|
|
path = cfg.extraPackages;
|
|
|
|
environment = {
|
|
|
|
HASHED_PASSWORD = cfg.hashedPassword;
|
|
|
|
} // cfg.extraEnvironment;
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${cfg.package}/bin/code-server --bind-addr ${cfg.host}:${toString cfg.port} --auth ${cfg.auth} " + builtins.concatStringsSep " " cfg.extraArguments;
|
|
|
|
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
|
|
|
RuntimeDirectory = cfg.user;
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
Restart = "on-failure";
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
users.users."${cfg.user}" = mkMerge [
|
|
|
|
(mkIf (cfg.user == defaultUser) {
|
|
|
|
isNormalUser = true;
|
|
|
|
description = "code-server user";
|
|
|
|
inherit (cfg) group;
|
|
|
|
})
|
|
|
|
{
|
|
|
|
packages = cfg.extraPackages;
|
|
|
|
inherit (cfg) extraGroups;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
users.groups."${defaultGroup}" = mkIf (cfg.group == defaultGroup) { };
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
meta.maintainers = with maintainers; [ stackshadow ];
|
|
|
|
}
|