Using the Microsoft vs Code Marketplace in Code-Server
I recently spent some time getting code-server to use the Microsoft VS Code Marketplace. I hit two annoying pitfalls, so here is the working setup.
Here is the final systemd --user override:
[Service]
Environment='EXTENSIONS_GALLERY={"serviceUrl":"https://marketplace.visualstudio.com/_apis/public/gallery","itemUrl":"https://marketplace.visualstudio.com/items","resourceUrlTemplate":"https://%%7Bpublisher%%7D.vscode-unpkg.net/%%7Bpublisher%%7D/%%7Bname%%7D/%%7Bversion%%7D/%%7Bpath%%7D","controlUrl":"","recommendationsUrl":""}'If your service is also the user service code-server.service, run:
systemctl --user edit code-server.servicePaste the override above, then reload and restart:
systemctl --user daemon-reload
systemctl --user restart code-server.serviceYou can verify whether the environment variable was injected correctly with:
systemctl --user show code-server.service -p EnvironmentIf it worked, you should see a valid JSON string there, not a broken one.
The Two Pitfalls
I. % must be written as %%
The resourceUrlTemplate contains %7B and %7D.
But inside a systemd unit, % is treated as a specifier. If you write %7Bpublisher%7D directly, the service will log an error like this:
Failed to resolve specifiers ... ignoring: Invalid slotSo every % in that URL must be escaped as %%.
II. The whole value must be quoted once more
If you write this directly:
Environment=EXTENSIONS_GALLERY={"serviceUrl":"..."}systemd will strip the JSON quotes before passing it to the process. The result is invalid JSON, and code-server may return HTTP 500.
So it needs to be written like this instead:
Environment='EXTENSIONS_GALLERY={"serviceUrl":"..."}'In other words, wrap the whole KEY=VALUE in one extra layer of quotes.
One More Note
In my case, the actual service was the user service:
code-server.serviceSo the file I changed was:
~/.config/systemd/user/code-server.service.d/override.confnot the system-level [email protected].
Final Result
After fixing both issues, the page loaded normally and the Microsoft marketplace worked.