2015-11-19 12:11:17 +00:00
|
|
|
{ stdenv, lib, curl, jshon, python, runCommand }:
|
|
|
|
|
|
|
|
# Inspired and simplified version of fetchurl.
|
|
|
|
# For simplicity we only support sha256.
|
|
|
|
|
|
|
|
# Currently only registry v1 is supported, compatible with Docker Hub.
|
|
|
|
|
|
|
|
{ imageName, imageTag ? "latest", imageId ? null
|
|
|
|
, sha256, name ? "${imageName}-${imageTag}"
|
|
|
|
, indexUrl ? "https://index.docker.io"
|
|
|
|
, registryVersion ? "v1"
|
|
|
|
, curlOpts ? "" }:
|
|
|
|
|
2016-01-27 19:48:04 +00:00
|
|
|
assert registryVersion == "v1";
|
|
|
|
|
2015-11-19 12:11:17 +00:00
|
|
|
let layer = stdenv.mkDerivation {
|
|
|
|
inherit name imageName imageTag imageId
|
2016-01-27 19:48:04 +00:00
|
|
|
indexUrl registryVersion curlOpts;
|
2015-11-19 12:11:17 +00:00
|
|
|
|
|
|
|
builder = ./pull.sh;
|
|
|
|
detjson = ./detjson.py;
|
|
|
|
|
|
|
|
buildInputs = [ curl jshon python ];
|
|
|
|
|
|
|
|
outputHashAlgo = "sha256";
|
|
|
|
outputHash = sha256;
|
|
|
|
outputHashMode = "recursive";
|
|
|
|
|
2016-09-17 20:50:01 +01:00
|
|
|
impureEnvVars = lib.fetchers.proxyImpureEnvVars ++ [
|
2015-11-19 12:11:17 +00:00
|
|
|
# This variable allows the user to pass additional options to curl
|
|
|
|
"NIX_CURL_FLAGS"
|
|
|
|
];
|
2016-09-17 20:50:01 +01:00
|
|
|
|
2015-11-19 12:11:17 +00:00
|
|
|
# Doing the download on a remote machine just duplicates network
|
|
|
|
# traffic, so don't do that.
|
|
|
|
preferLocalBuild = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
in runCommand "${name}.tar.gz" {} ''
|
|
|
|
tar -C ${layer} -czf $out .
|
|
|
|
''
|