summary refs log tree commit diff
path: root/pkgs/build-support/dotnet/make-nuget-source/default.nix
blob: a23a143ab2467e2547d42ad4bf4180eb1d00cc2c (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
{ lib, python3, stdenvNoCC }:

{ name
, description ? ""
, deps ? []
}:

let
  nuget-source = stdenvNoCC.mkDerivation rec {
    inherit name;

    meta.description = description;
    nativeBuildInputs = [ python3 ];

    buildCommand = ''
      mkdir -p $out/{lib,share}

      # use -L to follow symbolic links. When `projectReferences` is used in
      # buildDotnetModule, one of the deps will be a symlink farm.
      find -L ${lib.concatStringsSep " " deps} -type f -name '*.nupkg' -exec \
        cp --no-clobber '{}' $out/lib ';'

      # Generates a list of all licenses' spdx ids, if available.
      # Note that this currently ignores any license provided in plain text (e.g. "LICENSE.txt")
      python ${./extract-licenses-from-nupkgs.py} $out/lib > $out/share/licenses
    '';
  } // { # We need data from `$out` for `meta`, so we have to use overrides as to not hit infinite recursion.
    meta.licence = let
      depLicenses = lib.splitString "\n" (builtins.readFile "${nuget-source}/share/licenses");
    in (lib.flatten (lib.forEach depLicenses (spdx:
      lib.optionals (spdx != "") (lib.getLicenseFromSpdxId spdx)
    )));
  };
in nuget-source