Replies: 19 comments 6 replies
-
This is also reported by someone else in the workers-cli repo |
Beta Was this translation helpful? Give feedback.
-
what does |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Hmm it sure looks like the libraries are there. I am not sure what would cause |
Beta Was this translation helpful? Give feedback.
-
In that answer under solution one (manual), part of what's happening is that a not-found library is being resolved, while in our case here all of the binaries are present and have known paths. |
Beta Was this translation helpful? Give feedback.
-
Following along further with that SE answer, I'm trying to run it with steam-run but encountering another issue first lol |
Beta Was this translation helpful? Give feedback.
-
The problem can be located with the
#!/bin/sh
export SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt # https://github.com/cloudflare/workers-sdk/issues/3264
exec steam-run /path/to/workerd.orig "$@" Cloudflare should compile workerd as a static binary, as it has no interesting dependencies anyway. |
Beta Was this translation helpful? Give feedback.
-
@ckiee your comment led me to figure out what happened. Thank you!
Checking the statically linked interpreter of $ file $(which hello)
# (output truncated)
# /nix/store/qn3ggz5sf3hkjs2c797xf7nan3amdxmp-glibc-2.38-27/lib/ld-linux-x86-64.so.2 vs $ ldd ./workerd
# (output truncated)
# /nix/store/qn3ggz5sf3hkjs2c797xf7nan3amdxmp-glibc-2.38-27/lib64/ld-linux-x86-64.so.2 The difference between those two interpreter paths is # swaps `/lib64` to the resolved `/lib`
patchelf --set-interpreter /nix/store/qn3ggz5sf3hkjs2c797xf7nan3amdxmp-glibc-2.38-27/lib/ld-linux-x86-64.so.2 ./node_modules/@cloudflare/workerd-linux-64/bin/workerd The binary becomes executable 🎉 I'm able to run |
Beta Was this translation helpful? Give feedback.
-
Unfortunately, linking statically against glibc does not work, because glibc uses Therefore, we statically link everything except glibc. But it seems that NixOS isn't happy with such binaries, unless you use an extra wrapper. If there's something we could do that would make things easier on Nix without harming usability on other distros, we're happy to accept PRs. Unfortunately our team doesn't have the bandwidth to work on Nix support directly. |
Beta Was this translation helpful? Give feedback.
-
@PsychoLlama Would you mind clarifying the solution a bit? Is patchelf a command that you run once to fix the linking, then workerd starts working properly? Where do I get the interpreter path for my machine, does that come from the |
Beta Was this translation helpful? Give feedback.
-
TL;DR: I only need to patch it once. I got the expected path from Longer answerSure, I'll tell you what I can, but I think I'm still missing parts of the picture. If my first post was correct then patching the interpreter to use I also tried overriding the I no longer believe symlinking is the problem. I don't know why it fails. I'm still a noob when it comes to native stuff like this, so I might be missing something obvious. EDIT: While writing this response it occurs to me that
Yes, I only need to run it once after the first npm install, or any time the executable changes (e.g. updating the wrangler package).
I pulled it from
I just took the path that it printed and used that in the {
description = "Development environment";
outputs = { self, nixpkgs }:
let inherit (nixpkgs) lib;
in {
devShell = lib.genAttrs lib.systems.flakeExposed (system:
let pkgs = import nixpkgs { inherit system; };
in pkgs.mkShell {
nativeBuildInputs = [ pkgs.nodejs ];
# See: https://github.com/cloudflare/workerd/issues/1482
shellHook = ''
__patchTarget="./node_modules/@cloudflare/workerd-linux-64/bin/workerd"
if [[ -f "$__patchTarget" ]]; then
${pkgs.patchelf}/bin/patchelf --set-interpreter ${pkgs.glibc}/lib/ld-linux-x86-64.so.2 "$__patchTarget"
fi
'';
});
};
} Now every time I enter my dev shell it will auto-correct the workerd interpreter path. You may need to change |
Beta Was this translation helpful? Give feedback.
-
@jonahbron Ha, while poking around, I discovered a simpler alternative: remove wrangler from your I think through troubleshooting this issue, I rediscovered why the fixup phase of |
Beta Was this translation helpful? Give feedback.
-
Oh my god you're a life saver @PsychoLlama, installing with
Moving the flake down into the child directory fixed that issue. Only drawback is I have to invoke wrangler directly (can't have it in a package.json) script because it will search in |
Beta Was this translation helpful? Give feedback.
-
I'm going to move this issue to a discussion as it does not appear as if this is actually an issue to resolve in workerd itself. |
Beta Was this translation helpful? Give feedback.
-
NixOS uses a non-standard location for the glibc loader. Therefore compiled binaries that assume the Linux FHS won't run on NixOS. This is a well-known problem in the NixOS community, and it is by-design. Binaries compiled inside Nix will of course pick up the right glibc loader from the To run unpatched binaries you need to use Although ideally the whole thing would be a static binary to avoid problems. |
Beta Was this translation helpful? Give feedback.
-
So this is the best way to do it:
Just make sure that |
Beta Was this translation helpful? Give feedback.
-
On a nix-related note: I have tried to produce
Nix help is appreciated. |
Beta Was this translation helpful? Give feedback.
-
My work-around is to hook into npm's postinstall phase with:
It'd be cleaner to stuff this into shell.nix using Benefit of this method is that it runs every time a new package is added. Otherwise yarn overwrites the local node_modules with the bad copy and I have to manually trigger patchelf. I'll try nix-ld next time. |
Beta Was this translation helpful? Give feedback.
-
@patonw did you find the correct nix-ld config? i want to use that but am unable to find which pkg to put in it. |
Beta Was this translation helpful? Give feedback.
-
Running workerd-linux-64 under linux should be possible with just installing glibc according to the readme. However when I try to execute it, I get this error:
This is running in a Nix shell with nixpkgs.glibc present (and verified by running the binaries it provides)
Beta Was this translation helpful? Give feedback.
All reactions