1 # Updates the vscode setting file base on a nix expression
2 # should run from the workspace root.
11 # if marked as true will create an empty json file if does not exist
12 createIfDoesNotExists ? true,
13 vscodeSettingsFile ? ".vscode/settings.json",
14 userSettingsFolder ? "",
15 symlinkFromUserSetting ? false,
19 updateVSCodeSettingsCmd = ''
21 echo 'updateSettings.nix: Updating ${vscodeSettingsFile}...'
22 oldSettings=$(cat ${vscodeSettingsFile})
23 echo $oldSettings' ${builtins.toJSON settings}' | ${jq}/bin/jq -s add > ${vscodeSettingsFile}
26 createEmptySettingsCmd = ''mkdir -p .vscode && echo "{}" > ${vscodeSettingsFile}'';
27 fileName = builtins.baseNameOf vscodeSettingsFile;
28 symlinkFromUserSettingCmd = lib.optionalString symlinkFromUserSetting ''&& mkdir -p "${userSettingsFolder}" && ln -sfv "$(pwd)/${vscodeSettingsFile}" "${userSettingsFolder}/" '';
31 writeShellScriptBin ''vscodeNixUpdate-${lib.removeSuffix ".json" (fileName)}'' (
32 lib.optionalString (settings != { }) (
33 if createIfDoesNotExists then
35 [ ! -f "${vscodeSettingsFile}" ] && ${createEmptySettingsCmd}
36 ${updateVSCodeSettingsCmd} ${symlinkFromUserSettingCmd}
40 [ -f "${vscodeSettingsFile}" ] && ${updateVSCodeSettingsCmd} ${symlinkFromUserSettingCmd}