Error: syntex error, unespected LET when rebuilding configuration.nix

Hi all,
I’ve just installed Nix OS and I’ve a little problem with the configuration.nix file.
I’ve configured correctly my Nvidia card driver (GTX 1060) and I would like to install only blender from the unstable channel because I need 3.6.2 version to work with.
I’m following this older thread but after I add the line in the solution to configuration.nix and rebuild it with

sudo nixos-rebuild switch

I get this error

error: syntax error, unexpected LET

       at /etc/nixos/configuration.nix:159:3:

          158|
          159|   let
             |   ^
          160|     unstable = import <nixos-unstable> {};
(use '--show-trace' to show detailed location information)
building Nix...
error: syntax error, unexpected LET

       at /etc/nixos/configuration.nix:159:3:

          158|
          159|   let
             |   ^
          160|     unstable = import <nixos-unstable> {};
(use '--show-trace' to show detailed location information)
building the system configuration...
error: syntax error, unexpected LET

       at /etc/nixos/configuration.nix:159:3:

          158|
          159|   let
             |   ^
          160|     unstable = import <nixos-unstable> {};
(use '--show-trace' to show detailed location information)

and I don’t understand what have I done wrong in the syntax.

here the relevant configuration

  # Allow unfree packages
  nixpkgs.config.allowUnfree = true;

  # List packages installed in system profile. To search, run:
  # $ nix search wget
  # environment.systemPackages = with pkgs; [
  # vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default.
  #  wget
  # ];

  let
    unstable = import <nixos-unstable> {};
  in {
    environment.systemPackages = with pkgs; [ 
      vim
      cudaPackages.cudatoolkit 
      unstable.blender 
    ];
  };

what I’m doing wrong?
Also, the packages are indicated correctly for what I want to install?

Thanks in advance

You might want to read the section on the nix language syntax: Nix Language - Nix Reference Manual

But specifically, what you’re doing wrong, is breaking the syntax rules of attrsets. In an attrset, you do name = value;, but you’ve done let <bindings> in { name = value; }. This would be a valid expression, but it’s not a valid entry in an attrset. What you need to do is name = let <bindings> in value; i.ie:

  environment.systemPackages = let
    unstable = import <nixos-unstable> {};
  in with pkgs; [
    ...
  ];
1 Like

Thank you so much for the answer and for the usefull link.