New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vscode-utils/vscodeEnv: add vscodeWithConfiguration, vscodeExts2nix a… #76427
Conversation
…nd vscodeEnv move mktplcExtRefToFetchArgs to file in order to be shared with the new derivations(privately)
in | ||
vscodeWithConfiguration = (userParams : import ./vscodeWithConfiguration.nix { | ||
inherit lib vscode extensionsFromVscodeMarketplace writeShellScriptBin; | ||
} // userParams); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the parenthesis are not needed here
|
||
vscodeExts2nix = (userParams : import ./vscodeExts2nix.nix { | ||
inherit lib vscode; | ||
} // userParams); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
|
||
vscodeEnv = (userParams : import ./vscodeEnv.nix { | ||
inherit lib writeShellScriptBin extensionsFromVscodeMarketplace vscode; | ||
} // userParams ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
}; | ||
code = writeShellScriptBin "code" '' | ||
${vscodeWithConfiguration}/bin/code --wait "$@" | ||
echo 'running vscodeExts2nix to update ${mutableExtensionsFilePath}...' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
echo 'running vscodeExts2nix to update ${mutableExtensionsFilePath}...' | |
echo 'running vscodeExts2nix to update ${toString mutableExtensionsFilePath}...' |
code = writeShellScriptBin "code" '' | ||
${vscodeWithConfiguration}/bin/code --wait "$@" | ||
echo 'running vscodeExts2nix to update ${mutableExtensionsFilePath}...' | ||
${vscodeExts2nix}/bin/vscodeExts2nix > ${mutableExtensionsFilePath} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
${vscodeExts2nix}/bin/vscodeExts2nix > ${mutableExtensionsFilePath} | |
${vscodeExts2nix}/bin/vscodeExts2nix > ${toString mutableExtensionsFilePath} |
this is to avoid having the path be added to the /nix/store
, vscode ? pkgs.vscode | ||
}: | ||
let | ||
mutableExtensionsFilePath = builtins.toPath mutableExtensionsFile; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not needed. or use toString
instead, it does effectively the same thing.
@@ -0,0 +1,8 @@ | |||
ext: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ext: | |
{ publisher, name, version }: |
you can extract attributes
, nixExtensions ? [] | ||
# if file exists will use it and import the extensions in it into this dervation else will use empty extensions list | ||
# this file will be created/updated by vscodeExts2nix when vscode exists | ||
, mutableExtensionsFile ? ./extensions.nix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this argument should be provided by the user
, lib ? pkgs.lib | ||
, writeShellScriptBin ? pkgs.writeShellScriptBin | ||
, extensionsFromVscodeMarketplace ? pkgs.vscode-utils.extensionsFromVscodeMarketplace | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would return a second function with the user attributes below. These are the dependencies and below the function that the user wants to call.
, lib ? pkgs.lib | ||
, vscode ? pkgs.vscode | ||
, writeShellScriptBin ? pkgs.writeShellScriptBin | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same, split in two functions
, lib ? pkgs.lib | ||
, writeShellScriptBin ? pkgs.writeShellScriptBin | ||
, extensionsFromVscodeMarketplace ? pkgs.vscode-utils.extensionsFromVscodeMarketplace | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
split in two function
}@orig: | |
{ |
{ pkgs ? import <nixpkgs> {} | ||
, lib ? pkgs.lib | ||
, writeShellScriptBin ? pkgs.writeShellScriptBin | ||
, extensionsFromVscodeMarketplace ? pkgs.vscode-utils.extensionsFromVscodeMarketplace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
, extensionsFromVscodeMarketplace ? pkgs.vscode-utils.extensionsFromVscodeMarketplace | |
, extensionsFromVscodeMarketplace ? pkgs.vscode-utils.extensionsFromVscodeMarketplace | |
, vscode |
|
||
##User input | ||
|
||
, vscode ? pkgs.vscode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
, vscode ? pkgs.vscode | |
, vscode ? orig.vscode |
… vscodeExts2nix, vscodeEnv change usage of toPath with toString
@zimbatm updated base on your comments. |
cpExtensions = '' | ||
${lib.concatMapStringsSep "\n" (e : ''ln -sfn ${e}/share/vscode/extensions/* ${vscodeExtsFolderName}/'') nixExtsDrvs} | ||
${lib.concatMapStringsSep "\n" (e : '' | ||
cp -a ${e}/share/vscode/extensions/${e.vscodeExtUniqueId} ${vscodeExtsFolderName}/${e.vscodeExtUniqueId}-${(lib.findSingle (ext: ''${ext.publisher}.${ext.name}'' == e.vscodeExtUniqueId) "" "m" mutableExtensions ).version} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which extensions have problems when their directory is immutable? Could we fix these extensions to avoid this copying?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using this expression:
{ pkgs ? import <nixpkgs>{}}:
pkgs.vscode-with-extensions.override ({
vscodeExtensions = pkgs.vscode-utils.extensionsFromVscodeMarketplace ([
{
name = "csharp";
publisher = "ms-vscode";
version = "1.21.5";
sha256 = "031yx2kpjrw1b86y5nq110k9ywjgl26730ljddly05d8fxxham05";
}
]);
})
will cuase this error in vscode:
Failed at stage: touchBeginFile
Error: EACCES: permission denied, mkdir '/nix/store/vnz8ja4qzmg4qpbr5am647djadclswsm-vscode-extensions-1.40.1/share/vscode/extensions/ms-vscode.csharp/.omnisharp'
and this error when trying to use nix-collect-garbage :
deleting '/nix/store/trash'
12428 store paths deleted, 664.94 MiB freed
error: cannot unlink '/nix/store/trash/4mnbcnp5fb8495pjlzwrfy24c9yk122n-vscode/extension-ms-vscode-csharp-1.21.5/share/vscode/extensions/ms-vscode.csharp/.omnisharp/1.34.5/license.md': Permission denied
im using darwin.
@jonringer, what do you think about this PR? |
@zimbatm, are you still interested in this PR? It's been sitting in the queue for quite a while now and it does look pretty useful to me. IMHO, the submitter has addressed your comments so I wonder whether there's a path forward for this PR to get merged? |
@peti: it seems like a good idea and @countoren put quite a bit of effort in it. It's a mix between the pure and impure universes which is quite a new approach. The current complexity of the code is what prevented me from properly evaluating the PR. It would require me to block 1-2h to really look into it and see if it could be simplified. Which is what is slowing this PR down really. |
@peti , @zimbatm thanks guys for looking at it :). Another thing that I would like to solve here is the sudo that is done in order to keep the .vscode-exts folder in sync by removing non-nix-declared extensions, |
…nd vscodeEnv move mktplcExtRefToFetchArgs to file in order to be shared with the new derivations(privately)
… vscodeExts2nix, vscodeEnv change usage of toPath with toString
…nto the a vscode settings file
…ings.json, keybindings.json
… parameter type from path to string
Treat workspace setting files as global for that user-data-dir with symlink. Add updateLaunchCmd to update .vscode/launch.json.
This is a use example: let
personal-extensions-file = ./personal-extensions.nix;
in
vscodeEnv {
nixExtensions = import ./extensions.nix
++ (
if builtins.pathExists personal-extensions-file
then import personal-extensions-file else []
);
mutableExtensionsFile = ./mutable-extensions.nix;
settings =
{
"FSharp.useSdkScripts" = true;
};
} |
… delete them Do not use sudo.
…/nixpkgs-1 into vscode-utils/vscodeEnv * 'vscode-utils/vscodeEnv' of https://github.com/countoren/nixpkgs-1: (178391 commits) Use a different vscode user-data-dir for every project. Treat workspace setting files as global for that user-data-dir with symlink. Add updateLaunchCmd to update .vscode/launch.json. fix permission problem of mutableExtensions vscodeEnv updateSettings for keybindings change keybindings file name parameter type from path to string change vscodeSettingsFile parameter type from path to string add missing jq to vscodeEnv use updateSettings in vscodeEnv in order to create and/or update settings.json, keybindings.json add updateSettings drv which will union nix settings configurations into the a vscode settings file vscode-utils/vscodeEnv: fix typo and grammer in the description comment vscode-utils/vscodeEnv: split to 2 functions vscodeWithConfiguration, vscodeExts2nix, vscodeEnv vsode-utils: extracting attributes to limit input range vscode-utils/vscodeEnv: add vscodeWithConfiguration, vscodeExts2nix and vscodeEnv xfce.xfce4-icon-theme: update gtk dependency and add license xfce.xfce4-hardware-monitor-plugin: update meta xfce.xfce4-embed-plugin: update meta and buildInputs xfce.xfce4-mailwatch-plugin: remove broken status xfce.exo: add support for gtk2, besides gtk3 xfce.xfdesktop: 4.14.1 -> 4.14.2 xfce.xfce4-weather-plugin: 0.8.10 -> 0.10.1 xfce.xfdashboard: 0.7.5 -> 0.7.7 xfce.xfce4-timer-plugin: 1.6.0 -> 1.7.0 ...
I believe this PR has been waiting long enough and I'm not aware of any controversy around it, i.e. no-one seems to have anything against merging it. So ... I'm merging it. :-) |
based on this project
Motivation for this change
Declarative configuration of vscode settings and extensions in a per project basis.
And I was trying to solve these problems:
some extensions mutate the contents of their folder. Therefore, the nix store is not the best place for those extensions.
being able to automatically get the extensions' information that nix needs to fetch them. Also, use vscode interface to manage the extensions while having a nix expression defining the extensions that are used for a project.
VSCode Global configuration folder and globally enabled extensions.
Things done
created :
vsCodeWithConfiguration - wrapper for vscode that:
updateSettings - shell script that creates or overrides all settings files in .vscode based on the nix expression.
settings.json will be initialized with :
vscodeExtensions2nix - with a vscode given as parameter, it will run with "--list-extensions" to output a valid nix expression that returns a list of sets of this expression (including sha).
vscodeEnv - puts together vscodeWithConfiguration, vscodeExtensions2nix and updateSettings. Creates another wrapper above vscodeWithConfiguration which adds "--wait" flag in order to run vscodeExtensions2nix after vscode exits. vscodeExtensions2nix will update an expression file with the mutable extensions currently installed.
Notify maintainers
cc @zimbatm