Passing env to nix-shell - Nix

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

Sridhar Ratnakumar

When using nix-shell -i ... is it possible to pass custom environment variables to the chained script interpreter (the command in -i)? Reading the man page I don't see a mention of it.

Sridhar Ratnakumar

Doesn't look like there is a way, however env's -S came to rescue:

#! /usr/bin/env -S"GHC_ENVIRONMENT=-" nix-shell
#! nix-shell -p ghcid
#! nix-shell -p "haskellPackages.ghcWithPackages (p: [p.shower])"
#! nix-shell -i "ghcid -T main"

import Shower (printer)
import System.Environment (getEnv)

main :: IO ()
main = do
  printer =<< getEnv "GHC_ENVIRONMENT"
Jack Henahan

@Sridhar Ratnakumar --command 'export GHC_ENVIRONMENT=hello; return' might do the trick

Sridhar Ratnakumar

I don't think I can use --command, as this is all in the shebang (ctrl+f shebang in man nix-shell)