VS Code: Workaround for read-only settings

Hi! I’m learning Nix and trying to describe my Mac profile config with Nix. I’ve installed VSCode (actually VSCodium) and successfully configured it through helpful Home Manager options. However, using the app is very annoying as it constantly tries to modify settings (e.g. when my system theme changes) and fails to do so with an error message.

Is there any way in Nix to make the settings.json writable to the app and still overwrite it each time I switch configuration? Or maybe there is another way to solve it in a Nix way?

I am pretty sure I have this figured out…
I set all the defaults I like in my vscode.nix… this deploys vscode without fhs…
I do NOT set any profiles in nix… then there won’t be any conflict with the profiles folder existing (which is cloned from the git repo for me)
then simply go to: ~/.config/Code/User/profiles/<name>
and create profiles…
I can then select from the profiles in vscode and things seem to work as expected.
I don’t expect complex things like dl different sets of plugins and install them…
I get them all with Default Profile… then turn them on and off in unique Profiles
Don’t want 50 plugins? disable them…
Need a new one? add it to Defaults.

vscode Profiles

You can limit the new profile to only include a subset of configurations (settings, keyboard shortcuts, snippets, tasks and extensions) and use the rest of the configurations from the Default Profile. For example, you can create a profile with all configurations, except for keyboard shortcuts, and VS Code will apply the keyboard shortcuts from the Default Profile when this profile is active.

Thanks for posting this. I actually wasn’t aware of Profiles. I played a bit with them but am still puzzled… AFAIK profiles are not layered/inherited, they are exclusive in terms of defined settings and extensions. So a profile will have to duplicate/copy settings and extensions from default. Then when I change something in the default via Nix, I will have to manually sync it to the profile. Did I miss something?

I thought to go the other way around and generate profiles with Nix. That way I would be able to use “golden” immutable settings when I need and switch to default when I need to experiment with something. However, profile extensions JSON seems to contain absolute paths, so I don’t know if I can generate that with Nix.

@shishkin Did you find a way? I’m having the same problem right now.

I ended up with this (simplified) code in my vscode module:

  home.file."Library/Application Support/VSCodium/User/settings.json".source = lib.mkForce (
    config.lib.file.mkOutOfStoreSymlink "/path/to/repo/path/inside/repo/vscode-settings.json"
  );

Then I have vscode-settings.json inside my repo and it’s writable. Whenever I tweak my settings I can commit them in the repo.

For the whole thing to work the path must be absolute and you need to add --impure flag. As a result nix will create a symlink inside ~/Library/... pointing to a symlink inside /nix/store/... pointing to my JSON.

3 Likes

Thank you so much for your reply!
I updated my config, and it works perfectly :blush:. I didn’t even need to add the --impure flag - it worked right out of the box!

1 Like

I didn’t even need to add the --impure flag

Ah, cool. Thanks for the hint. I think it didn’t work for me without it, but now it works.

1 Like