lima-bin: Fix completion generation#331782
Conversation
|
@YorikSar Thank you for catching that. I'll still have to reproduce this. Is autopatchelf not run in the fixup phase as default? If so, then I'd move the install shell completion code to the postFixup phase. That seems cleaner to me because then we can profit from the default and don't have to manually patch. |
|
@YorikSar I could reproduce it 😃. Unfortunately, the installCheck phase fails with a go runtime error: Running phase: installCheckPhase
SIGSEGV: segmentation violation
PC=0xfffff7de1c4c m=5 sigcode=1 addr=0x60
signal arrived during cgo execution
goroutine 1 gp=0x40000021c0 m=5 mp=0x4000180008 [syscall]:
runtime.cgocall(0x11498, 0x40007a4ba8)
/opt/hostedtoolcache/go/1.22.2/x64/src/runtime/cgocall.go:157 +0x44 fp=0x40007a4b70 sp=0x40007a4b30 pc=0x189d4
os/user._Cfunc_mygetpwuid_r(0x3e8, 0x40001a8c00, 0x400, 0x4000453d90, 0x4000453d94)
_cgo_gotypes.go:163 +0x3c fp=0x40007a4ba0 sp=0x40007a4b70 pc=0x17d02c
os/user._C_getpwuid_r(0x3e8, 0x40001a8c00, 0x400)
...However, I found a working solution. Instead of applying the autopatchelf twice, can you try the following and move the installShellCompletion part to the fixupPhase like this: fixupPhase = ''
runHook preFixup
runHook postFixup
# the shell completion only works with a patched $out/bin/limactl and therefore
# needs to run after the autopatchelf hook is executed in postFixup.
installShellCompletion --cmd limactl \
--bash <($out/bin/limactl completion bash) \
--fish <($out/bin/limactl completion fish) \
--zsh <($out/bin/limactl completion zsh)
'';This should then work without any go runtime error. |
916c118 to
4ab23fb
Compare
|
@tricktron Thanks for the review.
You're linking to
I thought about putting it in the fixup phase, but I didn't like that all fixups will not be applied to generated completion scripts. It seems that scripts are not affected by fixups at this moment though, so I've moved it to the fixup phase as you suggested. |
tricktron
left a comment
There was a problem hiding this comment.
Seems to now build again on aarch64-linux. Also builds on aarch64-darwin. Looking good, thank you😃.
There was a problem hiding this comment.
This is broken. fixupPhase does quite a lot of stuff and when they override it like that, it will no longer happen. If it really needs to go to fixupPhase, it should be put it in postFixup hook.
There was a problem hiding this comment.
@jtojnar This does not work unfortunately because the postFixup runs before the binary patching. Anyway I think I found a way to manually patch this.
There was a problem hiding this comment.
postFixup should not run before binary patching. In case this really doesn't work, try using distPhase or postDistPhase
There was a problem hiding this comment.
@SuperSandro2000 No, postFixup does not work.
EDIT: Wow, both . This made the build work and I assumed it worked. However, no completions file were generated in result/share. So I think that these phases are not executed at all. So this does not solve the problem.distPhase and postDist work
I have never heard about this phase? What does it do and when is it run?
There was a problem hiding this comment.
@SuperSandro2000 runHook first runs implicit hook, then explicit ones, so postFixup will be called before autoPatchelfHook's explicit autoPatchelfPostFixup hook. I've added another explicit postFixupHook from installPhase. I hope that keeps abstractions somewhat solid. I don't like the idea of relying on distPhase not doing anything useful and running the last in the list.
|
@YorikSar I found another way to manually patch the binary following the manual steps here: https://nixos.wiki/wiki/Packaging/Binaries. Basically, we go back to Here is the diff: diff --git a/pkgs/applications/virtualization/lima/bin.nix b/pkgs/applications/virtualization/lima/bin.nix
index fa94db5e1169..897cbac237de 100644
--- a/pkgs/applications/virtualization/lima/bin.nix
+++ b/pkgs/applications/virtualization/lima/bin.nix
@@ -1,4 +1,4 @@
-{ stdenvNoCC
+{ stdenv
, lib
, fetchurl
, writeScript
@@ -37,38 +37,31 @@ let
};
};
in
-stdenvNoCC.mkDerivation {
+stdenv.mkDerivation {
inherit version;
pname = "lima";
src = fetchurl {
- inherit (dist.${stdenvNoCC.hostPlatform.system} or
- (throw "Unsupported system: ${stdenvNoCC.hostPlatform.system}")) url sha256;
+ inherit (dist.${stdenv.hostPlatform.system} or
+ (throw "Unsupported system: ${stdenv.hostPlatform.system}")) url sha256;
};
sourceRoot = ".";
nativeBuildInputs = [ makeBinaryWrapper installShellFiles ]
- ++ lib.optionals stdenvNoCC.isLinux [ autoPatchelfHook ];
+ ++ lib.optionals stdenv.isLinux [ autoPatchelfHook ];
installPhase = ''
runHook preInstall
mkdir -p $out
cp -r bin share $out
- chmod +x $out/bin/limactl
+ patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" $out/bin/limactl
wrapProgram $out/bin/limactl \
--prefix PATH : ${lib.makeBinPath [ qemu ]}
- runHook postInstall
- '';
-
- fixupPhase = ''
- runHook preFixup
- runHook postFixup
- # the shell completion only works with a patched $out/bin/limactl and so
- # needs to run after the autoPatchelfHook is executed in postFixup.
installShellCompletion --cmd limactl \
--bash <($out/bin/limactl completion bash) \
--fish <($out/bin/limactl completion fish) \
--zsh <($out/bin/limactl completion zsh)
+ runHook postInstall
'';
doInstallCheck = true;
@@ -79,7 +72,7 @@ stdenvNoCC.mkDerivation {
# Stripping removes entitlements of the binary on Darwin making it non-operational.
# Therefore, disable stripping on Darwin.
- dontStrip = stdenvNoCC.isDarwin;
+ dontStrip = stdenv.isDarwin;
passthru.updateScript =
let |
|
@YorikSar EDIT: See #331782 (comment) |
It was running unpatched binary which was failing and thus generating empty output. After NixOS#289517 installShellCompletion errors out because of this, which lead to broken build. Move installShellCompletion call to after autoPatchelfHook in fixupPhase.
|
@tricktron I don't like the idea of pulling in the compiler just to patch the binary. It seems like you're reimplementing what autopatchelf already does, but using NIX_CC. I don't see the benefit of it compared to my original version. I've modified it to add a postFixup hook to run after everything is patched. It seems cleaner than overriding fixupPhase entirely and less intrusive than pulling in the compiler or manually patching the binary. |
4ab23fb to
a58bfa1
Compare
@YorikSar I did not know about the |
|
It appears to still be failing in same way after this merged, see |
|
@mjgallag you’re pointing to upgrade logs, where a different version of lima is being built. Also, lines before this error are different: This means that the binary was executed, but failed. Before this PR, the binary could not have been executed. All in all, it seems like the new version does something different and fails with a different issue. |
|
Found this in the diff: lima-vm/lima@v0.22.0...v0.23.2#diff-95475f7f5560ba438d76bce7e63eb2f2d63b59438023d2af973e941510cdcf9cR100 - it now checks home directory on each run. My guess is that it fails here. You could try setting LIMA_HOME to something in the workdir to avoid that. |
Description of changes
It was running unpatched binary which was failing and thus generating empty output. After #289517 installShellCompletion errors out because of this, which lead to broken build.
Add a call to
autoPatchelfto patch limactl binary before generating completion files.Things done
nix.conf? (See Nix manual)sandbox = relaxedsandbox = truenix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)Add a 👍 reaction to pull requests you find important.