aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/environment-variables.hh
diff options
context:
space:
mode:
authorTom Hubrecht <github@mail.hubrecht.ovh>2024-05-28 10:50:54 +0200
committerTom Hubrecht <github@mail.hubrecht.ovh>2024-05-28 11:29:29 +0200
commit6fd6795bc4faed644c5f3abafdcb21638a119342 (patch)
tree29c0dfa1f90a44af6ca22a1985b45b13505f83c7 /src/libutil/environment-variables.hh
parent0b91a4b0ec79c27ee36d8a7e2afd7737cb825b65 (diff)
util.{hh,cc}: Split out environment-variables.{hh,cc}
Change-Id: Icff0aa33fda5147bd5dbe256a0b9d6a6c8a2c3f6
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);
+
+}