add updateSettings drv which will union nix settings configurations into the a vscode settings file
This commit is contained in:
parent
3d102d1c90
commit
a535e7a04f
33
pkgs/misc/vscode-extensions/updateSettings.nix
Normal file
33
pkgs/misc/vscode-extensions/updateSettings.nix
Normal file
@ -0,0 +1,33 @@
|
||||
# Updates the vscode setting file base on a nix expression
|
||||
# should run from the workspace root.
|
||||
{ writeShellScriptBin
|
||||
, lib
|
||||
, jq
|
||||
}:
|
||||
##User Input
|
||||
{ settings ? {}
|
||||
# if marked as true will create an empty json file if does not exists
|
||||
, createIfDoesNotExists ? true
|
||||
, vscodeSettingsFile ? .vscode/settings.json
|
||||
}:
|
||||
let
|
||||
#VSCode Settings file
|
||||
vscodeSettingsFileStr = toString vscodeSettingsFile;
|
||||
|
||||
updateVSCodeSettingsCmd = ''
|
||||
(
|
||||
echo 'updateSettings.nix: Updating ${vscodeSettingsFileStr}...'
|
||||
oldSettings=$(cat ${vscodeSettingsFileStr})
|
||||
echo $oldSettings' ${builtins.toJSON settings}' | ${jq}/bin/jq -s add > ${vscodeSettingsFileStr}
|
||||
)'';
|
||||
|
||||
createEmptySettingsCmd = ''mkdir -p .vscode && echo "{}" > ${vscodeSettingsFileStr}'';
|
||||
in
|
||||
writeShellScriptBin ''vscodeNixUpdate-${lib.removeSuffix ".json" (builtins.baseNameOf vscodeSettingsFileStr)}''
|
||||
(lib.optionalString (settings != {})
|
||||
(if createIfDoesNotExists then ''
|
||||
[ ! -f "${vscodeSettingsFileStr}" ] && ${createEmptySettingsCmd}
|
||||
${updateVSCodeSettingsCmd}
|
||||
''
|
||||
else ''[ -f "${vscodeSettingsFileStr}" ] && ${updateVSCodeSettingsCmd}''
|
||||
))
|
6
pkgs/misc/vscode-extensions/updateSettingsTest.nix
Normal file
6
pkgs/misc/vscode-extensions/updateSettingsTest.nix
Normal file
@ -0,0 +1,6 @@
|
||||
with import <nixpkgs>{};
|
||||
callPackage (import ./updateSettings.nix) {} {
|
||||
settings = {
|
||||
a = "fdsdf";
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user