Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mboss37 opened this issue May 19, 2024 · 1 comment

Comments

@mboss37
Copy link

mboss37 commented May 19, 2024

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
];

  • GREETING = "Hello, Nix!";
    }

Error Message

`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
Copy link
Contributor

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants