Why does visual studio code installation fail on nixos on wsl

223 views Asked by At

After installing nixos on wsl. I want to install visual studio code on nixos.

to install nixos on wsl: https://github.com/nix-community/NixOS-WSL and you need to run this 2 lines before sudo nixos-rebuild switch

sudo nix-channel --add  https://nixos.org/channels/nixos-23.11 nixos
sudo nix-channel --update

the command nixos-rebuild switch works. I have tested it by installing git only

I followed the instruction to install vscode: https://nixos.wiki/wiki/Visual_Studio_Code

/etc/nixos/configuration.nix look like that:

# Edit this configuration file to define what should be installed on
# your system. Help is available in the configuration.nix(5) man page, on
# https://search.nixos.org/options and in the NixOS manual (`nixos-help`).

# NixOS-WSL specific options are documented on the NixOS-WSL repository:
# https://github.com/nix-community/NixOS-WSL

{ config, lib, pkgs, ... }:

{
  imports = [
    # include NixOS-WSL modules
    <nixos-wsl/modules>
  ];

  wsl.enable = true;
  wsl.defaultUser = "nixos";
  environment.systemPackages = [
    pkgs.git
    pkgs.vscode
  ];


  # This value determines the NixOS release from which the default
  # settings for stateful data, like file locations and database versions
  # on your system were taken. It's perfectly fine and recommended to leave
  # this value at the release version of the first install of this system.
  # Before changing this value read the documentation for this option
  # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
  system.stateVersion = "23.05"; # Did you read the comment?
}

building Nix... building the system configuration...

error: … while calling the 'head' builtin

     at /nix/store/d3qda808yhlkqwaffvq34i4ks2c5lmxc-nixos-23.11/nixos/lib/attrsets.nix:850:11:

      849|         || pred here (elemAt values 1) (head values) then
      850|           head values
         |           ^
      851|         else

   … while evaluating the attribute 'value'

     at /nix/store/d3qda808yhlkqwaffvq34i4ks2c5lmxc-nixos-23.11/nixos/lib/modules.nix:807:9:

      806|     in warnDeprecation opt //
      807|       { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
         |         ^
      808|         inherit (res.defsFinal') highestPrio;

   (stack trace truncated; use '--show-trace' to show the full trace)

   error: Package ‘vscode-1.84.2’ in /nix/store/d3qda808yhlkqwaffvq34i4ks2c5lmxc-nixos-23.11/nixos/pkgs/applications/editors/vscode/vscode.nix:85

has an unfree license (‘unfree’), refusing to evaluate.

   a) To temporarily allow unfree packages, you can use an environment variable
      for a single invocation of the nix tools.

        $ export NIXPKGS_ALLOW_UNFREE=1

      Note: When using `nix shell`, `nix build`, `nix develop`, etc with a flake,
            then pass `--impure` in order to allow use of environment variables.

   b) For `nixos-rebuild` you can set
     { nixpkgs.config.allowUnfree = true; }
   in configuration.nix to override this.

   Alternatively you can configure a predicate to allow specific packages:
     { nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
         "vscode"
       ];
     }

   c) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add
     { allowUnfree = true; }
   to ~/.config/nixpkgs/config.nix.

It doesn't work.

1

There are 1 answers

0
bug On

The error message tells you everything you need to know, which is that the vscode package has an unfree software license, which you need to explicitly allow in order to install. It also gives you several options for how to do this:

b) For `nixos-rebuild` you can set
  { nixpkgs.config.allowUnfree = true; }
in configuration.nix to override this.

Alternatively you can configure a predicate to allow specific packages:
  { nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
      "vscode"
    ];
  }

You can choose either solution depending on how careful you like to be about unfree software, just be aware that the {} brackets shown are meant to represent the top-level {} brackets in your configuration.nix, so they so do not need to be copied.

Alternatively... you can simply install the vscodium package instead, which does not contain any unfree code or trademarks (or annoying telemetry)!