NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.42k stars 13.63k forks source link

dotnet: using nuget packages with native binaries in them #181373

Closed mdarocha closed 1 year ago

mdarocha commented 2 years ago

Issue description

Some NuGet packages include native binaries inside of them for various purposes - ie. see Grpc.Tools.

Using them in NixOS is currently impossible, since these binaries are compiled for a normal FHS linux system, and fail on NixOS.

Two additional features are needed for usage of such binaries to improve in NixOS:

  1. Support in buildDotnetModule

    buildDotnetModule should automatically run patchelf on all found binaries in the restored nuget dependencies. This would allow easy support in nixpkgs

  2. Support when running bare dotnet command

    This one is a lot more trickier. When running native dotnet command (outside the scope of a Nix build), patchelf should automatically patch restored nuget packages.

    This is a lower priority feature, mainly aimed at developer egonomics. It would be also a lot harder to implement. Ideas welcome.

Steps to reproduce

Try to create and build any .NET project that uses nuget packages with native binaries (ie. eventstore)

Technical details

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

winterqt commented 2 years ago

cc @IvarWithoutBones for point 1

mdarocha commented 1 year ago

I've implement a basic fix for buildDotnetModule in https://github.com/NixOS/nixpkgs/pull/233422. This should be enough to build most packages that require this.

emilytrau commented 1 year ago

Heya @mdarocha @GGG-KILLER 👋. I saw this issue was referenced in a fixme introduced in #187133. Is this something that can now be cleaned up?

https://github.com/NixOS/nixpkgs/blob/f50bf5864827281a50d46269e84f7262694f74d6/pkgs/development/compilers/dotnet/update.sh#L226-L238

mdarocha commented 1 year ago

Yeah, I think the comment can be removed

YoshiRulz commented 8 months ago

(...The note was removed in https://github.com/NixOS/nixpkgs/commit/ab466279f2f85293341206aa37b70ce541ce0f17.)

But point 2) of the OP (dotnet from profile or mkShell, no buildDotnetModule) doesn't seem to have been addressed. I'm still getting [...] line 2: .../ilc: cannot execute: required file not found when adding <PublishAot/>. Is it not feasible to implement it for that scenario?

GGG-KILLER commented 8 months ago

I do not think it is @YoshiRulz because we'd have to patch the dotnet binary to once a nuget package is downloaded, its binary executables be patched to work with the current system.

This would require us to build from source and also maintain our own fork of .NET, so the easiest method is to either use steam-run or a container. You can also manually patch those binaries yourself if you know how to using patchelf.

moinessim commented 6 months ago

I found this useful: https://blog.thalheim.io/2022/12/31/nix-ld-a-clean-solution-for-issues-with-pre-compiled-executables-on-nixos/

GGG-KILLER commented 6 months ago

Yes, nix-ld is is indeed a viable alternative to it, I've been using it for NativeAOT in one of my projects: https://github.com/GGG-KILLER/SimpleCompiler/blob/main/shell.nix

I didn't mention it before because only recently I've caved in and decided to use it, as before I wanted to keep a 100% pure nix environment and manually patchelf'd anything I needed.