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
# will add to the command updateKeybindings(which will run on executing vscode) keybindings to override in keybinding.json file
, keybindings ? { }
, createKeybindingsIfDoesNotExists ? true
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 ;
}
{
inherit nixExtensions mutableExtensions vscodeExtsFolderName ;
2019-12-24 18:15:15 +00:00
} ;
2020-01-30 04:28:44 +00:00
updateSettings = import ./updateSettings.nix { inherit lib writeShellScriptBin jq ; } ;
updateSettingsCmd = updateSettings {
inherit settings ;
createIfDoesNotExists = createSettingsIfDoesNotExists ;
} ;
updateKeybindingsCmd = updateSettings {
settings = keybindings ;
createIfDoesNotExists = createKeybindingsIfDoesNotExists ;
vscodeSettingsFile = .vscode/keybindings.json ;
} ;
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
$ { 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-01-30 04:28:44 +00:00
paths = [ code vscodeExts2nix updateSettingsCmd updateKeybindingsCmd ] ;
2019-12-24 18:15:15 +00:00
}