Work in progress : dotnet2nix / builtDotNetProject helper

Hello,

I’ve made a working prototype for a “dotnet2nix” solution that relies on NuGet lockfiles.

I’ve tested the solution against simple projects for now, so I’m looking for people that would like to review this project. Suggestions and PRs are of course welcome :slight_smile:.

I hope to possibly upstream the builtDotNetProject helper for the 20.09 (and possibly use it to provide a baget service).

Disclaimer : I haven’t took time to cleanup the code for now, I will do a cleanup pass the first week of august.

4 Likes

If you want to have a vendor sha similar to rust packages, you could provide:

outputHashAlgo = "sha256";
outputHash = sha256;
outputHashMode = "recursive";

and this will allow for a derivation to have network access. The catch is that the process should be reproducible, which a nuget lock file should be.

I will try that ! Would that permit to remove the need to precalculate the hash for each NuGet dependency ?

In theory, yes. But the lock files would need to be added

That’s really interesting, it might be a solution that can work without a dotnet2nix program, I’m going to do some experiments.

same, but it still might be nice to have a helper around which is able to produce the patchfiles for generating the lock files, and able to calculate the vendor sha

here’s a linting PR: dotnetCorePackages: lint by jonringer · Pull Request #93302 · NixOS/nixpkgs · GitHub

going to do my work on top of it, just easier to get it merged if I’m not also adding complexity to nixpkgs

I’ve almost managed to have it working without dotnet2nix : https://gist.github.com/Elyhaka/0f0e3afe488100487ada6a2a8bef78a4

I have to find a way to provide the runtime properly (not sure how unless I ask the developer to provide them explicitly, maybe I’m missing something obvious ?).

Here is an example if I want to package my dotnet2nix project with the gist.

{ callPackage, dotnetCorePackages }:

let
  buildDotNetProject = callPackage ./Nix/buildDotNetProject.nix { };
in buildDotNetProject rec {
  name = "dotnet2nix";
  version = "1.0.0";
  src = ./.;

  target = "linux-x64";
  sdk = dotnetCorePackages.sdk_3_1;
  lockFiles = [
    ./packages.lock.json
  ];
  runtimes = {
    "Microsoft.NETCore.App.Runtime.${target}" = "3.1.2";
    "Microsoft.AspNetCore.App.Runtime.${target}" = "3.1.2";
  };
  nugetSha256 = "033db302z52a8p6fgbi8nmb765pkrzmy7rk59qjh006xsyw04l19";
}

I will also have to add an option to support multiple Lockfiles.

EDIT: Update with runtimes information
EDIT 2: I’ve updated (again) my gist to use dotnet restore since I was having a lot of trouble with a real world project that relies on Newtonsoft.Json (might be related to this issue: The dotnet store is incorrectly including BCL assemblies when targeting .NET Core 3.1 · Issue #10973 · dotnet/sdk · GitHub), and I’m stuck with the runtime parts that are missing. I’m not sure I have the knowledge to fix this

I edited my post (and my gist), and I managed to add runtimes but I do not really like it. I was wondering if the runtimes that are on dotnetCorePackages could provide metadata that could be consumed by buildDotNetProject ?