summaryrefslogtreecommitdiffstats
path: root/pkgs/development/compilers/dotnet/default.nix
blob: 3b38f31d8e4eb42c37e009cc5f03ae83703362d3 (plain)
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
/*
  How to combine packages for use in development:
  dotnetCombined = with dotnetCorePackages; combinePackages [ sdk_9_0 aspnetcore_8_0 ];

  Hashes and urls are retrieved from:
  https://dotnet.microsoft.com/download/dotnet
*/
{
  lib,
  config,
  generateSplicesForMkScope,
  makeScopeWithSplicing',
  writeScriptBin,
  buildPackages,
  newScope,
}:

makeScopeWithSplicing' {
  otherSplices = generateSplicesForMkScope "dotnetCorePackages";
  f = (
    self:
    let
      callPackage = self.callPackage;

      fetchNupkg = callPackage ../../../build-support/dotnet/fetch-nupkg { };

      buildDotnetSdk =
        let
          buildDotnet = attrs: callWithUtils (import ./binary/build-dotnet.nix attrs) { };
        in
        version:
        import version {
          inherit fetchNupkg;
          buildAspNetCore = attrs: buildDotnet (attrs // { type = "aspnetcore"; });
          buildNetRuntime = attrs: buildDotnet (attrs // { type = "runtime"; });
          buildNetSdk = attrs: buildDotnet (attrs // { type = "sdk"; });
        };

      runtimeIdentifierMap = {
        "x86_64-linux" = "linux-x64";
        "aarch64-linux" = "linux-arm64";
        "aarch64-darwin" = "osx-arm64";
        "x86_64-windows" = "win-x64";
        "i686-windows" = "win-x86";
      };

      # used to break cycle in attribute names
      callWithUtils = newScope (utils // { callPackage = callWithUtils; });

      utils = {
        inherit
          callPackage
          fetchNupkg
          buildDotnetSdk
          ;

        generate-dotnet-sdk = writeScriptBin "generate-dotnet-sdk" (
          # Don't include current nixpkgs in the exposed version. We want to make the script runnable without nixpkgs repo.
          builtins.replaceStrings [ " -I nixpkgs=./." ] [ "" ] (builtins.readFile ./binary/update.sh)
        );

        # Convert a "stdenv.hostPlatform.system" to a dotnet RID
        systemToDotnetRid =
          system: runtimeIdentifierMap.${system} or (throw "unsupported platform ${system}");

        combinePackages = attrs: callPackage (import ./combine-packages.nix attrs) { };

        patchNupkgs = buildPackages.callPackage ./patch-nupkgs.nix { };
        nugetPackageHook = callPackage ./nuget-package-hook.nix { };
        autoPatchcilHook = callPackage ../../../build-support/dotnet/auto-patchcil-hook { };

        buildDotnetModule = callPackage ../../../build-support/dotnet/build-dotnet-module { };
        buildDotnetGlobalTool = callPackage ../../../build-support/dotnet/build-dotnet-global-tool { };

        mkNugetSource = callPackage ../../../build-support/dotnet/make-nuget-source { };
        mkNugetDeps = callPackage ../../../build-support/dotnet/make-nuget-deps { };
        addNuGetDeps = callPackage ../../../build-support/dotnet/add-nuget-deps { };
      };

    in
    utils
    // (
      let
        dotnet_6 = callWithUtils ./dotnet.nix {
          channel = "6.0";
        };

        dotnet_7 = callWithUtils ./dotnet.nix {
          channel = "7.0";
        };

        dotnet_8 = callWithUtils ./dotnet.nix {
          channel = "8.0";
        };

        dotnet_9 = callWithUtils ./dotnet.nix {
          channel = "9.0";
        };

        dotnet_10 = callWithUtils ./dotnet.nix {
          channel = "10.0";
        };

        dotnet_11 = callWithUtils ./dotnet.nix {
          channel = "11.0";
        };
      in
      lib.optionalAttrs config.allowAliases {
        # EOL
        sdk_2_1 = throw "Dotnet SDK 2.1 is EOL, please use 8.0 (LTS) or 9.0 (Current)";
        sdk_2_2 = throw "Dotnet SDK 2.2 is EOL, please use 8.0 (LTS) or 9.0 (Current)";
        sdk_3_0 = throw "Dotnet SDK 3.0 is EOL, please use 8.0 (LTS) or 9.0 (Current)";
        sdk_3_1 = throw "Dotnet SDK 3.1 is EOL, please use 8.0 (LTS) or 9.0 (Current)";
        sdk_5_0 = throw "Dotnet SDK 5.0 is EOL, please use 8.0 (LTS) or 9.0 (Current)";
      }
      // lib.mergeAttrsList [
        dotnet_6
        dotnet_7
        dotnet_8
        dotnet_9
        dotnet_10
        dotnet_11
      ]
    )
  );
}