2020-06-02 18:00:15 +00:00
#Use vscodeWithConfiguration and vscodeExts2nix to create a vscode executable. When the executable exits, it updates the mutable extension file, which is imported when evaluated by Nix later.
{ lib
, buildEnv
, writeShellScriptBin
, extensionsFromVscodeMarketplace
, vscodeDefault
, jq
} :
##User input
{ vscode ? vscodeDefault
, nixExtensions ? [ ]
, vscodeExtsFolderName ? " . v s c o d e - e x t s "
# will add to the command updateSettings (which will run on executing vscode) settings to override in settings.json file
, settings ? { }
, createSettingsIfDoesNotExists ? true
, launch ? { }
, createLaunchIfDoesNotExists ? true
# will add to the command updateKeybindings(which will run on executing vscode) keybindings to override in keybinding.json file
, keybindings ? { }
, createKeybindingsIfDoesNotExists ? true
, user-data-dir ? '' " ''$ { T M P } ''$ { n a m e } " / v s c o d e - d a t a - d i r ''
# 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
2020-09-25 04:45:31 +00:00
, mutableExtensionsFile
2020-06-02 18:00:15 +00:00
} :
2020-09-25 04:45:31 +00:00
let
2020-06-02 18:00:15 +00:00
mutableExtensionsFilePath = toString mutableExtensionsFile ;
2020-09-25 04:45:31 +00:00
mutableExtensions = if builtins . pathExists mutableExtensionsFile
2020-06-02 18:00:15 +00:00
then import mutableExtensionsFilePath else [ ] ;
2020-09-25 04:45:31 +00:00
vscodeWithConfiguration = import ./vscodeWithConfiguration.nix {
2020-06-02 18:00:15 +00:00
inherit lib writeShellScriptBin extensionsFromVscodeMarketplace ;
vscodeDefault = vscode ;
}
{
inherit nixExtensions mutableExtensions vscodeExtsFolderName user-data-dir ;
} ;
updateSettings = import ./updateSettings.nix { inherit lib writeShellScriptBin jq ; } ;
userSettingsFolder = " ${ user-data-dir } / U s e r " ;
updateSettingsCmd = updateSettings {
settings = {
" e x t e n s i o n s . a u t o C h e c k U p d a t e s " = false ;
" e x t e n s i o n s . a u t o U p d a t e " = false ;
" u p d a t e . m o d e " = " n o n e " ;
} // settings ;
inherit userSettingsFolder ;
createIfDoesNotExists = createSettingsIfDoesNotExists ;
symlinkFromUserSetting = ( user-data-dir != " " ) ;
} ;
updateLaunchCmd = updateSettings {
settings = launch ;
createIfDoesNotExists = createLaunchIfDoesNotExists ;
vscodeSettingsFile = " . v s c o d e / l a u n c h . j s o n " ;
} ;
updateKeybindingsCmd = updateSettings {
settings = keybindings ;
createIfDoesNotExists = createKeybindingsIfDoesNotExists ;
vscodeSettingsFile = " . v s c o d e / k e y b i n d i n g s . j s o n " ;
inherit userSettingsFolder ;
symlinkFromUserSetting = ( user-data-dir != " " ) ;
} ;
2020-09-25 04:45:31 +00:00
vscodeExts2nix = import ./vscodeExts2nix.nix {
2020-06-02 18:00:15 +00:00
inherit lib writeShellScriptBin ;
vscodeDefault = vscodeWithConfiguration ;
}
{
extensionsToIgnore = nixExtensions ;
2020-09-25 04:45:31 +00:00
extensions = mutableExtensions ;
2020-06-02 18:00:15 +00:00
} ;
code = writeShellScriptBin " c o d e " ''
$ { updateSettingsCmd } /bin/vscodeNixUpdate-settings
$ { updateLaunchCmd } /bin/vscodeNixUpdate-launch
$ { updateKeybindingsCmd } /bin/vscodeNixUpdate-keybindings
2020-09-25 04:45:31 +00:00
$ { vscodeWithConfiguration } /bin/code - - wait " $ @ "
2020-06-02 18:00:15 +00:00
echo ' running vscodeExts2nix to update $ { mutableExtensionsFilePath } . . . '
$ { vscodeExts2nix } /bin/vscodeExts2nix > $ { mutableExtensionsFilePath }
'' ;
in
buildEnv {
name = " v s c o d e E n v " ;
paths = [ code vscodeExts2nix updateSettingsCmd updateLaunchCmd updateKeybindingsCmd ] ;
}