aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/environment-variables.hh
diff options
context:
space:
mode:
authorjade <lix@jade.fyi>2024-05-30 02:33:05 +0000
committerGerrit Code Review <gerrit@lix-systems>2024-05-30 02:33:05 +0000
commit562ff516ab27b8e98490646dd30ac96e7e2c36bb (patch)
tree1798a20b33da0101bd91acf7da26c891f0cda620 /src/libutil/environment-variables.hh
parentc71f21da3ac4d95ef9a42a26416ccee71639dbd6 (diff)
parenta39ba22ff7112cd3984bbf28d8610d84dd525a0f (diff)
Merge changes from topic "libutil-split" into main
* changes: util.hh: Delete remaining file and clean up headers util.hh: Move nativeSystem to local-derivation-goal.cc util.hh: Move stuff to types.hh util.cc: Delete remaining file util.{hh,cc}: Move ignoreException to error.{hh,cc} util.{hh,cc}: Split out namespaces.{hh,cc} util.{hh,cc}: Split out users.{hh,cc} util.{hh,cc}: Split out strings.{hh,cc} util.{hh,cc}: Split out unix-domain-socket.{hh,cc} util.{hh,cc}: Split out child.{hh,cc} util.{hh,cc}: Split out current-process.{hh,cc} util.{hh,cc}: Split out processes.{hh,cc} util.{hh,cc}: Split out file-descriptor.{hh,cc} util.{hh,cc}: Split out file-system.{hh,cc} util.{hh,cc}: Split out terminal.{hh,cc} util.{hh,cc}: Split out environment-variables.{hh,cc}
Diffstat (limited to 'src/libutil/environment-variables.hh')
-rw-r--r--src/libutil/environment-variables.hh42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/libutil/environment-variables.hh b/src/libutil/environment-variables.hh
new file mode 100644
index 000000000..784b95921
--- /dev/null
+++ b/src/libutil/environment-variables.hh
@@ -0,0 +1,42 @@
+#pragma once
+/**
+ * @file
+ *
+ * Utilities for working with the current process's environment
+ * variables.
+ */
+
+#include <map>
+#include <optional>
+#include <string>
+
+
+namespace nix {
+
+/**
+ * @return an environment variable.
+ */
+std::optional<std::string> getEnv(const std::string & key);
+
+/**
+ * @return a non empty environment variable. Returns nullopt if the env
+ * variable is set to ""
+ */
+std::optional<std::string> getEnvNonEmpty(const std::string & key);
+
+/**
+ * Get the entire environment.
+ */
+std::map<std::string, std::string> getEnv();
+
+/**
+ * Clear the environment.
+ */
+void clearEnv();
+
+/**
+ * Replace the entire environment with the given one.
+ */
+void replaceEnv(const std::map<std::string, std::string> & newEnv);
+
+}