Skip to content
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

Merged
merged 18 commits into from May 29, 2020
Merged

vscode-utils/vscodeEnv: add vscodeWithConfiguration, vscodeExts2nix a… #76427

merged 18 commits into from May 29, 2020

Conversation

countoren
Copy link
Contributor

@countoren countoren commented Dec 24, 2019

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:

    • copy extensions to local extensions dir. mutable extensions will get copied while nix extensions will get symlinked.
    • set user-data folder to the template path of the nix-shell in order to avoid global settings(those could be configured in nix) and symlink global settings.json and keybindings.json to the local one in the project's .vscode folder.
  • updateSettings - shell script that creates or overrides all settings files in .vscode based on the nix expression.
    settings.json will be initialized with :

{  
   "extensions.autoCheckUpdates": false,
  "extensions.autoUpdate": false,
  "update.mode": "none"
}
  • 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

…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);
Copy link
Member

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);
Copy link
Member

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 );
Copy link
Member

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}...'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
${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;
Copy link
Member

@zimbatm zimbatm Dec 27, 2019

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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Member

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

Copy link
Member

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

Copy link
Member

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

split in two function

Suggested change
}@orig:
{

{ pkgs ? import <nixpkgs> {}
, lib ? pkgs.lib
, writeShellScriptBin ? pkgs.writeShellScriptBin
, extensionsFromVscodeMarketplace ? pkgs.vscode-utils.extensionsFromVscodeMarketplace
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
, extensionsFromVscodeMarketplace ? pkgs.vscode-utils.extensionsFromVscodeMarketplace
, extensionsFromVscodeMarketplace ? pkgs.vscode-utils.extensionsFromVscodeMarketplace
, vscode


##User input

, vscode ? pkgs.vscode
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
, vscode ? pkgs.vscode
, vscode ? orig.vscode

@countoren
Copy link
Contributor Author

@zimbatm updated base on your comments.

pkgs/misc/vscode-extensions/vscodeEnv.nix Outdated Show resolved Hide resolved
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}
Copy link
Contributor

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?

Copy link
Contributor Author

@countoren countoren Jan 11, 2020

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.

@countoren
Copy link
Contributor Author

@jonringer, what do you think about this PR?

@peti
Copy link
Member

peti commented Apr 17, 2020

@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?

@zimbatm
Copy link
Member

zimbatm commented Apr 19, 2020

@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.

@countoren
Copy link
Contributor Author

@peti , @zimbatm thanks guys for looking at it :).
while this PR was waiting to the evaluation I copied the code as a new repo (https://github.com/countoren/VSCodeEnv) and updated a bit more one of the main things was to be able to "ignore" global configuration of VSCode (this is to have more guaranties of the configurations) by moving vscode data folder to the tmp folder (instead of user folder) and symlink the user configuration files there to the project's one(which are overwritten from nix).
I am not sure if I should bring this feature before we merge or should we just look at this version first.

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,
I'm not 100% sure it is needed because the folder should be created by the user that runs the wrapper (code executable) but I had some problem with it so I added it but it could be due to something else I was missing.

@moinessim
Copy link
Contributor

moinessim commented May 25, 2020

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;
        };
      }

…/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
  ...
@peti
Copy link
Member

peti commented May 29, 2020

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. :-)

@peti peti merged commit e080ab1 into NixOS:master May 29, 2020
@eadwu eadwu mentioned this pull request May 30, 2020
10 tasks
veprbl added a commit that referenced this pull request Jun 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants