query
On this page

getEnv

builtins.getEnv

Primop
Docs pulled from | This Revision | about 3 hours ago


Nix manual

Takes 1 arguments

s

getEnv returns the value of the environment variable s, or an empty string if the variable doesn’t exist. This function should be used with care, as it can introduce all sorts of nasty environment dependencies in your Nix expression.

getEnv is used in Nix Packages to locate the file ~/.nixpkgs/config.nix, which contains user-local settings for Nix Packages. (That is, it does a getEnv "HOME" to locate the user’s home directory.)

Noogle detected

Detected Type
getEnv :: String -> String

Implementation

This function is implemented in c++ and is part of the native nix runtime.

src/libexpr/primops.cc:1245

static void prim_getEnv(EvalState & state, const PosIdx pos, Value ** args, Value & v)
{
    std::string name(
        state.forceStringNoCtx(*args[0], pos, "while evaluating the first argument passed to builtins.getEnv"));
    v.mkString(state.settings.restrictEval || state.settings.pureEval ? "" : getEnv(name).value_or(""), state.mem);
}