Nixos-rebuild fails to build a configuration with vscode-with-extensions even though the expression works in nix repl

I am just starting using Nix and NixOS and I am trying to have my environment as declarative as I can. However, I am struggling to get vscode with extensions to work. I tried to follow this this wiki page and placed the following in my /etc/nixos/configuration.nix (I obfuscated the actual username and omitted some fields):

  users.users.myuser = {
    isNormalUser = true;
    extraGroups = [ "networkmanager" "wheel" ];
    packages = with pkgs; [
      firefox
      git
      yakuake
      sbt
      vscode-with-extensions.override {
        vscode = vscodium;
        vscodeExtensions = with vscode-extensions; [
          bbenoist.nix
          vscodevim.vim
          scalameta.metals
        ];
      }
    ];
  };

Without vscode-with-extensions, I run nixos-rebuild switch and it works fine. But with the vscode-with-extensions, I get this error:

$ sudo nixos-rebuild switch 
building Nix...
building the system configuration...
error: A definition for option `users.users.myuser.packages.[definition 1-entry 5]' is not of type `package'. Definition values:
       - In `/etc/nixos/configuration.nix': <function, args: {buildEnv, lib, makeWrapper, runCommand, stdenv, vscode, vscodeExtensions?}>
(use '--show-trace' to show detailed location information)

By the message value, I thought something could be wrong with the way I wrote the vscode-with-extensions portion, so I tried to debug in nix repl. But it turns out I can build the package just fine:

$ NIXPKGS_ALLOW_UNFREE=1 nix repl
Welcome to Nix 2.8.1. Type :? for help.

nix-repl> :l <nixpkgs>           
Added 16516 variables.

nix-repl> my-vscode = vscode-with-extensions.override {
            vscode = vscodium;
            vscodeExtensions = with vscode-extensions; [
              bbenoist.nix
              vscodevim.vim
              scalameta.metals
            ];
          }

nix-repl> my-vscode
«derivation /nix/store/jncs3p3m2qfkx880ds17jd7hyrdnq28y-vscodium-with-extensions-1.69.2.drv»

nix-repl> :b my-vscode

This derivation produced the following outputs:
  out -> /nix/store/ficjcslxa0pn264v7aflxq5xkq91kiyy-vscodium-with-extensions-1.69.2

How can the same expression work in nix repl but cause the NixOS configuration to fail building? What am I missing?

You need parens around your function call. [ f a ] is a list with 2 elements. [ (f a) ] is a list with one element, the result of applying f to a.

2 Likes

so, specifically, this part should be enclosed in parens - that tripped me up when I first started using Nix as well.

3 Likes