Can I install vscodium and tweak its product.json?

Hi

I work with vscodium instead of vscode, and I’ve been installing it from Flatpak for years.

But recently, I needed to tweak its product.json (file inside the vscodium folder) to install some custom extensions…

I can (could) edit directly /var/lib/flatpak/app/com.vscodium.codium/x86_64/stable/33dbe633c25dd1ece5f188ac991090f5845cbd1fcfa8cb61ef3f068ecf1e7b96/files/share/codium/resources/app/product.json but the modification would be removed on the next flatpak upgrade.

That is why I’m wondering if I could get it done with nixos configuration.nix.

First I would start by adding vscodium to my configuration …

  users.users."seb" = {
    ...
    packages = with pkgs; [ vscodium ];
  };

And then … I don’k know :slight_smile:

I’m not familiar enough with NixOS to automatically modify the product.json from the installed package. For example, I would like to automatically sed on /nix/store/<vscode-subfolder>/lib/vscode/resources/app/product.json so that the modification would persist over nixos vscode upgrades…

First, is this possible?
And someone could help me on this or point some documentation on how to do it?

Thanks

Probably something like

  users.users.seb.packages = [
    (pkgs.vscodium.overrideAttrs (oldAttrs: {
      postInstall = (oldAttrs.postInstall or "") + ''
        substituteInPlace $out/lib/vscode/resources/app/product.json \
          oldString newString
      '';
    }))
  ];

change oldString and newString of course.

And for reference, if you’re confused about anything written above, or want to understand better how to work with nixpkgs, see Nixpkgs Reference Manual

PS I’ve not tested the above, so if there’s issues, please post what you tried and specific errors.

Thanks a lot @waffle8946

I knew that NixOS was powerful enough to allow such a thing, but the syntax is a bit too complex for me I guess.

For the record it didn’t work out of the box, you were missing a --replace which I managed to figure out :slight_smile:

Here is the final version

    packages = with pkgs; [
      (vscodium.overrideAttrs (oldAttrs: {
        postInstall = (oldAttrs.postInstall or "") + ''
        substituteInPlace $out/lib/vscode/resources/app/product.json \
          --replace \
          'old string here' \
          'new string here' 
        '';
      }))
    ];

Thanks again

Good catch, I would even use --replace-fail so that I know when the string has changed (--replace is deprecated and --replace-warn/--replace-quiet wouldn’t be loud enough to flag issues in the product.json for my use cases)

I don’t recall if the -fail variant is only present on unstable or not, so it might take a couple months to make its way to stable if so

1 Like