-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
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
setup.sh: substitute uses only valid bash names #14907
Conversation
I'm convinced the filtering is meant to reduce the risk of accidental substitution. It's a convention that standard global env vars are all-uppercase, and typically you have large amount of those in the env. On the other hand, the main intended purpose of |
The first change seems good to me. It's a bit unfortunate for |
@aszlig brought the same objection. However in my opinion the worst an automatic computing system can to is silently ignore user input. |
If we do not change this filtering, we should at least document it in http://nixos.org/nixpkgs/manual/#fun-substituteAll To me there seems a more pressing "silent" problem: if you forget to put |
How about files where |
I don't think you should use |
bash variable names may only contain alphanumeric ASCII-symbols and _, and must not start with a number. Nix expression attribute names however might contain nearly every character (in particular spaces and dashes). Previously, a substitution that was not a valid bash name would be expanded to an empty string. This commit introduce a check that throws a (hopefully) helpful error when a wrong name is used in a substitution.
bc6fffd
to
3bb93c1
Compare
@vcunat I added the filter again and included documentation. The first fallout of the changes is already visible, the documentation travis build is failing. If I did everything right, all of these failures should have been bugs from the get-go, though. |
Are you sure about the failures? It seems like stdenv won't even bootstrap.
|
OMG, the implementation has been crappy all along – it uses |
Let me properly test a fix for that. |
It got to building the final gcc so far, so it's probably OK. @Profpatsch: checkout Profpatsch#1 ;-) |
The filtering of environment variables that start with an uppercase letter is documented in the manual.
3bb93c1
to
a2d38bc
Compare
@vcunat I changed it, should we make Travis build everything? :) |
@vcunat What’s the next steps here? Should we merge into staging? |
@Profpatsch sounds like the next logical step |
Closed by 62616ec. Thanks! |
I think this PR is what causes that mass-breakage on darwin: http://hydra.nixos.org/build/34945843/nixlog/1/raw I assume the bash used at that point behaves differently, or something similar, as there seem to be no larger problems on the two linux platforms. |
Unfortunately, this leaves me in kind-of stuck situation, as I can't well test darwin stuff and I don't like bringing that mass failure to master either... |
Hm, do you think the |
And maybe an output of for e in $(set); do
if ! [[ "$varName" =~ ^[a-zA-Z_]+[a-zA-Z0-9_]*$ ]]; then
echo "$varName"
fi
done |
I think using What I think is the problem on Darwin is that the contents of a function is recognized as a variable name here. For example if I run
While |
I don't know, but in this case the largest stumbling block seems that |
@vcunat: Hm, what about doing that portion in C instead... like this (untested): #include <stdio.h>
int main(int argc, char **argv, char **envp) {
char *tmp = NULL;
fputs("local -a args=(", stdout);
while (*envp != NULL) {
if (tmp != NULL) putchar(' ');
fputs("'--subst-var' '", stdout);
tmp = *envp++;
while (*tmp != 0 && *tmp != '=') {
if (*tmp == '\'')
fputs("'\\''", stdout);
else
putchar(*tmp);
tmp++;
}
putchar('\'');
}
puts(")");
return 0;
} This could then be simply |
OTOH... what about replacing the whole set of substitute* functions by a single small C program ( |
Yeah, writing a C utility for all those substitute* functions seems a good longer-term goal. (Github won't allow to reopen this PR anymore.) |
We might finally make it an error when |
@vcunat: Mhm, that might be a good idea for a lot of these |
We really need a good DSL like Elm wraps JavaScript, but for Shell. Something simple, but well typed. |
If you know a good typed shell-suitable language, please, tell me. (Getting further from the topic, I'm afraid.) |
Scala with https://github.com/lihaoyi/Ammonite ;-) |
lol scala. |
Please, let's move this discussion elsewhere (sorry for bringing it up). Let's focus on the goal of the PR. Thank you! |
I'm getting a bunch of
Seemingly from:
in cc-wrapper.nix. |
@copumpkin Seeing the same thing. |
Yes, explained in 577fefe1d36. (We've always been attempting those bogus substitutions, only it was silent.) |
@vcunat I'm not sure I understand what's actually happening here. Does that mean someone's trying to pass in a key called |
@copumpkin: it's a false positive. The problem is that the string is in a multi-line variable (a build phase) and |
Ah yes, if you use /usr/bin/env, we have no control (literally, the OS wouldn't let us overwrite it even if we wanted to) over where that points in Darwin 😦 |
In this case |
Hmm, then I'm confused, because we use the usual GNU
|
@copumpkin: yes, but it wasn't so at some point during bootstrapping, at least according to my comment on 81df035. You can try before that commit yourself. |
bash variable names may only contain alphanumeric ASCII-symbols and _,
and must not start with a number. Nix expression attribute names however
might contain nearly every character (in particular spaces and dashes).
Previously, a substitution that was not a valid bash name would be
expanded to an empty string. This commit introduce a check that throws
a (hopefully) helpful error when a wrong name is used in a substitution.
That was discovered by chexxor when it happened to me in a substitution.
Additionally, substituteAll previously filtered out all environment
variables starting with an uppercase letter. That increased the number
of silently(!) ignored envvars (and nix attributes) even further.
Because it was quite arbitrary, it is removed.
This will trigger a mass rebuild.