NixOS / NixOS/nix.dev

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

Open
#984 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Nix
Stars
4k
Forks
339
Avg merge
2d 11h
Merged PRs (30d)
7

Description

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!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Open tutorials/first-steps/declarative-shell.html and read the environment-variable and shellHook examples around the reported syntax error. Verify the examples are valid Nix expressions and that the documented environment-variable approach works when evaluated in nix-shell.

Written by the indexing model from the issue text.

Assessment

Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.