1{
2 lib,
3 stdenv,
4 fetchurl,
5}:
6
7{
8 pkg,
9 version,
10 sha256,
11 meta ? { },
12}:
13
14stdenv.mkDerivation ({
15 pname = pkg;
16 inherit version;
17 dontBuild = true;
18 dontConfigure = true;
19 dontFixup = true;
20
21 src = fetchurl {
22 url = "https://repo.hex.pm/tarballs/${pkg}-${version}.tar";
23 inherit sha256;
24 };
25
26 unpackCmd = ''
27 tar -xf $curSrc contents.tar.gz CHECKSUM metadata.config
28 mkdir contents
29 tar -C contents -xzf contents.tar.gz
30 mv metadata.config contents/hex_metadata.config
31
32 # To make the extracted hex tarballs appear legitimate to mix, we need to
33 # make sure they contain not just the contents of contents.tar.gz but also
34 # a .hex file with some lock metadata.
35 # We use an old version of .hex file per hex's mix_task_test.exs since it
36 # is just plain-text instead of an encoded format.
37 # See: https://github.com/hexpm/hex/blob/main/test/hex/mix_task_test.exs#L410
38 echo -n "${pkg},${version},$(cat CHECKSUM | tr '[:upper:]' '[:lower:]'),hexpm" > contents/.hex
39 '';
40
41 installPhase = ''
42 runHook preInstall
43 mkdir "$out"
44 cp -Hrt "$out" .
45 success=1
46 runHook postInstall
47 '';
48
49 inherit meta;
50})