summaryrefslogtreecommitdiffstats
path: root/pkgs/development/compilers/dotnet/combine-packages.nix
blob: f6070922365e057cbeb938ae7942a5311fda557d (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
dotnetPackages:
{
  buildEnv,
  makeWrapper,
  lib,
  symlinkJoin,
  callPackage,
}:
# TODO: Rethink how we determine and/or get the CLI.
#       Possible options raised in #187118:
#         1. A separate argument for the CLI (as suggested by IvarWithoutBones
#         2. Use the highest version SDK for the CLI (as suggested by GGG)
#         3. Something else?
let
  cli = builtins.head dotnetPackages;
  mkWrapper = callPackage ./wrapper.nix { };
in
assert lib.assertMsg ((builtins.length dotnetPackages) > 0) ''
  You must include at least one package, e.g
        `with dotnetCorePackages; combinePackages [
            sdk_9_0 aspnetcore_8_0
         ];`'';
mkWrapper "sdk" (
  (buildEnv {
    name = "dotnet-combined";
    paths = dotnetPackages;
    pathsToLink = map (x: "/share/dotnet/${x}") [
      "host"
      "metadata"
      "packs"
      "sdk"
      "sdk-manifests"
      "shared"
      "templates"
    ];
    ignoreCollisions = true;
    nativeBuildInputs = [ makeWrapper ];
    postBuild = ''
      mkdir -p "$out"/bin "$out"/share/dotnet
      cp -R "${cli}"/nix-support "$out"/
      cp "${cli}"/share/dotnet/dotnet "$out"/share/dotnet
      # dotnet won't run if it's renamed, so we can't wrap it in-place
      makeWrapper "$out"/share/dotnet/dotnet "$out"/share/dotnet/.dotnet-wrapper \
        --set-default DOTNET_HOST_PATH "$out"/share/dotnet/dotnet
      # the wrapper itself can't be in $out/bin, because things follow symlinks
      # to find DOTNET_ROOT
      ln -s "$out"/share/dotnet/.dotnet-wrapper "$out"/bin/dotnet
      if [[ -e "${cli}"/share/dotnet/dnx ]]; then
        cp "${cli}"/share/dotnet/dnx "$out"/share/dotnet
        makeWrapper "$out"/share/dotnet/dnx "$out"/share/dotnet/.dnx-wrapper \
          --set-default DOTNET_HOST_PATH "$out"/share/dotnet/dotnet
        ln -s "$out"/share/dotnet/.dnx-wrapper "$out"/bin/dnx
      fi
    ''
    + lib.optionalString (cli ? man) ''
      ln -s ${cli.man} $man
    '';
    passthru = {
      pname = "dotnet";
      version = "combined";
      inherit (cli) icu hasCrossTargetBug;

      versions = lib.catAttrs "version" dotnetPackages;
      packages = lib.concatLists (lib.catAttrs "packages" dotnetPackages);
      targetPackages = lib.zipAttrsWith (_: lib.concatLists) (
        lib.catAttrs "targetPackages" dotnetPackages
      );
    };

    meta = {
      description = "${cli.meta.description or "dotnet"} (combined)";
      inherit (cli.meta)
        homepage
        license
        mainProgram
        maintainers
        platforms
        ;
    };
  }).overrideAttrs
    {
      propagatedSandboxProfile = toString (
        lib.unique (lib.concatLists (lib.catAttrs "__propagatedSandboxProfile" dotnetPackages))
      );
    }
)