core/pkgs/build-support/dotnet/build-dotnet-global-tool/default.nix

70 lines
1.5 KiB
Nix
Raw Normal View History

2024-06-30 08:16:52 +00:00
{
buildDotnetModule,
emptyDirectory,
mkNugetDeps,
dotnet-sdk,
}:
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
{
pname,
version,
2024-05-02 00:46:19 +00:00
# Name of the nuget package to install, if different from pname
2024-06-30 08:16:52 +00:00
nugetName ? pname,
2024-05-02 00:46:19 +00:00
# Hash of the nuget package to install, will be given on first build
2024-06-30 08:16:52 +00:00
nugetSha256 ? "",
2024-05-02 00:46:19 +00:00
# Additional nuget deps needed by the tool package
2024-06-30 08:16:52 +00:00
nugetDeps ? (_: [ ]),
2024-05-02 00:46:19 +00:00
# Executables to wrap into `$out/bin`, same as in `buildDotnetModule`, but with
# a default of `pname` instead of null, to avoid auto-wrapping everything
2024-06-30 08:16:52 +00:00
executables ? pname,
2024-05-02 00:46:19 +00:00
# The dotnet runtime to use, dotnet tools need a full SDK to function
2024-06-30 08:16:52 +00:00
dotnet-runtime ? dotnet-sdk,
...
}@args:
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
buildDotnetModule (
args
// {
inherit
pname
version
dotnet-runtime
executables
;
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
src = emptyDirectory;
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
nugetDeps = mkNugetDeps {
name = pname;
nugetDeps =
{ fetchNuGet }:
[
(fetchNuGet {
pname = nugetName;
inherit version;
sha256 = nugetSha256;
})
]
++ (nugetDeps fetchNuGet);
};
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
projectFile = "";
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
useDotnetFromEnv = true;
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
dontBuild = true;
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
installPhase = ''
runHook preInstall
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
dotnet tool install --tool-path $out/lib/${pname} ${nugetName}
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
# remove files that contain nix store paths to temp nuget sources we made
find $out -name 'project.assets.json' -delete
find $out -name '.nupkg.metadata' -delete
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
runHook postInstall
'';
}
)