2020-01-11 02:45:56 +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.
2019-12-28 21:43:41 +00:00
{ lib
, buildEnv
, writeShellScriptBin
, extensionsFromVscodeMarketplace
, vscodeDefault
2020-01-30 04:28:44 +00:00
, jq
2019-12-28 21:43:41 +00:00
} :
2019-12-24 18:15:15 +00:00
##User input
2020-01-30 04:28:44 +00:00
{ 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
2020-05-22 20:23:01 +00:00
, launch ? { }
, createLaunchIfDoesNotExists ? true
2020-01-30 04:28:44 +00:00
# will add to the command updateKeybindings(which will run on executing vscode) keybindings to override in keybinding.json file
, keybindings ? { }
, createKeybindingsIfDoesNotExists ? true
2020-05-22 20:23:01 +00:00
, user-data-dir ? '' " ''$ { T M P } ''$ { n a m e } " / v s c o d e - d a t a - d i r ''
2019-12-24 18:15:15 +00:00
# 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
2019-12-28 21:43:41 +00:00
, mutableExtensionsFile
2019-12-24 18:15:15 +00:00
} :
let
2019-12-28 21:43:41 +00:00
mutableExtensionsFilePath = toString mutableExtensionsFile ;
2019-12-24 18:15:15 +00:00
mutableExtensions = if builtins . pathExists mutableExtensionsFile
then import mutableExtensionsFilePath else [ ] ;
vscodeWithConfiguration = import ./vscodeWithConfiguration.nix {
2019-12-28 21:43:41 +00:00
inherit lib writeShellScriptBin extensionsFromVscodeMarketplace ;
vscodeDefault = vscode ;
}
{
2020-05-22 20:23:01 +00:00
inherit nixExtensions mutableExtensions vscodeExtsFolderName user-data-dir ;
2019-12-24 18:15:15 +00:00
} ;
2020-01-30 04:28:44 +00:00
updateSettings = import ./updateSettings.nix { inherit lib writeShellScriptBin jq ; } ;
2020-05-22 20:23:01 +00:00
userSettingsFolder = " ${ user-data-dir } / U s e r " ;
2020-01-30 04:28:44 +00:00
updateSettingsCmd = updateSettings {
2020-05-22 20:23:01 +00:00
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 ;
2020-01-30 04:28:44 +00:00
createIfDoesNotExists = createSettingsIfDoesNotExists ;
2020-05-22 20:23:01 +00:00
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 " ;
2020-01-30 04:28:44 +00:00
} ;
updateKeybindingsCmd = updateSettings {
settings = keybindings ;
createIfDoesNotExists = createKeybindingsIfDoesNotExists ;
2020-02-03 03:35:02 +00:00
vscodeSettingsFile = " . v s c o d e / k e y b i n d i n g s . j s o n " ;
2020-05-22 20:23:01 +00:00
inherit userSettingsFolder ;
symlinkFromUserSetting = ( user-data-dir != " " ) ;
2020-01-30 04:28:44 +00:00
} ;
2019-12-24 18:15:15 +00:00
vscodeExts2nix = import ./vscodeExts2nix.nix {
inherit lib writeShellScriptBin ;
2019-12-28 21:43:41 +00:00
vscodeDefault = vscodeWithConfiguration ;
}
{
2019-12-24 18:15:15 +00:00
extensionsToIgnore = nixExtensions ;
extensions = mutableExtensions ;
} ;
code = writeShellScriptBin " c o d e " ''
2020-01-30 04:28:44 +00:00
$ { updateSettingsCmd } /bin/vscodeNixUpdate-settings
2020-05-22 20:23:01 +00:00
$ { updateLaunchCmd } /bin/vscodeNixUpdate-launch
2020-01-30 04:28:44 +00:00
$ { updateKeybindingsCmd } /bin/vscodeNixUpdate-keybindings
2019-12-24 18:15:15 +00:00
$ { vscodeWithConfiguration } /bin/code - - wait " $ @ "
echo ' running vscodeExts2nix to update $ { mutableExtensionsFilePath } . . . '
$ { vscodeExts2nix } /bin/vscodeExts2nix > $ { mutableExtensionsFilePath }
'' ;
in
2019-12-28 21:43:41 +00:00
buildEnv {
2019-12-24 18:15:15 +00:00
name = " v s c o d e E n v " ;
2020-05-22 20:23:01 +00:00
paths = [ code vscodeExts2nix updateSettingsCmd updateLaunchCmd updateKeybindingsCmd ] ;
2019-12-24 18:15:15 +00:00
}