Can't get buildDotnetModule to work

Hi, I’m trying to get buildDotnetModule to work on one of my projects ( GitHub - SolrNet/SolrNet: Solr client for .Net ).

I’m following the docs at nixpkgs/dotnet.section.md at 5234f4ce9340fffb705b908fff4896faeddb8a12 · NixOS/nixpkgs · GitHub but they’re not very clear…

I’m going to detail each step and you tell me where I’m going wrong :slightly_smiling_face:

First I write the following nix file kk.nix in the source root:

let 
  nixpkgs = builtins.fetchTarball "https://github.com/nixos/nixpkgs/archive/a1291d0d020a200c7ce3c48e96090bfa4890a475.tar.gz";
  pkgs = import nixpkgs {};
in
pkgs.buildDotnetModule {
  pname = "solrnet";
  version = "1.1.1";
  src = ./.;
  dontDotnetFixup = true;
  unpackPhase = ":";

  projectFile = "SolrNet.sln";
}

Then I run nix-build kk.nix -A passthru.fetch-deps --no-out-link

This writes a script in the nix store to generate dependencies?
The docs are incorrect here I think. It says:

 nugetDeps = ./deps.nix; # File generated with `nix-build -A package.passthru.fetch-deps`.

But deps.nix is not actually generated by running that nix-build.
(the paragraph that precedes that code block is correct)

Here’s where things start going wrong, when I run that script it crashes with:

Restoring project...
MSBUILD : error MSB1009: Project file does not exist.
Switch: SolrNet.sln

So I inspect that script and I notice that it has a storeSrc variable pointing to what looks like the dotnet source code in the nix store. But that directory actually only has an env-vars file and nothing else (?)
So I copy the script somewhere I can edit it, and change storeSrc to a directory with my dotnet source code.
I run the script again and it works now, outputs:

Succesfully wrote lockfile to /tmp/solrnet-deps-F7Pc0D.nix

I copy that file to ./deps.nix in the directory of my source code.
I add nugetDeps = ./deps.nix; to kk.nix
I run nix-build kk.nix
It crashes at:

Executing dotnetConfigureHook
MSBUILD : error MSB1009: Project file does not exist.
Switch: SolrNet.sln

I change projectFile to an absolute path and the error becomes more explicit:

Executing dotnetConfigureHook
MSBUILD : error MSB1001: Unknown switch.
    Full command line: '/nix/store/ipv6srk9pr5x6py8wgdvzik9jv37vbm5-dotnet-sdk-6.0.405/sdk/6.0.405/MSBuild.dll -maxcpucount -verbosity:m -nologo -target:Restore -property:RestoreSources=/nix/store/cyqx65a72rar9gvia4isk2ki5lrsdr17-solrnet-1.1.1-nuget-source/lib -property:RestoreDisableParallel=true --property:ContinuousIntegrationBuild=true --property:Deterministic=true -property:RuntimeIdentifiers=linux-x64 /home/mauricio/prg/SolrNet/SolrNet.sln'
  Switches appended by response files:
Switch: /home/mauricio/prg/SolrNet/SolrNet.sln

So this seems to be generating an invalid call to msbuild?

At this point in the rabbit hole I could start debugging with the hooks in a local nixpkgs but it’s clear that I’m doing something wrong at some point here.

Can anyone help?

Problem 1:

  unpackPhase = ":";

Problem 2:

  dontDotnetFixup = true;

Overriding unpackPhase will break a lot of things, so don’t do that. This should work:

pkgs.buildDotnetModule {
  pname = "solrnet";
  version = "1.1.1";

  src = ./.;
  nugetDeps = ./deps.nix;

  projectFile = "SolrNet.sln";
}

Thanks, for some reason I was getting the dreaded “do not know how to unpack source archive” error before :man_shrugging: