NixOS / nix.dev

Official documentation for getting things done with Nix.
https://nix.dev
Creative Commons Attribution Share Alike 4.0 International
2.26k stars 238 forks source link

Issue on page /tutorials/first-steps/declarative-shell.html | Setting environment variables #984

Open mboss37 opened 1 month ago

mboss37 commented 1 month ago

Description

I encountered a syntax error while trying to set an environment variable in nix-shell using the your provided example:

let nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/tarball/nixos-23.11"; pkgs = import nixpkgs { config = {}; overlays = []; }; in

pkgs.mkShellNoCC { packages = with pkgs; [ cowsay lolcat ];

`error: syntax error, unexpected '+'

   at /home/mboss37/nix-configs/shell.nix:12:1:

       11|
       12| +  GREETING = "Hello, Nix!";
         | ^
       13|  }

`

On the same page you have another shellHook example that causes the same issue. Removing the + resolves the syntax error, but I want to confirm if this is the correct approach or if there's a better way to set environment variables.

Thanks!

henrik-ch commented 1 month ago

Hi,

I can confirm that your approach is correct.

The + symbol is shown because we use the unified format to indicate added lines in our examples. This symbol should not be included in your input to nix. Removing the + and using the line GREETING = "Hello, Nix!"; is indeed the correct way to set the environment variable.

You are probably not the first person to encounter this issue. We will consider adding a short explanation to our examples to prevent confusion in the future.

If you have any further questions or run into more issues, feel free to ask. We're here to help!