2018-01-10 02:38:19 +03:00
|
|
|
{ stdenvNoCC, runCommand, awscli }:
|
2017-04-26 05:01:18 +03:00
|
|
|
|
|
|
|
{ s3url
|
2018-05-03 13:08:25 +03:00
|
|
|
, name ? builtins.baseNameOf s3url
|
2017-04-26 05:01:18 +03:00
|
|
|
, sha256
|
|
|
|
, region ? "us-east-1"
|
|
|
|
, credentials ? null # Default to looking at local EC2 metadata service
|
|
|
|
, executable ? false
|
|
|
|
, recursiveHash ? false
|
|
|
|
, postFetch ? null
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2018-05-03 13:08:25 +03:00
|
|
|
mkCredentials = { access_key_id, secret_access_key, session_token ? null }: {
|
|
|
|
AWS_ACCESS_KEY_ID = access_key_id;
|
|
|
|
AWS_SECRET_ACCESS_KEY = secret_access_key;
|
|
|
|
AWS_SESSION_TOKEN = session_token;
|
2017-04-26 05:01:18 +03:00
|
|
|
};
|
2018-05-03 13:08:25 +03:00
|
|
|
|
|
|
|
credentialAttrs = stdenvNoCC.lib.optionalAttrs (credentials != null) (mkCredentials credentials);
|
|
|
|
in runCommand name ({
|
2018-01-09 23:36:14 +03:00
|
|
|
nativeBuildInputs = [ awscli ];
|
2018-05-03 13:08:25 +03:00
|
|
|
|
2017-04-26 05:01:18 +03:00
|
|
|
outputHashAlgo = "sha256";
|
|
|
|
outputHash = sha256;
|
|
|
|
outputHashMode = if recursiveHash then "recursive" else "flat";
|
2018-05-03 13:08:25 +03:00
|
|
|
|
|
|
|
preferLocalBuild = true;
|
|
|
|
|
|
|
|
AWS_DEFAULT_REGION = region;
|
2017-04-26 05:01:18 +03:00
|
|
|
} // credentialAttrs) (if postFetch != null then ''
|
|
|
|
downloadedFile="$(mktemp)"
|
|
|
|
aws s3 cp ${s3url} $downloadedFile
|
|
|
|
${postFetch}
|
|
|
|
'' else ''
|
|
|
|
aws s3 cp ${s3url} $out
|
|
|
|
'')
|