summaryrefslogtreecommitdiffstats
path: root/pkgs/build-support/build-typst-package.nix
blob: ead6d68a139533c5cb7db915dc43a3ed8dc15803 (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
{
  lib,
  stdenvNoCC,
}:

/**
  `buildTypstPackage` is a helper builder for typst packages.

  # Inputs

    `attrs`
    : attrs for stdenvNoCC.mkDerivation + typstDeps (a list of `buildTypstPackage` derivations)

  # Example
  ```nix
  { buildTypstPackage, typstPackages }:

  buildTypstPackage {
    pname = "example";
    version = "0.0.1";
    src = ./.;
    typstDeps = with typstPackages; [ oxifmt ];
  }
  ```
*/

lib.extendMkDerivation {
  constructDrv = stdenvNoCC.mkDerivation;

  excludeDrvArgNames = [
    "typstDeps"
  ];

  extendDrvArgs =
    finalAttrs:
    {
      typstDeps ? [ ],
      ...
    }@attrs:
    {
      name = "typst-package-${finalAttrs.pname}-${finalAttrs.version}";

      strictDeps = true;
      __structuredAttrs = true;

      dontBuild = true;

      installPhase =
        let
          outDir = "$out/lib/typst-packages/${finalAttrs.pname}/${finalAttrs.version}";
        in
        ''
          runHook preInstall
          mkdir -p ${outDir}
          cp -r . ${outDir}
          runHook postInstall
        '';

      propagatedBuildInputs = typstDeps;

      passthru = {
        inherit typstDeps;
      };
    };
}