Refactor fetchHex out of buildHex.

This will allow to reuse this code to fetch rebar3's dependencies to
ensure it's hermetic build.
This commit is contained in:
Gleb Peregud 2015-12-13 23:12:08 +01:00
parent acaf2c179e
commit 033902d269
3 changed files with 42 additions and 12 deletions

View File

@ -1,4 +1,4 @@
{ stdenv, erlang, rebar3, openssl, libyaml, fetchurl, fetchFromGitHub, { stdenv, erlang, rebar3, openssl, libyaml, fetchHex, fetchFromGitHub,
rebar3-pc }: rebar3-pc }:
{ name, version, sha256 { name, version, sha256
@ -16,6 +16,12 @@ stdenv.mkDerivation (attrs // {
buildInputs = buildInputs ++ [ erlang rebar3 openssl libyaml ]; buildInputs = buildInputs ++ [ erlang rebar3 openssl libyaml ];
src = fetchHex {
pkg = hexPkg;
inherit version;
inherit sha256;
};
postPatch = let postPatch = let
registrySnapshot = import ./registrySnapshot.nix { inherit fetchFromGitHub; }; registrySnapshot = import ./registrySnapshot.nix { inherit fetchFromGitHub; };
in '' in ''
@ -35,12 +41,6 @@ stdenv.mkDerivation (attrs // {
${postPatch} ${postPatch}
''; '';
unpackCmd = ''
tar -xf $curSrc contents.tar.gz
mkdir contents
tar -C contents -xzf contents.tar.gz
'';
configurePhase = let configurePhase = let
plugins = pluginDeps ++ (if compilePorts then [rebar3-pc] else []); plugins = pluginDeps ++ (if compilePorts then [rebar3-pc] else []);
getDeps = drv: [drv] ++ (map getDeps drv.erlangDeps); getDeps = drv: [drv] ++ (map getDeps drv.erlangDeps);
@ -84,11 +84,6 @@ stdenv.mkDerivation (attrs // {
runHook postInstall runHook postInstall
''; '';
src = fetchurl {
url = "https://s3.amazonaws.com/s3.hex.pm/tarballs/${hexPkg}-${version}.tar";
sha256 = sha256;
};
meta = { meta = {
inherit (erlang.meta) platforms; inherit (erlang.meta) platforms;
} // meta; } // meta;

View File

@ -0,0 +1,34 @@
{ stdenv, fetchurl }:
{ pkg, version, sha256
, meta ? {}
}:
with stdenv.lib;
stdenv.mkDerivation ({
name = "hex-source-${pkg}-${version}";
src = fetchurl {
url = "https://s3.amazonaws.com/s3.hex.pm/tarballs/${pkg}-${version}.tar";
inherit sha256;
};
phases = [ "unpackPhase" "installPhase" ];
unpackCmd = ''
tar -xf $curSrc contents.tar.gz
mkdir contents
tar -C contents -xzf contents.tar.gz
'';
installPhase = ''
runHook preInstall
mkdir "$out"
cp -Hrt "$out" .
success=1
runHook postInstall
'';
inherit meta;
})

View File

@ -5020,6 +5020,7 @@ let
rebar = callPackage ../development/tools/build-managers/rebar { }; rebar = callPackage ../development/tools/build-managers/rebar { };
rebar3 = callPackage ../development/tools/build-managers/rebar3 { }; rebar3 = callPackage ../development/tools/build-managers/rebar3 { };
fetchHex = callPackage ../development/tools/build-managers/rebar3/fetch-hex.nix { };
erlangPackages = callPackage ../development/erlang-modules { }; erlangPackages = callPackage ../development/erlang-modules { };