From a04361cd78f0f04b5bf1262e41be787dd10b8af7 Mon Sep 17 00:00:00 2001 From: Thomas BESSOU Date: Wed, 3 Jul 2024 15:50:38 +0200 Subject: [PATCH 01/10] Add option to enable the service for all users --- README.md | 42 +++++++++++++++++++ modules/vscode-server/default.nix | 67 ++++++++++++++++++++++++++----- modules/vscode-server/home.nix | 37 ++++++++++------- modules/vscode-server/module.nix | 20 +++++++-- 4 files changed, 139 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 46f2b66..1099eab 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,27 @@ you'll have to manually enable the service for each user (see below). #### Enable the service +##### Automatically for all users + +Instead of just +```nix +{ services.vscode-server.enable = true; } +``` + +use: +```nix +{ + services.vscode-server = { + enable = true; + enableForAllUsers = true; + }; +} +``` + +This will use `tmpfiles` to setup the permanent symlink described below for each regular user. + +##### Manually for each user + And then enable them for the relevant users: ```bash @@ -79,6 +100,8 @@ ln -sfT /run/current-system/etc/systemd/user/auto-fix-vscode-server.service ~/.c ### Home Manager +#### Install as a tarball + Put this code into your [home-manager](https://github.com/nix-community/home-manager) configuration i.e. in `~/.config/nixpkgs/home.nix`: ```nix @@ -91,6 +114,25 @@ Put this code into your [home-manager](https://github.com/nix-community/home-man } ``` +#### Install as a flake + +```nix +{ + inputs.vscode-server.url = "github:nix-community/nixos-vscode-server"; + + outputs = { self, vscode-server, home-manager }: { + homeConfigurations.yourhostname = home-manager.lib.homeManagerConfiguration { + modules = [ + vscode-server.homeModules.default + ({ config, pkgs, ... }: { + services.vscode-server.enable = true; + }) + ]; + }; + }; +} +``` + ## Usage When using VS Code as released by Microsoft without any special needs, just enabling and starting the service should be enough to make things work. If you have some custom build or needs, there are a few options available that might help you out. diff --git a/modules/vscode-server/default.nix b/modules/vscode-server/default.nix index 6e9b419..4773a4b 100644 --- a/modules/vscode-server/default.nix +++ b/modules/vscode-server/default.nix @@ -1,10 +1,57 @@ -import ./module.nix ({ - name, - description, - serviceConfig, -}: { - systemd.user.services.${name} = { - inherit description serviceConfig; - wantedBy = [ "default.target" ]; - }; -}) +import ./module.nix ( + { name + , description + , serviceConfig + , lib + , config + , cfg + }: lib.mkMerge [ + { + systemd.user.services.${name} = { + inherit description serviceConfig; + wantedBy = [ "default.target" ]; + }; + } + (lib.mkIf cfg.enableForAllUsers { + systemd.tmpfiles.settings = + let + forEachUser = ({ path, file }: lib.attrsets.mapAttrs' + (username: userOptions: + { + # Create the directory so that it has the appropriate permissions if it doesn't already exist + # Otherwise the directive below creating the symlink would have that owned by root + name = "${userOptions.home}/${path}"; + value = file username; + }) + (lib.attrsets.filterAttrs (username: userOptions: userOptions.isNormalUser) config.users.users)); + homeDirectory = (path: forEachUser { + inherit path; + file = (username: { + "d" = { + user = username; + group = "users"; + mode = "0755"; + }; + }); + }); + in + { + # We need to create each of the folders before the next file otherwise parents get owned by root + "80-setup-config-folder-for-all-users" = homeDirectory ".config"; + "81-setup-systemd-folder-for-all-users" = homeDirectory ".config/systemd"; + "82-setup-systemd-user-folder-for-all-users" = homeDirectory ".config/systemd/user"; + "83-enable-auto-fix-vscode-server-service-for-all-users" = forEachUser { + path = ".config/systemd/user/auto-fix-vscode-server.service"; + file = (username: { + "L+" = { + user = username; + group = "users"; + # This path is made available by `services.vscode-server.enable = true;` + argument = "/run/current-system/etc/systemd/user/auto-fix-vscode-server.service"; + }; + }); + }; + }; + }) + ] +) diff --git a/modules/vscode-server/home.nix b/modules/vscode-server/home.nix index 616145b..4dd2665 100644 --- a/modules/vscode-server/home.nix +++ b/modules/vscode-server/home.nix @@ -1,17 +1,26 @@ -import ./module.nix ({ - name, - description, - serviceConfig, -}: { - systemd.user.services.${name} = { - Unit = { - Description = description; - }; +import ./module.nix ( + { name + , description + , serviceConfig + , cfg + , ... + }: + { + systemd.user.services.${name} = { + Unit = { + Description = description; + }; - Service = serviceConfig; + Service = serviceConfig; - Install = { - WantedBy = [ "default.target" ]; + Install = { + WantedBy = [ "default.target" ]; + }; }; - }; -}) + + assertions = [{ + assertion = !cfg.enableForAllUsers; + message = "enableForAllUsers=true doesn't make sense when using nixos-vscode-server as a home-manager module"; + }]; + } +) diff --git a/modules/vscode-server/module.nix b/modules/vscode-server/module.nix index 4bf714b..ec9af77 100644 --- a/modules/vscode-server/module.nix +++ b/modules/vscode-server/module.nix @@ -6,9 +6,9 @@ moduleConfig: { }: { options.services.vscode-server = let inherit (lib) mkEnableOption mkOption; - inherit (lib.types) lines listOf nullOr package str; + inherit (lib.types) lines listOf nullOr package str bool; in { - enable = mkEnableOption "VS Code Server"; + enable = mkEnableOption "VS Code Server autofix"; enableFHS = mkEnableOption "a FHS compatible environment"; @@ -49,6 +49,19 @@ moduleConfig: { This can be used as a hook for custom further patching. ''; }; + + enableForAllUsers = mkOption { + type = bool; + default = false; + example = true; + description = '' + Whether to enable the VS Code Server auto-fix service for all users. + + This only makes sense if auto-fix-vscode-server is installed as a NixOS module. + + This automatically sets up the service's symlinks for systemd in each users' home directory. + ''; + }; }; config = let @@ -56,7 +69,7 @@ moduleConfig: { cfg = config.services.vscode-server; auto-fix-vscode-server = pkgs.callPackage ../../pkgs/auto-fix-vscode-server.nix - (removeAttrs cfg [ "enable" ]); + (removeAttrs cfg [ "enable" "enableForAllUsers" ]); in mkIf cfg.enable (mkMerge [ { @@ -74,6 +87,7 @@ moduleConfig: { RestartSec = 0; ExecStart = "${auto-fix-vscode-server}/bin/auto-fix-vscode-server"; }; + inherit config cfg lib; }) ]); } From b5a62ed5f925b50fabc2759027096637f4a2ace0 Mon Sep 17 00:00:00 2001 From: Thomas BESSOU Date: Sat, 19 Oct 2024 18:38:29 +0200 Subject: [PATCH 02/10] Make it possible to customize user list --- README.md | 2 +- modules/vscode-server/default.nix | 12 +++++------ modules/vscode-server/home.nix | 4 ++-- modules/vscode-server/module.nix | 36 +++++++++++++++++++++---------- 4 files changed, 34 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 1099eab..76f95c8 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ use: { services.vscode-server = { enable = true; - enableForAllUsers = true; + enableForUsers.enable = true; }; } ``` diff --git a/modules/vscode-server/default.nix b/modules/vscode-server/default.nix index 4773a4b..ec63f83 100644 --- a/modules/vscode-server/default.nix +++ b/modules/vscode-server/default.nix @@ -12,18 +12,18 @@ import ./module.nix ( wantedBy = [ "default.target" ]; }; } - (lib.mkIf cfg.enableForAllUsers { + (lib.mkIf cfg.enableForUsers.enable { systemd.tmpfiles.settings = let - forEachUser = ({ path, file }: lib.attrsets.mapAttrs' - (username: userOptions: - { + forEachUser = ({ path, file }: builtins.listToAttrs + (builtins.map + (username: { # Create the directory so that it has the appropriate permissions if it doesn't already exist # Otherwise the directive below creating the symlink would have that owned by root - name = "${userOptions.home}/${path}"; + name = "${config.users.users.${username}.home}/${path}"; value = file username; }) - (lib.attrsets.filterAttrs (username: userOptions: userOptions.isNormalUser) config.users.users)); + cfg.enableForUsers.users)); homeDirectory = (path: forEachUser { inherit path; file = (username: { diff --git a/modules/vscode-server/home.nix b/modules/vscode-server/home.nix index 4dd2665..bd8d3ca 100644 --- a/modules/vscode-server/home.nix +++ b/modules/vscode-server/home.nix @@ -19,8 +19,8 @@ import ./module.nix ( }; assertions = [{ - assertion = !cfg.enableForAllUsers; - message = "enableForAllUsers=true doesn't make sense when using nixos-vscode-server as a home-manager module"; + assertion = !cfg.enableForUsers.enable; + message = "enableForUsers.enable=true doesn't make sense when using nixos-vscode-server as a home-manager module"; }]; } ) diff --git a/modules/vscode-server/module.nix b/modules/vscode-server/module.nix index ec9af77..e68d8d4 100644 --- a/modules/vscode-server/module.nix +++ b/modules/vscode-server/module.nix @@ -6,7 +6,7 @@ moduleConfig: { }: { options.services.vscode-server = let inherit (lib) mkEnableOption mkOption; - inherit (lib.types) lines listOf nullOr package str bool; + inherit (lib.types) lines listOf nullOr package str bool passwdEntry; in { enable = mkEnableOption "VS Code Server autofix"; @@ -50,17 +50,31 @@ moduleConfig: { ''; }; - enableForAllUsers = mkOption { - type = bool; - default = false; - example = true; - description = '' - Whether to enable the VS Code Server auto-fix service for all users. + enableForUsers = { + enable = mkOption { + type = bool; + default = false; + example = true; + description = '' + Whether to enable the VS Code Server auto-fix service for each user. - This only makes sense if auto-fix-vscode-server is installed as a NixOS module. + This only makes sense if auto-fix-vscode-server is installed as a NixOS module. - This automatically sets up the service's symlinks for systemd in each users' home directory. - ''; + This automatically sets up the service's symlinks for systemd in each users' home directory. + ''; + }; + + users = mkOption { + type = listOf (passwdEntry str); + default = builtins.attrNames (lib.attrsets.filterAttrs (username: userOptions: userOptions.isNormalUser) config.users.users); + defaultText = "builtins.attrNames (lib.filterAttrs (_: userOptions: userOptions.isNormalUser) config.users.users)"; + example = [ "alice" "bob" ]; + description = '' + List of users to enable the VS Code Server auto-fix service for. + + By default this will fallback to the list of "normal" users. + ''; + }; }; }; @@ -69,7 +83,7 @@ moduleConfig: { cfg = config.services.vscode-server; auto-fix-vscode-server = pkgs.callPackage ../../pkgs/auto-fix-vscode-server.nix - (removeAttrs cfg [ "enable" "enableForAllUsers" ]); + (removeAttrs cfg [ "enable" "enableForUsers" ]); in mkIf cfg.enable (mkMerge [ { From af14d643d79ce86a239fc4390bb429dae1c7f520 Mon Sep 17 00:00:00 2001 From: Thomas BESSOU Date: Sat, 19 Oct 2024 20:14:45 +0200 Subject: [PATCH 03/10] reduce odds of file conflict --- modules/vscode-server/default.nix | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/vscode-server/default.nix b/modules/vscode-server/default.nix index ec63f83..1ba80f3 100644 --- a/modules/vscode-server/default.nix +++ b/modules/vscode-server/default.nix @@ -37,10 +37,10 @@ import ./module.nix ( in { # We need to create each of the folders before the next file otherwise parents get owned by root - "80-setup-config-folder-for-all-users" = homeDirectory ".config"; - "81-setup-systemd-folder-for-all-users" = homeDirectory ".config/systemd"; - "82-setup-systemd-user-folder-for-all-users" = homeDirectory ".config/systemd/user"; - "83-enable-auto-fix-vscode-server-service-for-all-users" = forEachUser { + "80-vscode-server-setup-config-folder-for-all-users" = homeDirectory ".config"; + "81-vscode-server-setup-systemd-folder-for-all-users" = homeDirectory ".config/systemd"; + "82-vscode-server-setup-systemd-user-folder-for-all-users" = homeDirectory ".config/systemd/user"; + "83-vscode-server-enable-auto-fix-vscode-server-service-for-all-users" = forEachUser { path = ".config/systemd/user/auto-fix-vscode-server.service"; file = (username: { "L+" = { From 725f14eaf6a9c57d0992e711b27c08d1f9a74d05 Mon Sep 17 00:00:00 2001 From: Thomas BESSOU Date: Sun, 20 Oct 2024 12:41:34 +0200 Subject: [PATCH 04/10] Account for changed user name --- modules/vscode-server/default.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/vscode-server/default.nix b/modules/vscode-server/default.nix index 1ba80f3..f91bfb4 100644 --- a/modules/vscode-server/default.nix +++ b/modules/vscode-server/default.nix @@ -17,11 +17,11 @@ import ./module.nix ( let forEachUser = ({ path, file }: builtins.listToAttrs (builtins.map - (username: { + (username: let user = config.users.users.${username}; in { # Create the directory so that it has the appropriate permissions if it doesn't already exist # Otherwise the directive below creating the symlink would have that owned by root - name = "${config.users.users.${username}.home}/${path}"; - value = file username; + name = "${user.home}/${path}"; + value = file user.name; }) cfg.enableForUsers.users)); homeDirectory = (path: forEachUser { From 97a396083c78e30d32aa49866311a44ec3101bb2 Mon Sep 17 00:00:00 2001 From: Thomas BESSOU Date: Sun, 20 Oct 2024 13:05:19 +0200 Subject: [PATCH 05/10] naming & documentation improvements --- README.md | 10 ++++++++++ modules/vscode-server/default.nix | 8 ++++---- modules/vscode-server/module.nix | 2 ++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 76f95c8..d7e8c66 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,16 @@ use: This will use `tmpfiles` to setup the permanent symlink described below for each regular user. +If you do not wish to enable it for all users, but only for a specific subset, the list of users this will be setup for can be overridden: + +```nix +{ + services.vscode-server.enableForUsers.users = [ "alice" "bob" ]; +} +``` + +Note that when disabling `services.vscode-server.enableForUsers.enable`, the file that was created in the user's `.config/systemd/user` will not be cleaned up, so you will have to clean it up manually. + ##### Manually for each user And then enable them for the relevant users: diff --git a/modules/vscode-server/default.nix b/modules/vscode-server/default.nix index f91bfb4..e726b22 100644 --- a/modules/vscode-server/default.nix +++ b/modules/vscode-server/default.nix @@ -37,10 +37,10 @@ import ./module.nix ( in { # We need to create each of the folders before the next file otherwise parents get owned by root - "80-vscode-server-setup-config-folder-for-all-users" = homeDirectory ".config"; - "81-vscode-server-setup-systemd-folder-for-all-users" = homeDirectory ".config/systemd"; - "82-vscode-server-setup-systemd-user-folder-for-all-users" = homeDirectory ".config/systemd/user"; - "83-vscode-server-enable-auto-fix-vscode-server-service-for-all-users" = forEachUser { + "80-vscode-server-enable-for-users-create-config-folder" = homeDirectory ".config"; + "81-vscode-server-enable-for-users-create-systemd-folder" = homeDirectory ".config/systemd"; + "82-vscode-server-enable-for-users-create-systemd-user-folder" = homeDirectory ".config/systemd/user"; + "83-vscode-server-enable-for-users-enable-auto-fix-vscode-server-service" = forEachUser { path = ".config/systemd/user/auto-fix-vscode-server.service"; file = (username: { "L+" = { diff --git a/modules/vscode-server/module.nix b/modules/vscode-server/module.nix index e68d8d4..dcd7f2a 100644 --- a/modules/vscode-server/module.nix +++ b/modules/vscode-server/module.nix @@ -61,6 +61,8 @@ moduleConfig: { This only makes sense if auto-fix-vscode-server is installed as a NixOS module. This automatically sets up the service's symlinks for systemd in each users' home directory. + + By default this will set it up for all regular users, but that list can be overridden by setting `users`. ''; }; From c7d960ef86ab55f6f564a220a92ca7f2b54e1ee2 Mon Sep 17 00:00:00 2001 From: Thomas BESSOU Date: Sun, 20 Oct 2024 13:07:27 +0200 Subject: [PATCH 06/10] cleanup a comment that seemingly shouldn't be there --- modules/vscode-server/default.nix | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/vscode-server/default.nix b/modules/vscode-server/default.nix index e726b22..216f76f 100644 --- a/modules/vscode-server/default.nix +++ b/modules/vscode-server/default.nix @@ -18,8 +18,6 @@ import ./module.nix ( forEachUser = ({ path, file }: builtins.listToAttrs (builtins.map (username: let user = config.users.users.${username}; in { - # Create the directory so that it has the appropriate permissions if it doesn't already exist - # Otherwise the directive below creating the symlink would have that owned by root name = "${user.home}/${path}"; value = file user.name; }) From 3082f0adc92eaaaacc9d998bfe6a7f570537e4c5 Mon Sep 17 00:00:00 2001 From: Elsa Date: Fri, 3 Jan 2025 11:18:22 +0800 Subject: [PATCH 07/10] Support monitor multiple vscode distros --- modules/vscode-server/module.nix | 8 +++--- pkgs/auto-fix-vscode-server.nix | 49 +++++++++++++++++++++++--------- 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/modules/vscode-server/module.nix b/modules/vscode-server/module.nix index 4bf714b..127d336 100644 --- a/modules/vscode-server/module.nix +++ b/modules/vscode-server/module.nix @@ -33,11 +33,11 @@ moduleConfig: { }; installPath = mkOption { - type = str; - default = "$HOME/.vscode-server"; - example = "$HOME/.vscode-server-oss"; + type = listOf str; + default = [ "$HOME/.vscode-server" ]; + example = [ "$HOME/.vscode-server" "$HOME/.vscode-server-oss" "$HOME/.vscode-server-insiders" ]; description = '' - The install path. + The install paths for VS Code Server. ''; }; diff --git a/pkgs/auto-fix-vscode-server.nix b/pkgs/auto-fix-vscode-server.nix index 2649e40..457fd40 100644 --- a/pkgs/auto-fix-vscode-server.nix +++ b/pkgs/auto-fix-vscode-server.nix @@ -123,11 +123,12 @@ name = "auto-fix-vscode-server"; runtimeInputs = [ coreutils findutils inotify-tools ]; text = '' - bins_dir_1=${installPath}/bin - bins_dir_2=${installPath}/cli/servers + # Convert installPath list to an array + IFS=':' read -r -a installPaths <<< "${lib.concatStringsSep ":" installPath}" patch_bin () { local actual_dir="$1" + local current_install_path="$2" local patched_file="$actual_dir/.nixos-patched" if [[ -e $patched_file ]]; then @@ -139,9 +140,9 @@ old_patched_file="$(basename "$actual_dir")" if [[ $old_patched_file == "server" ]]; then old_patched_file="$(basename "$(dirname "$actual_dir")")" - old_patched_file="${installPath}/.''${old_patched_file%%.*}.patched" + old_patched_file="$current_install_path/.''${old_patched_file%%.*}.patched" else - old_patched_file="${installPath}/.''${old_patched_file%%-*}.patched" + old_patched_file="$current_install_path/.''${old_patched_file%%-*}.patched" fi if [[ -e $old_patched_file ]]; then echo "Migrating old nixos-vscode-server patch marker file to new location in $actual_dir." >&2 @@ -183,38 +184,58 @@ echo 0 > "$patched_file" } - mkdir -p "$bins_dir_1" "$bins_dir_2" - while read -rd ''' bin; do - if [[ $bin == "$bins_dir_2"* ]]; then + # Initialize arrays for bins_dirs_1 and bins_dirs_2 + bins_dirs_1=() + bins_dirs_2=() + + # Populate bins_dirs_1 and bins_dirs_2 based on installPaths + for current_install_path in "''${installPaths[@]}"; do + bins_dirs_1+=("$current_install_path/bin") + bins_dirs_2+=("$current_install_path/cli/servers") + done + + # Create directories and patch existing bins + for bins_dir_1 in "''${bins_dirs_1[@]}"; do + mkdir -p "$bins_dir_1" + while read -rd ''' bin; do + patch_bin "$bin" "$(dirname "$(dirname "$bin")")" + done < <(find "$bins_dir_1" -mindepth 1 -maxdepth 1 -type d -printf '%p\0') + done + for bins_dir_2 in "''${bins_dirs_2[@]}"; do + mkdir -p "$bins_dir_2" + while read -rd ''' bin; do bin="$bin/server" - fi - patch_bin "$bin" - done < <(find "$bins_dir_1" "$bins_dir_2" -mindepth 1 -maxdepth 1 -type d -printf '%p\0') - + patch_bin "$bin" "$(dirname "$(dirname "$bin")")" + done < <(find "$bins_dir_2" -mindepth 1 -maxdepth 1 -type d -printf '%p\0') + done + + # Watch for new installations while IFS=: read -r bins_dir bin event; do # A new version of the VS Code Server is being created. if [[ $event == 'CREATE,ISDIR' ]]; then actual_dir="$bins_dir$bin" - if [[ "$bins_dir" == "$bins_dir_2/" ]]; then + actual_install_path="$(dirname "$bins_dir")" + if [[ "$bins_dir" == */cli/servers/ ]]; then actual_dir="$actual_dir/server" # Hope that VSCode will not die if the directory exists when it tries to install, otherwise we'll need to # use a coproc to wait for the directory to be created without entering in a race, then watch for the node # file to be created (probably while also avoiding a race) # https://unix.stackexchange.com/a/185370 mkdir -p "$actual_dir" + actual_install_path="$(dirname "$(dirname "$bins_dir")")" fi echo "VS Code server is being installed in $actual_dir..." >&2 # Quickly create a node file, which will be removed when vscode installs its own version touch "$actual_dir/node" # Hope we don't race... inotifywait -qq -e DELETE_SELF "$actual_dir/node" - patch_bin "$actual_dir" + patch_bin "$actual_dir" "$actual_install_path" # 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' "$bins_dir_1" "$bins_dir_2") + done < <(inotifywait -q -m -e CREATE,ISDIR -e DELETE_SELF --format '%w:%f:%e' "''${bins_dirs_1[@]}" "''${bins_dirs_2[@]}") ''; }; in From 30bd24c6740c48318e00bd21983c2ad5d816f472 Mon Sep 17 00:00:00 2001 From: Elsa Date: Fri, 3 Jan 2025 11:18:35 +0800 Subject: [PATCH 08/10] Increase restart sec to avoid restart failure --- modules/vscode-server/module.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/vscode-server/module.nix b/modules/vscode-server/module.nix index 127d336..aac8104 100644 --- a/modules/vscode-server/module.nix +++ b/modules/vscode-server/module.nix @@ -71,7 +71,7 @@ moduleConfig: { # Unfortunately the monitor does not kill itself when it stops monitoring, # so rather than creating our own restart mechanism, we leverage systemd to do this for us. Restart = "always"; - RestartSec = 0; + RestartSec = 5; ExecStart = "${auto-fix-vscode-server}/bin/auto-fix-vscode-server"; }; }) From 40dc5fdcb5fc4292b35caaebffec9e71c8c6e3df Mon Sep 17 00:00:00 2001 From: Elsa Date: Fri, 3 Jan 2025 11:19:58 +0800 Subject: [PATCH 09/10] Update readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1e6d711..2d816e9 100644 --- a/README.md +++ b/README.md @@ -140,11 +140,11 @@ This same list is also used to determine the `RPATH` when automatically patching ``` ### `installPath` -The installation path for VS Code server is configurable and the default can differ for alternative builds (e.g. oss and insider), so this option allows you to configure which installation path should be monitered and automatically fixed. +The installation path for VS Code server is configurable and the default can differ for alternative builds (e.g. oss and insider), so this option allows you to configure which installation path should be monitered and automatically fixed. If you have multiple installations, you can specify them as an array. ```nix { - services.vscode-server.installPath = "$HOME/.vscode-server-oss"; + services.vscode-server.installPath = [ "$HOME/.vscode-server" "$HOME/.vscode-server-oss" ]; } ``` From 7943271335904017d3fafbf6fea395beebe42239 Mon Sep 17 00:00:00 2001 From: Elsa Date: Sat, 8 Mar 2025 10:21:11 +0800 Subject: [PATCH 10/10] Accept a string or a list of strings --- README.md | 16 ++++++++++++++-- modules/vscode-server/module.nix | 6 ++++-- pkgs/auto-fix-vscode-server.nix | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2d816e9..487a35a 100644 --- a/README.md +++ b/README.md @@ -140,14 +140,26 @@ This same list is also used to determine the `RPATH` when automatically patching ``` ### `installPath` -The installation path for VS Code server is configurable and the default can differ for alternative builds (e.g. oss and insider), so this option allows you to configure which installation path should be monitered and automatically fixed. If you have multiple installations, you can specify them as an array. +The installation path for VS Code server is configurable. You can specify either a single path as a string or multiple paths as a list. If you have multiple installations (e.g., stable, OSS, and insider builds), you can specify all of them to be monitored and automatically fixed. ```nix +# Single path (string) { - services.vscode-server.installPath = [ "$HOME/.vscode-server" "$HOME/.vscode-server-oss" ]; + services.vscode-server.installPath = "$HOME/.vscode-server"; +} + +# Multiple paths (list) +{ + services.vscode-server.installPath = [ + "$HOME/.vscode-server" + "$HOME/.vscode-server-oss" + "$HOME/.vscode-server-insiders" + ]; } ``` +String values are automatically coerced to a single-element list for backwards compatibility. + ### `postPatch` The goal of this project is to make VS Code server work with NixOS, anything more is outside of the scope of the project, but if you want additional things to be done, you can use this hook to run a shell script after the patching is done. diff --git a/modules/vscode-server/module.nix b/modules/vscode-server/module.nix index aac8104..cfea28e 100644 --- a/modules/vscode-server/module.nix +++ b/modules/vscode-server/module.nix @@ -33,11 +33,13 @@ moduleConfig: { }; installPath = mkOption { - type = listOf str; + type = lib.types.coercedTo str (x: [x]) (listOf str); default = [ "$HOME/.vscode-server" ]; example = [ "$HOME/.vscode-server" "$HOME/.vscode-server-oss" "$HOME/.vscode-server-insiders" ]; description = '' - The install paths for VS Code Server. + Path(s) where VS Code Server will be installed. + Accepts either a single path string or a list of paths. + String values are automatically coerced to a single-element list for backwards compatibility. ''; }; diff --git a/pkgs/auto-fix-vscode-server.nix b/pkgs/auto-fix-vscode-server.nix index 457fd40..a17bbf2 100644 --- a/pkgs/auto-fix-vscode-server.nix +++ b/pkgs/auto-fix-vscode-server.nix @@ -21,7 +21,7 @@ enableFHS ? false, nodejsPackage ? null, extraRuntimeDependencies ? [ ], - installPath ? "$HOME/.vscode-server", + installPath ? [ "$HOME/.vscode-server" ], postPatch ? "", }: let inherit (lib) makeBinPath makeLibraryPath optionalString;