Skip to content
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

Having trouble using cached protoc binary with nix-shell #326

Open
martyall opened this issue Jan 24, 2023 · 4 comments
Open

Having trouble using cached protoc binary with nix-shell #326

martyall opened this issue Jan 24, 2023 · 4 comments

Comments

@martyall
Copy link

martyall commented Jan 24, 2023

I'm trying to compile a scala project that generates code via sbt-protoc but I am getting the following error message:

...
[error] 	at java.base/java.lang.Thread.run(Thread.java:829)
[error] (protos / Compile / protocGenerate) error occurred while compiling protobuf files: Cannot run program "/home/martyall/.cache/protocbridge/v1/protoc-linux-x86_64-3.19.3": error=2, No such file or directory
[error] Total time: 2 s, completed Jan 24, 2023, 2:44:16 AM

My thought is that because I am using nix flakes, nix has no clue where $HOME/.cache is located. What is the advised workaround for this problem?

My flake file looks like:

image

@thesamet
Copy link
Owner

Hi @martyall , sorry for the late response. I have missed the notification email.

I am not familiar with flakes, but I do use Nix myself. If you use a recent sbt-protoc (>1.0.0) things should work by default. There's a special code path in that looks for NIX_CC environment variable so it can execute protoc correctly. Can you check if flakes sets up this environment variable in the same way something like nix-shell -p bash would?

@yilinwei
Copy link

yilinwei commented Jan 20, 2024

@martyall the error message is the generic misleading error because the binary isn't built using nix.

You can manually override the setting in the build.sbt to use the distro protoc that you have in your flake.

@thesamet The new nix shell command which you install at the same time as flakes, does not seem to set the NIX_CC variable at all - maybe we could add a setting to use an installed version instead via the PATH variable?

@thesamet
Copy link
Owner

Would it be possible to send over the flake file so I can try? However, sbt-protoc downloads protoc from maven through coursier. You can override this behavior by settings PB.protocExecutable. Also protoc >= 3.23.0 with sbt-protoc >=1.0.7 should work well as protoc is statically linked and require no workarounds.

@yilinwei
Copy link

@thesamet

I'm actually using the floating nix package, so something like nix shell nixpkgs#sbt nixpkgs#protobuf_317 so there isn't a flake file!

Yes I'm doing the override manually at the moment. I'll try the updated plugin version and see whether it works out the box.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants