Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
environment-variables.hh File Reference
#include <optional>
#include "nix/util/types.hh"
#include "nix/util/os-string.hh"

Go to the source code of this file.

Functions

std::optional< std::string > nix::getEnv (const std::string &key)
std::optional< OsString > nix::getEnvOs (const OsString &key)
OsStringMap nix::getEnvOs ()
std::optional< std::string > nix::getEnvNonEmpty (const std::string &key)
std::optional< OsString > nix::getEnvOsNonEmpty (const OsString &key)
StringMap nix::getEnv ()
void nix::setEnv (const char *name, const char *value)
void nix::setEnvOs (const OsString &name, const OsString &value)
void nix::unsetEnv (const char *name)
void nix::unsetEnvOs (const OsChar *name)
void nix::clearEnv ()
void nix::replaceEnv (const StringMap &newEnv)

Detailed Description

Utilities for working with the current process's environment variables.

Function Documentation

◆ clearEnv()

void nix::clearEnv ( )

Clear the environment.

◆ getEnv() [1/2]

StringMap nix::getEnv ( )

Get the entire environment.

◆ getEnv() [2/2]

std::optional< std::string > nix::getEnv ( const std::string & key)
Returns
an environment variable.

◆ getEnvNonEmpty()

std::optional< std::string > nix::getEnvNonEmpty ( const std::string & key)
Returns
a non empty environment variable. Returns nullopt if the env variable is set to ""

◆ getEnvOs() [1/2]

OsStringMap nix::getEnvOs ( )

Like getEnv, but using OsString to avoid coercions.

◆ getEnvOs() [2/2]

std::optional< OsString > nix::getEnvOs ( const OsString & key)

Like getEnv, but using OsString to avoid coercions.

◆ getEnvOsNonEmpty()

std::optional< OsString > nix::getEnvOsNonEmpty ( const OsString & key)

Like getEnvNonEmpty, but using OsString to avoid coercions. Returns nullopt if the env variable is not set or set to "".

◆ replaceEnv()

void nix::replaceEnv ( const StringMap & newEnv)

Replace the entire environment with the given one.

◆ setEnv()

void nix::setEnv ( const char * name,
const char * value )

Like POSIX setenv, but always overrides.

We don't need the non-overriding version, and this is easier to reimplement on Windows.

Exceptions
SystemErroron failure

◆ setEnvOs()

void nix::setEnvOs ( const OsString & name,
const OsString & value )

Like setEnv, but using OsString to avoid coercions.

◆ unsetEnv()

void nix::unsetEnv ( const char * name)

Like POSIX unsetenv, on every platform.

Unsetting a variable that is not set succeeds.

Exceptions
SystemErroron failure

◆ unsetEnvOs()

void nix::unsetEnvOs ( const OsChar * name)

Like unsetEnv, but using OsChar to avoid coercions.