mirror of
https://github.com/nix-community/nixos-vscode-server.git
synced 2024-10-03 21:17:38 +03:00
add extra options
This commit is contained in:
parent
abc8f1d59c
commit
6bb84c3b7b
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@ -0,0 +1 @@
|
||||
* text eol=lf
|
@ -1,12 +1,50 @@
|
||||
moduleConfig:
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
{
|
||||
options.services.vscode-server.enable = with types; mkEnableOption "VS Code Server";
|
||||
options.services.vscode-server = let
|
||||
inherit (lib) mkEnableOption mkOption;
|
||||
inherit (lib.types) bool functionTo listOf package str;
|
||||
in {
|
||||
enable = mkEnableOption "VS Code Server";
|
||||
|
||||
config = lib.mkIf config.services.vscode-server.enable (moduleConfig rec {
|
||||
enableFHS = mkOption {
|
||||
type = bool;
|
||||
default = true;
|
||||
example = false;
|
||||
description = ''
|
||||
Whether to enable FHS compatible environment.
|
||||
'';
|
||||
};
|
||||
|
||||
extraFHSPackages = mkOption {
|
||||
type = functionTo (listOf package);
|
||||
default = pkgs: [ ];
|
||||
description = ''
|
||||
A function to add extra packages to the FHS compatible environment.
|
||||
'';
|
||||
};
|
||||
|
||||
nodejsPackage = mkOption {
|
||||
type = package;
|
||||
default = pkgs.nodejs-16_x;
|
||||
example = pkgs.nodejs-18_x;
|
||||
description = ''
|
||||
The Node.js package of the Node.js version used by VS Code version of the client.
|
||||
'';
|
||||
};
|
||||
|
||||
installPath = mkOption {
|
||||
type = str;
|
||||
default = "~/.vscode-server";
|
||||
example = "~/.vscode-server-oss";
|
||||
description = ''
|
||||
The install path.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config = let cfg = config.services.vscode-server; in mkIf cfg.enable (moduleConfig {
|
||||
name = "auto-fix-vscode-server";
|
||||
description = "Automatically fix the VS Code server used by the remote SSH extension";
|
||||
serviceConfig = {
|
||||
@ -16,34 +54,7 @@ with lib;
|
||||
# so rather than creating our own restart mechanism, we leverage systemd to do this for us.
|
||||
Restart = "always";
|
||||
RestartSec = 0;
|
||||
ExecStart = "${pkgs.writeShellScript "${name}.sh" ''
|
||||
set -euo pipefail
|
||||
PATH=${makeBinPath (with pkgs; [ coreutils findutils inotify-tools ])}
|
||||
bin_dir=~/.vscode-server/bin
|
||||
|
||||
# Fix any existing symlinks before we enter the inotify loop.
|
||||
if [[ -e $bin_dir ]]; then
|
||||
find "$bin_dir" -mindepth 2 -maxdepth 2 -name node -exec ln -sfT ${pkgs.nodejs-18_x}/bin/node {} \;
|
||||
find "$bin_dir" -path '*/@vscode/ripgrep/bin/rg' -exec ln -sfT ${pkgs.ripgrep}/bin/rg {} \;
|
||||
else
|
||||
mkdir -p "$bin_dir"
|
||||
fi
|
||||
|
||||
while IFS=: read -r bin_dir event; do
|
||||
# A new version of the VS Code Server is being created.
|
||||
if [[ $event == 'CREATE,ISDIR' ]]; then
|
||||
# Create a trigger to know when their node is being created and replace it for our symlink.
|
||||
touch "$bin_dir/node"
|
||||
inotifywait -qq -e DELETE_SELF "$bin_dir/node"
|
||||
ln -sfT ${pkgs.nodejs-18_x}/bin/node "$bin_dir/node"
|
||||
ln -sfT ${pkgs.ripgrep}/bin/rg "$bin_dir/node_modules/@vscode/ripgrep/bin/rg"
|
||||
# The monitored directory is deleted, e.g. when "Uninstall VS Code Server from Host" has been run.
|
||||
elif [[ $event == DELETE_SELF ]]; then
|
||||
# See the comments above Restart in the service config.
|
||||
exit 0
|
||||
fi
|
||||
done < <(inotifywait -q -m -e CREATE,ISDIR -e DELETE_SELF --format '%w%f:%e' "$bin_dir")
|
||||
''}";
|
||||
ExecStart = pkgs.callPackage ../../pkgs/auto-fix-vscode-server.nix (removeAttrs [ "enable" ] cfg);
|
||||
};
|
||||
});
|
||||
}
|
||||
|
75
pkgs/auto-fix-vscode-server.nix
Normal file
75
pkgs/auto-fix-vscode-server.nix
Normal file
@ -0,0 +1,75 @@
|
||||
{ lib, writeShellScript, coreutils, findutils, inotify-tools, ripgrep, buildFHSUserEnv, nodejs-16_x
|
||||
, enableFHS ? true
|
||||
, extraFHSPackages ? (pkgs: [ ])
|
||||
, nodejsPackage ? nodejs-16_x
|
||||
, installPath ? "~/.vscode-server"
|
||||
}:
|
||||
|
||||
let
|
||||
nodejs = nodejsPackage;
|
||||
|
||||
# Based on: https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/applications/editors/vscode/generic.nix
|
||||
nodejsFHS = pkgs.buildFHSUserEnv {
|
||||
name = nodejs.name;
|
||||
|
||||
# additional libraries which are commonly needed for extensions
|
||||
targetPkgs = pkgs: (builtins.attrValues {
|
||||
inherit (pkgs)
|
||||
# ld-linux-x86-64-linux.so.2 and others
|
||||
glibc
|
||||
|
||||
# dotnet
|
||||
curl
|
||||
icu
|
||||
libunwind
|
||||
libuuid
|
||||
lttng-ust
|
||||
openssl
|
||||
zlib
|
||||
|
||||
# mono
|
||||
krb5
|
||||
;
|
||||
}) ++ extraFHSPackages pkgs;
|
||||
|
||||
runScript = "${nodejs}/bin/node";
|
||||
|
||||
meta = {
|
||||
description = ''
|
||||
Wrapped variant of ${nodejs.name} which launches in an FHS compatible envrionment,
|
||||
which should allow for easy usage of extensions without nix-specific modifications.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
nodeBin = if enableFHS then "${nodejs}/bin/node" else "${nodejsFHS}/bin/${nodejsFHS.name}";
|
||||
|
||||
in
|
||||
writeShellScript "auto-fix-vscode-server.sh" ''
|
||||
set -euo pipefail
|
||||
PATH=${lib.makeBinPath [ coreutils findutils inotify-tools ]}
|
||||
bin_dir='${installPath}/bin'
|
||||
|
||||
# Fix any existing symlinks before we enter the inotify loop.
|
||||
if [[ -e $bin_dir ]]; then
|
||||
find "$bin_dir" -mindepth 2 -maxdepth 2 -name node -exec ln -sfT ${nodeBin} {} \;
|
||||
find "$bin_dir" -path '*/@vscode/ripgrep/bin/rg' -exec ln -sfT ${ripgrep}/bin/rg {} \;
|
||||
else
|
||||
mkdir -p "$bin_dir"
|
||||
fi
|
||||
|
||||
while IFS=: read -r bin_dir event; do
|
||||
# A new version of the VS Code Server is being created.
|
||||
if [[ $event == 'CREATE,ISDIR' ]]; then
|
||||
# Create a trigger to know when their node is being created and replace it for our symlink.
|
||||
touch "$bin_dir/node"
|
||||
inotifywait -qq -e DELETE_SELF "$bin_dir/node"
|
||||
ln -sfT ${nodeBin} "$bin_dir/node"
|
||||
ln -sfT ${ripgrep}/bin/rg "$bin_dir/node_modules/@vscode/ripgrep/bin/rg"
|
||||
# The monitored directory is deleted, e.g. when "Uninstall VS Code Server from Host" has been run.
|
||||
elif [[ $event == DELETE_SELF ]]; then
|
||||
# See the comments above Restart in the service config.
|
||||
exit 0
|
||||
fi
|
||||
done < <(inotifywait -q -m -e CREATE,ISDIR -e DELETE_SELF --format '%w%f:%e' "$bin_dir")
|
||||
''
|
Loading…
Reference in New Issue
Block a user