about summary refs log tree commit diff
path: root/nixpkgs/pkgs/build-support/dotnet/build-dotnet-global-tool/default.nix
blob: 7ae9cfc9f661859dfde140043f8eacf5f390b2a5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
{ buildDotnetModule, emptyDirectory, mkNugetDeps, dotnet-sdk }:

{ pname
, version
  # Name of the nuget package to install, if different from pname
, nugetName ? pname
  # Hash of the nuget package to install, will be given on first build
, nugetSha256 ? ""
  # Additional nuget deps needed by the tool package
, nugetDeps ? (_: [])
  # Executables to wrap into `$out/bin`, same as in `buildDotnetModule`, but with
  # a default of `pname` instead of null, to avoid auto-wrapping everything
, executables ? pname
  # The dotnet runtime to use, dotnet tools need a full SDK to function
, dotnet-runtime ? dotnet-sdk
, ...
} @ args:

buildDotnetModule (args // {
  inherit pname version dotnet-runtime executables;

  src = emptyDirectory;

  nugetDeps = mkNugetDeps {
    name = pname;
    nugetDeps = { fetchNuGet }: [
      (fetchNuGet { pname = nugetName; inherit version; sha256 = nugetSha256; })
    ] ++ (nugetDeps fetchNuGet);
  };

  dotnetGlobalTool = true;

  useDotnetFromEnv = true;

  dontBuild = true;

  installPhase = ''
    runHook preInstall

    dotnet tool install --tool-path $out/lib/${pname} ${nugetName}

    # 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

    runHook postInstall
  '';
})