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