summaryrefslogtreecommitdiffstats
path: root/pkgs/build-support/dlang/builddubpackage/default.nix
blob: 9785e2f89c741c6192f64f6c3345938ff9705f76 (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
{
  lib,
  stdenv,
  dub,
  importDubLock,
  dubSetupHook,
  dubBuildHook,
  dubCheckHook,
  ldc,
  removeReferencesTo,
}:

lib.extendMkDerivation {
  constructDrv = stdenv.mkDerivation;

  excludeDrvArgNames = [
    "dubLock"
    "compiler"
  ];

  extendDrvArgs =
    finalAttrs:
    {
      # A lockfile generated by `dub-to-nix` from the source of the package.
      # Can be either a path to the file, or an attrset already parsed with `lib.importJSON`.
      dubLock,
      compiler ? ldc,
      ...
    }@args:

    {
      dubDeps = importDubLock {
        inherit (finalAttrs) pname version;
        lock = dubLock;
      };

      strictDeps = args.strictDeps or true;
      __structuredAttrs = args.__structuredAttrs or true;

      nativeBuildInputs = args.nativeBuildInputs or [ ] ++ [
        dubSetupHook
        (dubBuildHook.override { inherit dub; })
        compiler
        removeReferencesTo
      ];

      configurePhase = ''
        runHook preConfigure
        dubFlags+=("--compiler=${lib.getExe compiler}")
        runHook postConfigure
      '';

      doCheck = args.doCheck or false;

      nativeCheckInputs = [
        (dubCheckHook.override { inherit dub; })
      ];

      preFixup = ''
        ${args.preFixup or ""}

        find "$out" -type f -exec remove-references-to ${
          lib.concatMapStringsSep " " (output: "-t ${output}") compiler.all
        } '{}' +
      '';

      disallowedReferences = args.disallowedReferences or compiler.all;

      meta = {
        platforms = dub.meta.platforms;
      }
      // args.meta or { };
    };
}