-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
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
buildEnv: better warning and error messages #134215
Conversation
Could you add a test in |
@roberth not the scope of this PR |
Sure, if you don't mind it breaking in the future. Don't you already have an example? I'm not asking you to write a big test suite; just a test case. |
The change is a strict relaxation of builds, this can be logically seen from the refactored conditional expressions. Example: currently the zulu16 package contains a dangling symlink,
After the change, you get a warning instead:
|
What does everyone think about the relaxation of dangling symlinks? It could be argued that in some cases it defers failure, therefore breaks a fail-early expectation. But I am guessing that it fixes more failing builds than it lengthens. In any case, I can be convinced of the opposite. But the added clarity of error messages is dearly needed. |
Right, I assumed you had a valid use case. Just improving the error message seems like a better solution if you were able to fix your input. |
I wrote a test for you, and it's failing: diff --git a/pkgs/build-support/buildenv/test.nix b/pkgs/build-support/buildenv/test.nix
new file mode 100644
index 00000000000..ea445fe7278
--- /dev/null
+++ b/pkgs/build-support/buildenv/test.nix
@@ -0,0 +1,18 @@
+{ buildEnv, runCommand }: let
+ danglingSymlink = runCommand "danglingSymlink" {} ''
+ mkdir $out
+ ln -s /does/not/exist $out/bin
+ '';
+ collidingDir = runCommand "collidingDir" {} ''
+ mkdir -p $out/bin
+ echo foo > $out/bin/foo
+ '';
+ result = buildEnv {
+ name = "regression-for-issue-82685";
+ paths = [ danglingSymlink collidingDir ];
+ };
+in
+ runCommand "check" {} ''
+ [ "$(cat ${result}/bin/foo)" = foo ]
+ ''
+
diff --git a/pkgs/test/default.nix b/pkgs/test/default.nix
index ebf732839ce..5189ff8e1fb 100644
--- a/pkgs/test/default.nix
+++ b/pkgs/test/default.nix
@@ -55,4 +55,6 @@ with pkgs;
trivial-overriding = callPackage ../build-support/trivial-builders/test-overriding.nix {};
writers = callPackage ../build-support/writers/test.nix {};
+
+ buildEnv = callPackage ../build-support/buildenv/test.nix {};
} Ouput:
It really looks like #82685 so I suspect something is off. |
Thanks for the test @symphorien, I included it in the PR. The error was that the dangling symlink check only happened if there was a colliding file before it in the env. I fixed it so that the check and skip happens first. This results in two changes to previous buildEnv behavior:
Are these acceptable changes? Are there any other concerns regarding this PR? |
@infinisil wrote this though NixOS/nix#4790, which is for the builtin builder used by nix-env. A symlink can become valid on a system when it has an absolute path. I am not aware of an instance of this. |
@roberth that's indeed relevant here. The unpleasant thing with symlinks that dangle during merging is that they cannot be merged like directories. I think the greatest common divisior in this case is creating dangling symlinks with a warning, and failing on collision with a clear error message. |
I think dangling symlinks should be handled the same as in normal derivations, which currently allow them just fine: pkgs.runCommand "etc" {} ''
ln -s /etc $out
'' And I think they should be allowed, because:
|
I'm all in favor of a warning for dangling symlinks though |
This PR looks good to me. |
New warning format:
I have trouble with including tests for these changes, because what needs to be tested is how the build fails, which in turn triggers an evaluation failure. Could try running nix in the sandbox, but meh. So for now scratch the tests. I've tested the following scenarios manually:
and all of them correctly fail with understandable error messages. |
You might be able to pull it off by pulling the |
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.
lgtm, but I don't really know perl.
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.
code lgtm
I'm getting an error on my hydra instance (which builds staging), and I think it might be related to this:
The $extraPrefix seems to be declared further down the file. I don't know much about perl, but I could imagine that being an issue here. Reproduce with |
Yes, this error broke really lots of things. It will be reverted if not fixed quickly. Example failures: https://hydra.nixos.org/eval/1697428 |
It's probably as simple as moving the my $extraPrefix up, but I'm not sure how correct that is. It seems to be working locally for me though (at least fixes the build). |
I added the extraPrefix part after the reviews, that was a mistake. Thanks for pointing the error out @Mindavi. This needs to be fixed in another PR. |
buildenv: fix regression introduced by #134215
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/trouble-sleeping-problem-with-sleep-command/19101/7 |
Motivation for this change
Detailed error messages for buildEnv failures. Also, warn the user about dangling symlinks instead of dying with a confusing error message. Warning about dangling symlinks is more inline with nix's buildenv.cc as well.
Obviates #82685.
Elucidates LnL7/nix-darwin#320.
Things done
sandbox
innix.conf
on non-NixOS linux)