function Env.arch
Returns the CPU architecture.
Returns a string describing the CPU architecture, such as
“x86_64”, “aarch64”, etc.
function Env.aspect_cli_version
Returns the version of the Aspect CLI.
function Env.aspect_root_dir
Returns the Aspect project root directory — the anchor for axl / config loading.
Found by walking upwards from the current working directory looking
for an
.aspect/version.axl or MODULE.aspect marker. Falls back
to the deepest Bazel workspace marker (MODULE.bazel, WORKSPACE,
etc.) so a pure-Bazel monorepo still resolves to a sane project
anchor, and finally to the current working directory if no marker
exists anywhere.
Distinct from the Bazel workspace root — bazelrc discovery and
bazel info workspace use the deepest Bazel marker, which can
differ when a Bazel sub-workspace sits under an Aspect root.
function Env.bazel_root_dir
Returns the Bazel workspace root directory — the anchor for bazelrc discovery,
bazel info workspace, and BES output paths.
Found by walking upwards from the current working directory looking
for a MODULE.bazel / WORKSPACE marker. Falls back to the deepest
.aspect/version.axl or MODULE.aspect marker so a pure-Aspect
workspace still resolves, and finally to the current working
directory if no marker exists anywhere.
Distinct from the Aspect project root — axl / config loading uses
the deepest .aspect/ marker, which can differ when a Bazel
sub-workspace sits under an Aspect root.
function Env.current_dir
Returns the current working directory as a path.
Platform-specific behavior
This function currently corresponds to the
getcwd function on Unix
and the GetCurrentDirectoryW function on Windows.
Errors
Fails if the current working directory value is invalid.
Possible cases:
- Current directory does not exist.
- There are insufficient permissions to access the current directory.
function Env.current_exe
function Env.git_root_dir
Returns the git repository root — the directory containing
.git — or None when not inside a git repository.
function Env.home_dir
Returns the path of the current user’s home directory if known.
This may return
None if getting the directory fails or if the platform does not have user home directories.
For storing user data and configuration it is often preferable to use more specific directories.
For example, XDG Base Directories on Unix or the LOCALAPPDATA and APPDATA environment variables on Windows.
Unix
- Returns the value of the ‘HOME’ environment variable if it is set (including to an empty string).
- Otherwise, it tries to determine the home directory by invoking the
getpwuid_rfunction using the UID of the current user. An empty home directory field returned from thegetpwuid_rfunction is considered to be a valid value. - Returns
Noneif the current user has no entry in the /etc/passwd file.
- Returns the value of the ‘USERPROFILE’ environment variable if it is set, and is not an empty string.
- Otherwise,
GetUserProfileDirectoryis used to return the path. This may change in the future.
None.
function Env.os
Returns the operating system name.
Returns a string describing the operating system in use, such as
“linux”, “macos”, “windows”, etc.
function Env.remove_var
Removes an environment variable from the current process.
Has no effect if the variable is not set. Subsequent
var() calls will
return None for the removed variable.
function Env.set_var
Sets an environment variable for the current process.
This affects all subsequent
var() calls and any child processes spawned
after this call. Use with care — environment variables are global process
state.
function Env.temp_dir
Returns the path of a temporary directory.
The temporary directory may be shared among users, or between processes
with different privileges; thus, the creation of any files or directories
in the temporary directory must use a secure method to create a uniquely
named file. Creating a file or directory with a fixed or predictable name
may result in “insecure temporary file” security vulnerabilities. Consider
using a crate that securely creates temporary files or directories.
Note that the returned value may be a symbolic link, not a directory.
Platform-specific behavior
On Unix, returns the value of the
TMPDIR environment variable if it is
set, otherwise the value is OS-specific:
- On Darwin-based OSes (macOS, iOS, etc) it returns the directory provided
by
confstr(_CS_DARWIN_USER_TEMP_DIR, ...), as recommended by Apple’s security guidelines. - On all other unix-based OSes, it returns
/tmp.
GetTempPath2 /
GetTempPath, which this function uses internally.
function Env.var
Fetches the environment variable key from the current process.
function Env.vars
Returns an iterator of (variable, value) pairs of strings, for all the environment variables of the current process.
The returned iterator contains a snapshot of the process’s environment
variables at the time of this invocation. Modifications to environment
variables afterwards will not be reflected in the returned iterator.

