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
tup: Let tup passthrough NIX_* env vars #60016
Conversation
I don't think this is a good idea. If people want a pure environment for |
@infinisil Thank you for your feedback! I extended the PR's description because i felt we were not talking about the same thing. I hope this change is now provided with enough context to make it acceptable. |
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.
Ah I see, this looks good to me then, thanks for the explanation!
Why not use |
@FRidh Please realize that scripts generated by
|
Maybe this patch is good enough as a workaround, but I see potential issue with such wildcard-style variable inclusion. Patched tup does not handle adding/removing/renaming of
Suppose I build with environment variable
Expected contents of You have to remove Note that this isn't an issue for |
@xzfc thank you for your feedback. Does it make the patch acceptable for you if it only passed through (with/without adding them to the DB like |
FYI, you can use |
@infinisil thank you, but i was already aware of this and must say that it does not really make the In the end one has to patch the Tupfiles with those 3 |
It still has a wildcard variable. And what about some other possible required variables (like Another idea: concatenate all required variables into a special variable and passthrough this variable.
This way tup will rebuild whenever a variable with prefix Or maybe create an issue in the mainstream issue tracker? |
@xzfc i see that my patch is really not enough (e.g. in cases with I am closing this PR and wil try to get something working that follows your idea with the |
Motivation for this change
tup
prunes all environment variables for all subprocesses that it starts. Some variables likePATH
are passed through. This preventsnix-shell
C and C++ environments from giving the compiler the right include and library folders for compiling/linking with/against external libraries.At least the variables are needed for the typical c/c++ wrapper in nix:
NIX_CFLAGS_COMPILE
NIX_LDFLAGS
NIX_CC_WRAPPER_x86_64_unknown_linux_gnu_TARGET_HOST
(If this is not set in the env, then the compiler wrapper will also not consume the other two vars, which is critical)This PR adds a patch to
tup
which passes through all environment variables that are prefixed withNIX_
in order to provide a painless build experience in e.g. C++ projects with external libs.This only affects the tup workflow in
nix-shell
. (For sandboxed nix build environments, users typically usetup generate
to generate a shell script that performs the build process, becausetup
wants the SUID bit set, which is not allowed withinnix-build
)Example:
Tup project with
hello.cpp
:...and
Tupfile
:When building this with an unpatched
tup
in anix-shell
, you get the following error:The patched version correctly passes through all the nix vars to the compiler wrapper and then it works:
...because this time the compiler got all the include folders right via
NIX_CFLAGS_COMPILE
.(please note that in order to perform this at home one needs to delete the
.tup
directory in the project and reruntup init
because that folder's state would lead to the same old error)An alternative to this patch is prepending the following lines to every tup project's root
Tupfile
:This does also work, but please note that:
nix-shell
, so i'd personally prefertup
not taking these nix-specific env vars away in the first placeNIX_CC_WRAPPER...
env var name is arch- and OS-specific, so this is not a portable addition to tupfiles... Thetup
patch presented does it right, no matter what target platform is selected, because it is generic.Things done
sandbox
innix.conf
on non-NixOS)nix-shell -p nix-review --run "nix-review wip"
./result/bin/
)nix path-info -S
before and after)