4

This is a beginner question. So there is a package vscode-with-extensions. The package says:

A set of vscode extensions to be installed alongside the editor. Here's a an example:

vscode-with-extensions.override {
  # When the extension is already available in the default extensions set.
  vscodeExtensions = with vscode-extensions; [
    bbenoist.Nix
  ]
  # Concise version from the vscode market place when not available in the default set.
  ++ vscode-utils.extensionsFromVscodeMarketplace [
    {
      name = "code-runner";
      publisher = "formulahendry";
      version = "0.6.33";
      sha256 = "166ia73vrcl5c9hm4q1a73qdn56m0jc7flfsk5p5q41na9f10lb0";
    }
  ];
}

Where in configuration.nix do I have to put this expression? I already have

  environment.systemPackages = with pkgs; [
     wget 
     vim 
     vscode-with-extensions
  ];

therein.

Manuel Schmidt
  • 2,429
  • 1
  • 19
  • 32

3 Answers3

5

You’re supposed to use it as in the configuration.nix directly, like for instance

  environment.systemPackages = with pkgs; [
     wget 
     vim 
     (vscode-with-extensions.override {
  # When the extension is already available in the default extensions set.
  vscodeExtensions = with vscode-extensions; [
    bbenoist.Nix
  ]
  # Concise version from the vscode market place when not available in the default set.
  ++ vscode-utils.extensionsFromVscodeMarketplace [
    {
      name = "code-runner";
      publisher = "formulahendry";
      version = "0.6.33";
      sha256 = "166ia73vrcl5c9hm4q1a73qdn56m0jc7flfsk5p5q41na9f10lb0";
    }
  ];
})
  ];

Or, in a more readable version:

environment.systemPackages = with pkgs;
  let
    vcsodeWithExtension = vscode-with-extensions.override {
      # When the extension is already available in the default extensions set.
      vscodeExtensions = with vscode-extensions; [
        bbenoist.Nix
      ]
      # Concise version from the vscode market place when not available in the default set.
      ++ vscode-utils.extensionsFromVscodeMarketplace [
        {
          name = "code-runner";
          publisher = "formulahendry";
          version = "0.6.33";
          sha256 = "166ia73vrcl5c9hm4q1a73qdn56m0jc7flfsk5p5q41na9f10lb0";
        }
      ];
    })
  in
    [
      wget
      vim
      vcsodeWithExtension
    ];
Stig Brautaset
  • 2,602
  • 1
  • 22
  • 39
Immae
  • 313
  • 1
  • 2
  • 6
  • Where do I get the sha256 from? – akaihola Dec 04 '21 at 20:48
  • 2
    The usual way is to put a random string there ("0000000000000000000000000000000000000000000000000000") and let nix complain about it, and it will tell you the actual computed one – Immae Dec 05 '21 at 06:57
0

So, apparently it can go directly into environment.systemPackages, but requires parentheses:

  environment.systemPackages = with pkgs; [
    wget 
    vim 
    (vscode-with-extensions.override {
      vscodeExtensions = with vscode-extensions; [
        bbenoist.Nix
      ];
    })
  ];
Manuel Schmidt
  • 2,429
  • 1
  • 19
  • 32
0

I've just started using nix ... installed nixos. I came across this problem also (trying to get vscode installed with this extensions mechanism, but with a slightly different set of extensions and not wanting to pollute my base machine with a vscode install). The solution that worked for me, using the nix-shell command via the terminal console to create a reproducible environment. After running nix-shell the command code . successfully started vscode:

  • needed to create a file config.nix in the directory ~/.config/nixpkgs/ with the contents:
{ allowUnfree = true; }

  • in a console, in a directory with a shell.nix file in it with the following code that configures vscode using this extensions mechanism:
{ pkgs ? import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/50c23cd4ff6c8344e0b4d438b027b3afabfe58dd.tar.gz") {} }:

let vscodeWithExtension = (pkgs.vscode-with-extensions.override {
        vscodeExtensions = with pkgs.vscode-extensions; [
              bbenoist.nix
              ms-python.python
              ms-azuretools.vscode-docker
              ms-vscode-remote.remote-ssh
            ] ++ pkgs.vscode-utils.extensionsFromVscodeMarketplace [
              {
                name = "remote-ssh-edit";
                publisher = "ms-vscode-remote";
                version = "0.47.2";
                sha256 = "1hp6gjh4xp2m1xlm1jsdzxw9d8frkiidhph6nvl24d0h8z34w49g";
              }
            ];
          }
    );
in
pkgs.mkShell {
  buildInputs = [
    pkgs.git
    pkgs.ghc
    pkgs.ghcid
    vscodeWithExtension
  ];

  shellHook = ''
    echo hello ghc
  '';

  MY_ENVIRONMENT_VARIABLE = "world";
}
Simon Dowdeswell
  • 1,001
  • 11
  • 19