about summary refs log tree commit diff
path: root/pkgs/development/compilers/dotnet/packages.nix
blob: f9a5190d158851b6f4f117e91a70b7165c4efb56 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
{
  stdenvNoCC,
  lib,
  callPackage,
  vmr,
  xmlstarlet,
  strip-nondeterminism,
  zip,
  nugetPackageHook,
  fallbackTargetPackages ? { },
}:

let
  mkCommon = callPackage ./common.nix { };
  inherit (vmr) targetRid releaseManifest;

  # TODO: do this properly
  hostRid = targetRid;

  mkPackage =
    pname: version:
    stdenvNoCC.mkDerivation {
      inherit pname version;

      src = vmr;
      dontUnpack = true;

      nativeBuildInputs = [
        xmlstarlet
        nugetPackageHook
      ];

      installPhase = ''
        runHook preInstall

        mkdir -p "$out"

        pushd "$src"/Private.SourceBuilt.Artifacts.*.${targetRid}
        pushd ${pname}.${version}.nupkg

        xmlstarlet \
          sel -t \
          -m /_:package/_:metadata \
          -v _:id -nl \
          -v _:version -nl \
          *.nuspec | (
          read id
          read version
          id=''${id,,}
          version=''${version,,}
          mkdir -p "$out"/share/nuget/packages/"$id"
          cp -r . "$out"/share/nuget/packages/"$id"/"$version"
          chmod +w "$out"/share/nuget/packages/"$id"/"$version"
          echo {} > "$out"/share/nuget/packages/"$id"/"$version"/.nupkg.metadata
        )

        popd
        popd

        runHook postInstall
      '';
    };

  packages =
    [
      (mkPackage "Microsoft.AspNetCore.App.Ref" aspnetcore.version)
      (mkPackage "Microsoft.NETCore.DotNetAppHost" runtime.version)
      (mkPackage "Microsoft.NETCore.App.Ref" runtime.version)
      (mkPackage "Microsoft.DotNet.ILCompiler" runtime.version)
      (mkPackage "Microsoft.NET.ILLink.Tasks" runtime.version)
      (mkPackage "Microsoft.NETCore.App.Crossgen2.${hostRid}" runtime.version)
      (mkPackage "runtime.${hostRid}.Microsoft.DotNet.ILCompiler" runtime.version)
    ]
    ++ lib.optionals (lib.versionOlder runtime.version "9") [
      (mkPackage "Microsoft.NETCore.DotNetHost" runtime.version)
      (mkPackage "Microsoft.NETCore.DotNetHostPolicy" runtime.version)
      (mkPackage "Microsoft.NETCore.DotNetHostResolver" runtime.version)
    ];

  targetPackages = fallbackTargetPackages // {
    ${targetRid} =
      [
        (mkPackage "Microsoft.AspNetCore.App.Runtime.${targetRid}" aspnetcore.version)
        (mkPackage "Microsoft.NETCore.App.Host.${targetRid}" runtime.version)
        (mkPackage "Microsoft.NETCore.App.Runtime.${targetRid}" runtime.version)
        (mkPackage "runtime.${targetRid}.Microsoft.NETCore.DotNetAppHost" runtime.version)
      ]
      ++ lib.optionals (lib.versionOlder runtime.version "9") [
        (mkPackage "runtime.${targetRid}.Microsoft.NETCore.DotNetHost" runtime.version)
        (mkPackage "runtime.${targetRid}.Microsoft.NETCore.DotNetHostPolicy" runtime.version)
        (mkPackage "runtime.${targetRid}.Microsoft.NETCore.DotNetHostResolver" runtime.version)
      ];
  };

  sdk = mkCommon "sdk" rec {
    pname = "dotnet-sdk";
    version = releaseManifest.sdkVersion;

    src = vmr;
    dontUnpack = true;

    nativeBuildInputs = [
      xmlstarlet
      strip-nondeterminism
      zip
    ];

    outputs = [
      "out"
      "artifacts"
    ];

    installPhase = ''
      runHook preInstall

      cp -r "$src"/dotnet-sdk-${version}-${targetRid} "$out"
      chmod +w "$out"
      mkdir "$out"/bin
      ln -s "$out"/dotnet "$out"/bin/dotnet

      mkdir -p "$artifacts"
      cp -r "$src"/Private.SourceBuilt.Artifacts.*.${targetRid}/* "$artifacts"/
      chmod +w -R "$artifacts"

      local package

      for package in "$artifacts"/{,SourceBuildReferencePackages/}*.nupkg; do
        echo packing "$package" to artifacts
        (cd "$package" && zip -rq0 "$package.tmp" .)
        strip-nondeterminism --type zip "$package.tmp"
        rm -r "$package"
        mv "$package.tmp" "$package"
      done

      runHook postInstall
    '';

    passthru = {
      inherit (vmr) icu targetRid hasILCompiler;

      inherit packages targetPackages;
    };

    meta = vmr.meta // {
      mainProgram = "dotnet";
    };
  };

  runtime = mkCommon "runtime" rec {
    pname = "dotnet-runtime";
    version = releaseManifest.runtimeVersion;

    src = vmr;
    dontUnpack = true;

    outputs = [ "out" ];

    installPhase = ''
      runHook preInstall

      cp -r "$src/dotnet-runtime-${version}-${targetRid}" "$out"
      chmod +w "$out"
      mkdir "$out"/bin
      ln -s "$out"/dotnet "$out"/bin/dotnet

      runHook postInstall
    '';

    meta = vmr.meta // {
      mainProgram = "dotnet";
    };
  };

  aspnetcore = mkCommon "aspnetcore" rec {
    pname = "dotnet-aspnetcore-runtime";
    version = releaseManifest.aspNetCoreVersion or releaseManifest.runtimeVersion;

    src = vmr;
    dontUnpack = true;

    outputs = [ "out" ];

    installPhase = ''
      runHook preInstall

      cp -r "$src/dotnet-runtime-${releaseManifest.runtimeVersion}-${targetRid}" "$out"
      chmod +w "$out"
      mkdir "$out"/bin
      ln -s "$out"/dotnet "$out"/bin/dotnet

      chmod +w "$out"/shared
      cp -Tr "$src/aspnetcore-runtime-${version}-${targetRid}" "$out"

      runHook postInstall
    '';

    meta = vmr.meta // {
      mainProgram = "dotnet";
    };
  };
in
{
  inherit
    vmr
    sdk
    runtime
    aspnetcore
    ;

}