DotNET: Difference between revisions

m ryantm link -> canonical Nixpkgs manual link
Lostmsu (talk | contribs)
a few more steps were required to successfully build a new package
Line 4: Line 4:
Example build file:
Example build file:


<syntaxHighlight lang=nix>
<syntaxhighlight lang="nix">
{ fetchFromGitHub
{ fetchFromGitHub
, dotnetCorePackages
, buildDotnetModule
, buildDotnetModule
}:
}:
Line 17: Line 18:
     repo = pname;
     repo = pname;
     rev = "v${version}";
     rev = "v${version}";
     sha256 = "";
     sha256 = ""; # can be figured out from the first build attempt
   };
   };


   projectFile = "SomeProject/SomeProject.csproj";
   projectFile = "SomeProject/SomeProject.csproj";
  dotnet-sdk = dotnetCorePackages.sdk_8_0;
  dotnet-runtime = dotnetCorePackages.runtime_8_0;
  nugetDeps = ./nuget-deps.nix; # only if there are NuGet dependencies


   meta = with lib; {
   meta = with lib; {
Line 29: Line 33:
}
}


</syntaxHighlight>
</syntaxhighlight>


Note that the above package will not build the first time. After adding the above definition to `all-packages.nix`, you
Note that the above package will not build the first time. After adding the above definition to `all-packages.nix`, you
can run the package-specific `fetch-deps` script, which will generate a file containing all the nuget dependencies of the
can run the package-specific `fetch-deps` script, which will generate a file containing all the nuget dependencies of the
package. Build the script with <code>nix-build -A some-package.fetch-deps</code>, copy that generated file (the location will be printed by the script) and set the <code>nugetDeps</code> attribute in <code>buildDotnetModule</code> to point to that generated file (ie. <code>nugetDeps = ./deps.nix</code>).
package. Build the script with <code>nix-build -A some-package.fetch-deps</code>, might need to run <code>./result deps.nix</code>, copy that generated file (the location will be printed by the script) and set the <code>nugetDeps</code> attribute in <code>buildDotnetModule</code> to point to that generated file (ie. <code>nugetDeps = ./deps.nix</code>).


After that the package will build normally. Remember to re-run <code>fetch-deps</code> every time the package is updated.
After that the package will build normally. Remember to re-run <code>fetch-deps</code> every time the package is updated.