Error while trying to make package for ReportGenerator (dotenv C#)

Hello, I’ve been following the documentation for writing a package using buildDotenvModule for ReportGenerator (specifically the global tool). I think I’m pretty close now, but getting a weird error:

Package source with Name: nuget disabled successfully.                                                                                                                                                                                                                                 
Package source with Name: _nix added successfully.                                                                                                                                                                                                                                     
Running phase: unpackPhase                                                                                                                                                                                                                                                             
@nix { "action": "setPhase", "phase": "unpackPhase" }                                                                                                                                                                                                                                  
unpacking source archive /nix/store/32jx9aw3n2b8nbv840wl6mfyxkyqj7ar-source                                                                                                                                                                                                            
source root is source                                                                                                                                                                                                                                                                  
Running phase: patchPhase                                                                                                                                                                                                                                                              
@nix { "action": "setPhase", "phase": "patchPhase" }                                                                                                                                                                                                                                   
Running phase: configureNuget                                                                                                                                                                                                                                                          
@nix { "action": "setPhase", "phase": "configureNuget" }                                                                                                                                                                                                                               
ln: failed to create symbolic link '/build/.nuget-temp/source/microsoft.aspnetcore.app.ref/6.0.32': File exists

Here’s the package so far:

{ 
  fetchFromGitHub,
  dotnetCorePackages,
  buildDotnetModule
}:
let
  sdks = (with dotnetCorePackages; combinePackages [
    sdk_6_0
    sdk_7_0
    sdk_8_0
  ]);
in
buildDotnetModule rec {
  pname = "ReportGenerator";
  version = "5.3.8";

  src = fetchFromGitHub {
    owner = "danielpalme";
    repo = pname;
    rev = "v${version}";
    hash = "sha256-V7k4DBmE4fRuIygvhYS0P1oiTkn9ICnnE7VKK0T6CY4=";
  };

  projectFile = "src/ReportGenerator.DotnetGlobalTool/ReportGenerator.DotnetGlobalTool.csproj";
  dotnet-sdk = sdks;
  dotnet-runtime = dotnetCorePackages.runtime_6_0;
  nugetDeps = ./deps.nix;

}

with deps.nix

{ fetchNuGet }: [
  (fetchNuGet { pname = "DotNetConfig"; version = "1.2.0"; hash = "sha256-gbhocVVZQ61VKJMUhdL7O62qTzYNUhh/LopLH67GsLw="; })
  (fetchNuGet { pname = "McMaster.NETCore.Plugins"; version = "1.4.0"; hash = "sha256-PtpD8S74UXyoA80YRDlrp8qR/I7Ws7+4m2EJZzH4WMw="; })
  (fetchNuGet { pname = "Microsoft.AspNetCore.App.Ref"; version = "6.0.32"; hash = "sha256-1mQTxwruzhm20YdlZefrYuy7xrBs17pH4Vo0K3Tl7Fc="; })
  (fetchNuGet { pname = "Microsoft.AspNetCore.App.Ref"; version = "7.0.20"; hash = "sha256-OEDXXjQ1HDRPiA4Y1zPr1xUeH6wlzTCJpts+DZL61wI="; })
  (fetchNuGet { pname = "Microsoft.Bcl.AsyncInterfaces"; version = "8.0.0"; hash = "sha256-9aWmiwMJKrKr9ohD1KSuol37y+jdDxPGJct3m2/Bknw="; })
  (fetchNuGet { pname = "Microsoft.Build.Tasks.Git"; version = "8.0.0"; hash = "sha256-vX6/kPij8vNAu8f7rrvHHhPrNph20IcufmrBgZNxpQA="; })
  (fetchNuGet { pname = "Microsoft.DotNet.PlatformAbstractions"; version = "3.1.6"; hash = "sha256-RfM2qXiqdiamPkXr4IDkNc0IZSF9iTZv4uou/E7zNS0="; })
  (fetchNuGet { pname = "Microsoft.Extensions.Configuration"; version = "8.0.0"; hash = "sha256-9BPsASlxrV8ilmMCjdb3TiUcm5vFZxkBnAI/fNBSEyA="; })
  (fetchNuGet { pname = "Microsoft.Extensions.Configuration.Abstractions"; version = "8.0.0"; hash = "sha256-4eBpDkf7MJozTZnOwQvwcfgRKQGcNXe0K/kF+h5Rl8o="; })
  (fetchNuGet { pname = "Microsoft.Extensions.Configuration.Binder"; version = "8.0.2"; hash = "sha256-aGB0VuoC34YadAEqrwoaXLc5qla55pswDV2xLSmR7SE="; })
  (fetchNuGet { pname = "Microsoft.Extensions.Configuration.CommandLine"; version = "8.0.0"; hash = "sha256-fmPC/o8S+weTtQJWykpnGHm6AKVU21xYE/CaHYU7zgg="; })
  (fetchNuGet { pname = "Microsoft.Extensions.Configuration.FileExtensions"; version = "8.0.0"; hash = "sha256-BCxcjVP+kvrDDB0nzsFCJfU74UK4VBvct2JA4r+jNcs="; })
  (fetchNuGet { pname = "Microsoft.Extensions.Configuration.Json"; version = "8.0.0"; hash = "sha256-Fi/ijcG5l0BOu7i96xHu96aN5/g7zO6SWQbTsI3Qetg="; })
  (fetchNuGet { pname = "Microsoft.Extensions.DependencyModel"; version = "5.0.0"; hash = "sha256-vUwAWMxXiMW+JOiQE5fcJycOfJJzO87ESYAsEPsPqtY="; })
  (fetchNuGet { pname = "Microsoft.Extensions.FileProviders.Abstractions"; version = "8.0.0"; hash = "sha256-uQSXmt47X2HGoVniavjLICbPtD2ReQOYQMgy3l0xuMU="; })
  (fetchNuGet { pname = "Microsoft.Extensions.FileProviders.Physical"; version = "8.0.0"; hash = "sha256-29y5ZRQ1ZgzVOxHktYxyiH40kVgm5un2yTGdvuSWnRc="; })
  (fetchNuGet { pname = "Microsoft.Extensions.FileSystemGlobbing"; version = "8.0.0"; hash = "sha256-+Oz41JR5jdcJlCJOSpQIL5OMBNi+1Hl2d0JUHfES7sU="; })
  (fetchNuGet { pname = "Microsoft.Extensions.Primitives"; version = "8.0.0"; hash = "sha256-FU8qj3DR8bDdc1c+WeGZx/PCZeqqndweZM9epcpXjSo="; })
  (fetchNuGet { pname = "Microsoft.NETCore.App.Host.linux-x64"; version = "6.0.32"; hash = "sha256-2aDGkn0QqXXHUUSAwtQQbjKl5I6S0fcQWPciqPnOiM4="; })
  (fetchNuGet { pname = "Microsoft.NETCore.App.Host.linux-x64"; version = "7.0.20"; hash = "sha256-Y1Dg8Sqhya86xD+9aJOuznT4mJUyFmoF/YZc0+5LBdc="; })
  (fetchNuGet { pname = "Microsoft.NETCore.App.Ref"; version = "6.0.32"; hash = "sha256-Fm3RUZNcro434rIu3c7unGviGeGBjXj2dGnr2mmrM2g="; })
  (fetchNuGet { pname = "Microsoft.NETCore.App.Ref"; version = "7.0.20"; hash = "sha256-W9RU3bja4BQLAbsaIhANQPJJh6DycDiBR+WZ3mK6Zrs="; })
  (fetchNuGet { pname = "Microsoft.NETCore.Platforms"; version = "1.1.0"; hash = "sha256-FeM40ktcObQJk4nMYShB61H/E8B7tIKfl9ObJ0IOcCM="; })
  (fetchNuGet { pname = "Microsoft.SourceLink.Common"; version = "8.0.0"; hash = "sha256-AfUqleVEqWuHE7z2hNiwOLnquBJ3tuYtbkdGMppHOXc="; })
  (fetchNuGet { pname = "Microsoft.SourceLink.GitHub"; version = "8.0.0"; hash = "sha256-hNTkpKdCLY5kIuOmznD1mY+pRdJ0PKu2HypyXog9vb0="; })
  (fetchNuGet { pname = "NETStandard.Library"; version = "2.0.3"; hash = "sha256-Prh2RPebz/s8AzHb2sPHg3Jl8s31inv9k+Qxd293ybo="; })
  (fetchNuGet { pname = "StyleCop.Analyzers"; version = "1.1.118"; hash = "sha256-CjC1f5z0sP15F6FeXqIDOtZLHqgjmQTzpsIrRkxXREI="; })
  (fetchNuGet { pname = "System.Buffers"; version = "4.5.1"; hash = "sha256-wws90sfi9M7kuCPWkv1CEYMJtCqx9QB/kj0ymlsNaxI="; })
  (fetchNuGet { pname = "System.Collections.Immutable"; version = "6.0.0"; hash = "sha256-DKEbpFqXCIEfqp9p3ezqadn5b/S1YTk32/EQK+tEScs="; })
  (fetchNuGet { pname = "System.Memory"; version = "4.5.4"; hash = "sha256-3sCEfzO4gj5CYGctl9ZXQRRhwAraMQfse7yzKoRe65E="; })
  (fetchNuGet { pname = "System.Memory"; version = "4.5.5"; hash = "sha256-EPQ9o1Kin7KzGI5O3U3PUQAZTItSbk9h/i4rViN3WiI="; })
  (fetchNuGet { pname = "System.Numerics.Vectors"; version = "4.4.0"; hash = "sha256-auXQK2flL/JpnB/rEcAcUm4vYMCYMEMiWOCAlIaqu2U="; })
  (fetchNuGet { pname = "System.Runtime.CompilerServices.Unsafe"; version = "6.0.0"; hash = "sha256-bEG1PnDp7uKYz/OgLOWs3RWwQSVYm+AnPwVmAmcgp2I="; })
  (fetchNuGet { pname = "System.Text.Encodings.Web"; version = "8.0.0"; hash = "sha256-IUQkQkV9po1LC0QsqrilqwNzPvnc+4eVvq+hCvq8fvE="; })
  (fetchNuGet { pname = "System.Text.Json"; version = "8.0.4"; hash = "sha256-g5oT7fbXxQ9Iah1nMCr4UUX/a2l+EVjJyTrw3FTbIaI="; })
  (fetchNuGet { pname = "System.Threading.Tasks.Extensions"; version = "4.5.4"; hash = "sha256-owSpY8wHlsUXn5xrfYAiu847L6fAKethlvYx97Ri1ng="; })
]

There are no duplicate packages, and the final was generated by nuget-to-nix (using sdk8). Any ideas?

Ok well I fixed this error by using the fetch-deps script. Now it’s complaining about me not specifying the SDK (I’ll try to fix this).

/nix/store/1nmjsx4wkr7braiz5spq84b1ibvvz2jb-dotnet-sdk-8.0.303/sdk/8.0.303/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.CrossTargeting.targets(31,5): error NETSDK1129: The 'Publish' target is not supported without specifying a target framework. The current project targets multiple frameworks, you must specify one of the following frameworks in order to publish: net6.0, net7.0, net8.0 [/build/source/src/ReportGenerator.DotnetGlobalTool/ReportGenerator.DotnetGlobalTool.csproj]

EDIT: Working version now:

{ 
  lib,
  fetchFromGitHub,
  dotnetCorePackages,
  buildDotnetModule
}:
let
  sdks = (with dotnetCorePackages; combinePackages [
    sdk_6_0
    sdk_7_0
    sdk_8_0
  ]);
  installVersion = "net8.0";
  projectFile = "src/ReportGenerator.DotnetGlobalTool/ReportGenerator.DotnetGlobalTool.csproj";
in
buildDotnetModule rec {
  inherit projectFile;

  pname = "ReportGenerator";
  version = "5.3.8";

  src = fetchFromGitHub {
    owner = "danielpalme";
    repo = pname;
    rev = "v${version}";
    hash = "sha256-V7k4DBmE4fRuIygvhYS0P1oiTkn9ICnnE7VKK0T6CY4=";
  };

  postPatch = ''
    rm global.json

    substituteInPlace "${projectFile}" \
      --replace "<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>" "<TargetFramework>${installVersion}</TargetFramework>"
  '';

  dotnet-sdk = sdks;
  dotnet-runtime = dotnetCorePackages.runtime_8_0;
  nugetDeps = ./deps.nix;
  executables = [ "ReportGenerator" ];

  meta = with lib; {
      description = "ReportGenerator converts coverage reports generated by coverlet, OpenCover, dotCover, Visual Studio, NCover, Cobertura, JaCoCo, Clover, gcov or lcov into human readable reports in various formats.";
      homepage = "https://github.com/danielpalme/ReportGenerator";
      license = with licenses; [ asl20 ];
      mainProgram = "ReportGenerator";
      platforms = lib.platforms.all;
  };

}

Feels slightly hacky because I think you can only “install” one version, but works good enough for me.