Nix 2.26.3
Nix, the purely functional package manager; unstable internal interfaces
 
Loading...
Searching...
No Matches
environment-variables.hh File Reference
#include <optional>
#include "types.hh"
#include "file-path.hh"

Go to the source code of this file.

Functions

std::optional< std::string > nix::getEnv (const std::string &key)
 
std::optional< OsStringnix::getEnvOs (const OsString &key)
 
std::optional< std::string > nix::getEnvNonEmpty (const std::string &key)
 
std::map< std::string, std::string > nix::getEnv ()
 
int nix::setEnv (const char *name, const char *value)
 
int nix::setEnvOs (const OsString &name, const OsString &value)
 
void nix::clearEnv ()
 
void nix::replaceEnv (const std::map< std::string, std::string > &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]

std::map< std::string, std::string > 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()

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

Like getEnv, but using OsString to avoid coercions.

◆ replaceEnv()

void nix::replaceEnv ( const std::map< std::string, std::string > & newEnv)

Replace the entire environment with the given one.

◆ setEnv()

int 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.

◆ setEnvOs()

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

Like setEnv, but using OsString to avoid coercions.