-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
treat empty NIX_STORE_DIR env vars as unset #7918
Conversation
if (!value) return {}; | ||
auto str = std::string(value); | ||
return !str.empty() ? std::optional<std::string>{str} : std::nullopt; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this could be expressed in terms of getEnv()
? I.e. something like
auto value = getEnv(key);
return value == "" ? std::nullopt : value;
This feels ad-hoc to me. What about The other issue had a bad error message. I would simply make a nice error message on the store URL parse to reject the empty string. |
Oh the title is wrong this is about |
@Ericson2314 I agree with your assessment in general, it's better to report failures than to paper over them. Bor env vars specifically, I think most scripts already don't make the distinction between empty and unset env vars ( |
So I wouldn't mind if we did this for every environment variable --- at least it would be consistent. But for some of them it does matter, e.g. for |
👍 Makes sense.
I think this pattern mostly makes sense for the env variables sent to |
Yeah I think it could be good to make a function that combines |
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.
619d7ca
to
25300c0
Compare
^ is that better? |
Yeah it is better :) |
Co-authored-by: Théophane Hufschmitt <[email protected]>
src/libutil/util.cc
Outdated
auto value = getEnv(key); | ||
if (value == "") { | ||
// TODO: determine whether this should be a warning or an error. | ||
warn("ignoring the '%1%' env variable, its value has been set to \"\"", key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would drop this warning. If empty vars are equivalent to the var not being set, there is no reason to complain about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are not equal on my system at least:
philip@shiki ~> env FOO="" printenv FOO
philip@shiki ~> env printenv FOO
philip@shiki ~ [1]>
one returns ""
and the other status 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I had something set to ""
, I’d be kind of confused if nix ignored it silently.
Anything else before I squash the commits? |
I personally think that silently ignoring configuration paths that have been explicitly set by the user will make debugging such a situation much harder. An env variable that is defined, but empty is likely a code smell/downstream bug, I think warning the user about that makes sense. [Edit]: this post is apparently unclear, apologies. I personally think we should either warn the user and move on with the default value, or fail and throw an error. |
I agree with @NinjaTrappeur that the warning is important for debugging, which is why I asked for it. @edolstra would you be OK if we added the warning after all? I would prefer the error, but I accept the warning as a middle ground. |
@NinjaTrappeur Can you open a new PR for the warning? That will give us something to discuss. |
Motivation
Fixes #6409
Actually written by @NinjaTrappeur
Context
See the above issue ^
We might want to expand the same change to the other env vars, IFF having empty env vars doesn't make sense to them.
Checklist for maintainers
Maintainers: tick if completed or explain if not relevant
tests/**.sh
src/*/tests
tests/nixos/*