Merge pull request #231435 from drupol/openvscode-server/systemd-service

This commit is contained in:
Sandro 2023-05-16 14:14:29 +02:00 committed by GitHub
commit efb55108b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 242 additions and 1 deletions

View File

@ -158,6 +158,8 @@ In addition to numerous new and upgraded packages, this release has the followin
- [ivpn](https://www.ivpn.net/), a secure, private VPN with fast WireGuard connections. Available as [services.ivpn](#opt-services.ivpn.enable). - [ivpn](https://www.ivpn.net/), a secure, private VPN with fast WireGuard connections. Available as [services.ivpn](#opt-services.ivpn.enable).
- [openvscode-server](https://github.com/gitpod-io/openvscode-server), run VS Code on a remote machine with access through a modern web browser from any device, anywhere. Available as [services.openvscode-server](#opt-services.openvscode-server.enable).
## Backward Incompatibilities {#sec-release-23.05-incompatibilities} ## Backward Incompatibilities {#sec-release-23.05-incompatibilities}
<!-- To avoid merge conflicts, consider adding your item at an arbitrary place in the list instead. --> <!-- To avoid merge conflicts, consider adding your item at an arbitrary place in the list instead. -->

View File

@ -1214,6 +1214,7 @@
./services/web-apps/nifi.nix ./services/web-apps/nifi.nix
./services/web-apps/node-red.nix ./services/web-apps/node-red.nix
./services/web-apps/onlyoffice.nix ./services/web-apps/onlyoffice.nix
./services/web-apps/openvscode-server.nix
./services/web-apps/openwebrx.nix ./services/web-apps/openwebrx.nix
./services/web-apps/outline.nix ./services/web-apps/outline.nix
./services/web-apps/peering-manager.nix ./services/web-apps/peering-manager.nix

View File

@ -0,0 +1,211 @@
{ config, lib, pkgs, ... }:
let
cfg = config.services.openvscode-server;
defaultUser = "openvscode-server";
defaultGroup = defaultUser;
in {
options = {
services.openvscode-server = {
enable = lib.mkEnableOption (lib.mdDoc "openvscode-server");
package = lib.mkPackageOptionMD pkgs "openvscode-server" { };
extraPackages = lib.mkOption {
default = [ ];
description = lib.mdDoc ''
Additional packages to add to the openvscode-server {env}`PATH`.
'';
example = lib.literalExpression "[ pkgs.go ]";
type = lib.types.listOf lib.types.package;
};
extraEnvironment = lib.mkOption {
type = lib.types.attrsOf lib.types.str;
description = lib.mdDoc ''
Additional environment variables to pass to openvscode-server.
'';
default = { };
example = { PKG_CONFIG_PATH = "/run/current-system/sw/lib/pkgconfig"; };
};
extraArguments = lib.mkOption {
default = [ ];
description = lib.mdDoc ''
Additional arguments to pass to openvscode-server.
'';
example = lib.literalExpression ''[ "--log=info" ]'';
type = lib.types.listOf lib.types.str;
};
host = lib.mkOption {
default = "localhost";
description = lib.mdDoc ''
The host name or IP address the server should listen to.
'';
type = lib.types.str;
};
port = lib.mkOption {
default = 3000;
description = lib.mdDoc ''
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.
'';
type = lib.types.port;
};
user = lib.mkOption {
default = defaultUser;
example = "yourUser";
description = lib.mdDoc ''
The user to run openvscode-server as.
By default, a user named `${defaultUser}` will be created.
'';
type = lib.types.str;
};
group = lib.mkOption {
default = defaultGroup;
example = "yourGroup";
description = lib.mdDoc ''
The group to run openvscode-server under.
By default, a group named `${defaultGroup}` will be created.
'';
type = lib.types.str;
};
extraGroups = lib.mkOption {
default = [ ];
description = lib.mdDoc ''
An array of additional groups for the `${defaultUser}` user.
'';
example = [ "docker" ];
type = lib.types.listOf lib.types.str;
};
withoutConnectionToken = lib.mkOption {
default = false;
description = lib.mdDoc ''
Run without a connection token. Only use this if the connection is secured by other means.
'';
example = true;
type = lib.types.bool;
};
socketPath = lib.mkOption {
default = null;
example = "/run/openvscode/socket";
description = lib.mdDoc ''
The path to a socket file for the server to listen to.
'';
type = lib.types.nullOr lib.types.str;
};
userDataDir = lib.mkOption {
default = null;
description = lib.mdDoc ''
Specifies the directory that user data is kept in. Can be used to open multiple distinct instances of Code.
'';
type = lib.types.nullOr lib.types.str;
};
serverDataDir = lib.mkOption {
default = null;
description = lib.mdDoc ''
Specifies the directory that server data is kept in.
'';
type = lib.types.nullOr lib.types.str;
};
extensionsDir = lib.mkOption {
default = null;
description = lib.mdDoc ''
Set the root path for extensions.
'';
type = lib.types.nullOr lib.types.str;
};
telemetryLevel = lib.mkOption {
default = "off";
example = "crash";
description = lib.mdDoc ''
Sets the initial telemetry level. Valid levels are: 'off', 'crash', 'error' and 'all'.
'';
type = lib.types.str;
};
connectionToken = lib.mkOption {
default = null;
example = "secret-token";
description = lib.mdDoc ''
A secret that must be included with all requests.
'';
type = lib.types.nullOr lib.types.str;
};
connectionTokenFile = lib.mkOption {
default = null;
description = lib.mdDoc ''
Path to a file that contains the connection token.
'';
type = lib.types.nullOr lib.types.str;
};
};
};
config = lib.mkIf cfg.enable {
systemd.services.openvscode-server = {
description = "OpenVSCode server";
wantedBy = [ "multi-user.target" ];
after = [ "network-online.target" ];
path = cfg.extraPackages;
environment = cfg.extraEnvironment;
serviceConfig = {
ExecStart = ''
${lib.getExe cfg.package} \
--accept-server-license-terms \
--host=${cfg.host} \
--port=${toString cfg.port} \
'' + lib.optionalString (cfg.telemetryLevel == true) ''
--telemetry-level=${cfg.telemetryLevel} \
'' + lib.optionalString (cfg.withoutConnectionToken == true) ''
--without-connection-token \
'' + lib.optionalString (cfg.socketPath != null) ''
--socket-path=${cfg.socketPath} \
'' + lib.optionalString (cfg.userDataDir != null) ''
--user-data-dir=${cfg.userDataDir} \
'' + lib.optionalString (cfg.serverDataDir != null) ''
--server-data-dir=${cfg.serverDataDir} \
'' + lib.optionalString (cfg.extensionsDir != null) ''
--extensions-dir=${cfg.extensionsDir} \
'' + lib.optionalString (cfg.connectionToken != null) ''
--connection-token=${cfg.connectionToken} \
'' + lib.optionalString (cfg.connectionTokenFile != null) ''
--connection-token-file=${cfg.connectionTokenFile} \
'' + lib.escapeShellArgs 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}" = lib.mkMerge [
(lib.mkIf (cfg.user == defaultUser) {
isNormalUser = true;
description = "openvscode-server user";
inherit (cfg) group;
})
{
packages = cfg.extraPackages;
inherit (cfg) extraGroups;
}
];
users.groups."${defaultGroup}" = lib.mkIf (cfg.group == defaultGroup) { };
};
meta.maintainers = [ lib.maintainers.drupol ];
}

View File

@ -554,6 +554,7 @@ in {
opentabletdriver = handleTest ./opentabletdriver.nix {}; opentabletdriver = handleTest ./opentabletdriver.nix {};
owncast = handleTest ./owncast.nix {}; owncast = handleTest ./owncast.nix {};
image-contents = handleTest ./image-contents.nix {}; image-contents = handleTest ./image-contents.nix {};
openvscode-server = handleTest ./openvscode-server.nix {};
orangefs = handleTest ./orangefs.nix {}; orangefs = handleTest ./orangefs.nix {};
os-prober = handleTestOn ["x86_64-linux"] ./os-prober.nix {}; os-prober = handleTestOn ["x86_64-linux"] ./os-prober.nix {};
osrm-backend = handleTest ./osrm-backend.nix {}; osrm-backend = handleTest ./osrm-backend.nix {};

View File

@ -0,0 +1,22 @@
import ./make-test-python.nix ({pkgs, lib, ...}:
{
name = "openvscode-server";
nodes = {
machine = {pkgs, ...}: {
services.openvscode-server = {
enable = true;
withoutConnectionToken = true;
};
};
};
testScript = ''
start_all()
machine.wait_for_unit("openvscode-server.service")
machine.wait_for_open_port(3000)
machine.succeed("curl -k --fail http://localhost:3000", timeout=10)
'';
meta.maintainers = [ lib.maintainers.drupol ];
})

View File

@ -1,7 +1,7 @@
{ lib, stdenv, fetchFromGitHub, buildGoModule, makeWrapper { lib, stdenv, fetchFromGitHub, buildGoModule, makeWrapper
, cacert, moreutils, jq, git, pkg-config, yarn, python3 , cacert, moreutils, jq, git, pkg-config, yarn, python3
, esbuild, nodejs_16, libsecret, xorg, ripgrep , esbuild, nodejs_16, libsecret, xorg, ripgrep
, AppKit, Cocoa, Security, cctools }: , AppKit, Cocoa, Security, cctools, nixosTests }:
let let
system = stdenv.hostPlatform.system; system = stdenv.hostPlatform.system;
@ -164,6 +164,10 @@ in stdenv.mkDerivation rec {
ln -s ${nodejs}/bin/node $out ln -s ${nodejs}/bin/node $out
''; '';
passthru.tests = {
inherit (nixosTests) openvscode-server;
};
meta = with lib; { meta = with lib; {
description = "Run VS Code on a remote machine"; description = "Run VS Code on a remote machine";
longDescription = '' longDescription = ''