about summary refs log tree commit diff
path: root/pkgs/development/compilers/dotnet/combine-deps.nix
blob: af21c3aa248ed9c35f6b0943c1485db9d41f65f4 (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
{
  list,
  baseRid,
  otherRids,
  pkgs ? import ../../../.. {}
}:
let
  inherit (pkgs) writeText;

  inherit (pkgs.lib)
    concatMap
    concatMapStringsSep
    generators
    optionals
    replaceStrings
    sortOn
    strings
    unique
    ;

  fns = map (file: import file) list;

  packages = unique
    (concatMap (fn: fn { fetchNuGet = package: package; }) fns);

  changePackageRid = package: rid:
    let replace = replaceStrings [".${baseRid}"] [".${rid}"];
    in rec {
      pname = replace package.pname;
      inherit (package) version;
      url = replace package.url;
      sha256 = builtins.hashFile "sha256" (builtins.fetchurl url);
    };

  expandPackage = package:
    [ package ] ++
    optionals (strings.match ".*\\.${baseRid}(\\..*|$)" package.pname != null)
    (map (changePackageRid package) otherRids);

  allPackages =
    sortOn (package: [ package.pname package.version ])
    (concatMap expandPackage packages);

  fetchExpr = package:
    "  (fetchNuGet ${generators.toPretty { multiline = false; } package})";

in writeText "deps.nix" ''
  { fetchNuGet }: [
  ${concatMapStringsSep "\n" fetchExpr allPackages}
  ]
''