-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
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
Finally handle wrappers correctly to make them invisible to applications #150841
Comments
#124556 probably fixed this please test |
Thanks, but no it does not fixes it for the reasons I mentioned above (I even tried with the latest PR in #150079). For reproducibility, here is my
my
output:
and I checked, the binary wrapper contains:
|
scripts getting the wrong $0 is expected behaviour according to the bash manpage:
for bash scripts this may be solvable by having the wrapper set it may also be fundamentally unsolvable for scripts with a |
Thanks for your comment, but I'm not sure to get your point. The manpage only says that Of course, the more robust solution would certainly to add the environment variable directly at the beginning of the script. But it means that we need to know for each scripting language a way to populate properly and robustly the environment variable, which may be hard to do reliably. But if I'm not wrong it's how the python wrapper already works right? After, another solution is imaginable: we can apply the robust solution which edit each script when the language is known, and if not fallback to a generic, language agnostic solution. For
If I did not get your point, maybe you could propose a precise scenario in which my proposed solution fails when packaging a program, and is a regression compared to the current system? |
I like this solution, and am actually wondering if it could be extended to also work with binary programs, e.g. by replacing the interpreter segment of ELF files with a wrapped version. The downside is that wrapped binaries would be less discoverable. |
@tobiasBora i should have been more clear about that, but you did get the gist: it seems very wrong that running a script plain ( re env: please ignore, that was just a red herring i slipped on. |
I don't think that's a real problem: in the case you're describing, you probably wouldn't want to source the environment variables set by the wrapper. It's already quite common to have |
@pennae thanks for the clarification. And indeed, it's something to keep in mind that it might work, or semi-work while today it either works (bash) or crash completely. As far as I know I see only two solutions to this problem:
But considering the above discussion it may also never cause any troubles... |
@ncfavier For elf files, your solution could work, but I'm not enough experimented to say more. But the advantage may be less clear for binaries since as far as I know |
Also note that |
Another failure mode we're not currently experiencing is where the wrapper behavior should not be repeated. Some changes to environment variables would be redundant and potentially harmful if they pile up after multiple self-execs. The same could apply to args, depending on how the wrapped program performs the self-exec. |
If we're airing out all things wrappers, which we probably shouldn't, environmental pollution is antithetical to the encapsulation and hermeticity promises of Nix. Executing the result of a build from another result of a build may (will) give different results. E.g. running a KDE app in the Plasma desktop vs. a "non-DE" WM setup. |
@samueldr And is any proposed solution better with respect to @roberth The solution I can imagine is that the wrapper can also define a random name for an environment variable (why not based on the hash of its path in @samueldr But environmental pollution is sometimes necessary right? For instance I guess that the user may want to define |
Sure, if the user defines it in the user-controlled domain (e.g. their
The list of installed applications viewed by a process shouldn't depend on the parent processes' packaging. So I assume that you're probably missing something. Let's present the issue with environmental pollution with a theoretical GUI/app toolkit [TTK] that needs apps to be wrapped, just like there are some right now in Nixpkgs. "TTK" apps expect runtime libraries. here image loaders, to be provided with some conventions:
Let's package "correctly" application A with the TTKWrapper and wrap it with the plugin path such that it can load additional image types, like Great, application A can now open ico and psd files. Let's package "incorrectly" application B without the TTKWrapper entirely. The application may start correctly even without any environmental manipulation. Some toolkits are resilient about that. This one will only know about the image formats built into TTK. Fine. Now, assume that application A can open application B as a child process. Application B will inherit A's It may not look like a big deal, until you think about further scenarios, like a complete desktop environment made with TTK which seeds the There are actual issues, other than "eww this is impure". Using a This is not the only scenario where it happens. If a programming language runtime uses the environment to resolve dependencies, it's going to fail the same ways (I think python does that?). Any environment change done in a wrapper to "fix" things is, in my opinion, technical debt. Furthermore, more often than not this technical debt is moved from a central core location (e.g. the toolkit) and pushed onto the unsuspecting packagers. The solution to this, sadly, will often be to hook a (hopefully small) code change where the toolkit, or language, reads the environment for such needs, and read it from a static well-known package-dependent location. For example, |
I think so. But AFAICT will scale to binaries; unless I'm missing something, it only concerns itself with |
Thanks a lot for the detailed example, it helps a lot. Concerning the problem with applications installed from unstable on a stable system, I also got a lot of issues due to that (that's part of the reason why I moved my whole system to unstable). Would your proposed solution also solve the problems related to errors about different glibc ABI versions? And could it also be extended to solve the issues related with incompatibilities between different versions of the drivers? (sorry if my last two sentences make no sense, but I think to remember that being able to properly handle drivers in a pure world can be quite challenging, and that opengl often suffers from that) Concerning your proposed solution, I'm not sure to understand who would apply this code change and where ? I'm not sure to understand how it would differ from writing a wrapper that completely forgets all previous environment variables. Also, I agree now that environment variables must sometimes be forgotten, but sometimes as we mentioned it before I think they should be propagated (like when the user configures it). One particular variable that I don't see how to handle properly is certainly the |
Describe the problem
In Nix, wrappers are required to properly configure paths and can cause dirty issues #60260. In this thread, I focus on one issue of wrappers.
So far, wrapping is done using
exec -a "$0" application-unwrapped
. When wrapping an executable (i.e. not a script), I think it works nicely as the program cannot really detect that it is inside a wrapper (if the-a
is forgotten, it can indeed cause troubles as I just experimented it #60260). However, for scripts the$0
variable is not propagated (this seems to be a quite fundamental issue due to the fact that the interpreter of the scripts does not care about$0
): as a consequence, the program thinks that it's name isprogram-unwrapped
. Most of the time it is not a great problem (except that help page may sounds funny with unwrapped paths), but sometimes it can cause more troubles. This is the case notably when the program tries to use$0
to start a new instance of himself (at runtime, or to respawn later, why not in a cron or as a new application...). This is done in carla #117781 but also in chromium #150826 (chromium is a binary, so it's not too much of an issue...) or in Awesome window manager #60229. It requires additional patches, from inside Nixpkgs that may be hard to maintain later and cause additional debugging time from the maintainer.Steps To Reproduce
Steps to reproduce the behavior:
Create a file
myscript.sh
:the file
derivation.nix
:the file
default.nix
:and run:
Expected behavior
I'd expect to see:
Proposed solution
A solution would be not to add a wrapper replacing the script, but to put the wrapper code directly in the interpreter of the script as I proposed it here:
Result:
The text was updated successfully, but these errors were encountered: