1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-26 20:01:15 +02:00

Treat empty env var paths as unset

We make sure the env var paths are actually set (ie. not "") before
sending them to the canonicalization function. If we forget to do so,
the user will end up facing a puzzled failed assertion internal error.

We issue a non-failing warning as a stop-gap measure. We could want to
revisit this to issue a detailed failing error message in the future.
This commit is contained in:
Félix Baylac Jacqué 2023-03-01 20:01:36 +01:00 committed by zimbatm
parent 4489def1b3
commit 25300c0ecd
No known key found for this signature in database
GPG key ID: 71BAF6D40C1D63D7
4 changed files with 24 additions and 8 deletions

View file

@ -54,6 +54,18 @@ std::optional<std::string> getEnv(const std::string & key)
return std::string(value);
}
std::optional<std::string> getEnvNonEmpty(const std::string & key) {
auto value = getEnv(key);
if (value == "") {
// TODO: determine whether this should be a warning or an error.
logWarning({
.msg = hintfmt("ignoring the '%1%' env variable, its value has been set to \"\"", key)
});
return std::nullopt;
} else {
return value;
}
}
std::map<std::string, std::string> getEnv()
{