mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-25 00:12:56 +00:00
fetchs3: support hash
attribute
This commit is contained in:
parent
b5aefcd40a
commit
1ccd5ba540
@ -1,36 +1,37 @@
|
|||||||
{ lib, runCommand, awscli }:
|
{ lib, runCommand, awscli }:
|
||||||
|
lib.fetchers.withNormalizedHash { } (
|
||||||
|
{ s3url
|
||||||
|
, name ? builtins.baseNameOf s3url
|
||||||
|
, outputHash
|
||||||
|
, outputHashAlgo
|
||||||
|
, region ? "us-east-1"
|
||||||
|
, credentials ? null # Default to looking at local EC2 metadata service
|
||||||
|
, recursiveHash ? false
|
||||||
|
, postFetch ? null
|
||||||
|
}:
|
||||||
|
|
||||||
{ s3url
|
let
|
||||||
, name ? builtins.baseNameOf s3url
|
mkCredentials = { access_key_id, secret_access_key, session_token ? null }: {
|
||||||
, sha256
|
AWS_ACCESS_KEY_ID = access_key_id;
|
||||||
, region ? "us-east-1"
|
AWS_SECRET_ACCESS_KEY = secret_access_key;
|
||||||
, credentials ? null # Default to looking at local EC2 metadata service
|
AWS_SESSION_TOKEN = session_token;
|
||||||
, recursiveHash ? false
|
};
|
||||||
, postFetch ? null
|
|
||||||
}:
|
|
||||||
|
|
||||||
let
|
credentialAttrs = lib.optionalAttrs (credentials != null) (mkCredentials credentials);
|
||||||
mkCredentials = { access_key_id, secret_access_key, session_token ? null }: {
|
in runCommand name ({
|
||||||
AWS_ACCESS_KEY_ID = access_key_id;
|
nativeBuildInputs = [ awscli ];
|
||||||
AWS_SECRET_ACCESS_KEY = secret_access_key;
|
|
||||||
AWS_SESSION_TOKEN = session_token;
|
|
||||||
};
|
|
||||||
|
|
||||||
credentialAttrs = lib.optionalAttrs (credentials != null) (mkCredentials credentials);
|
inherit outputHash outputHashAlgo;
|
||||||
in runCommand name ({
|
outputHashMode = if recursiveHash then "recursive" else "flat";
|
||||||
nativeBuildInputs = [ awscli ];
|
|
||||||
|
|
||||||
outputHashAlgo = "sha256";
|
preferLocalBuild = true;
|
||||||
outputHash = sha256;
|
|
||||||
outputHashMode = if recursiveHash then "recursive" else "flat";
|
|
||||||
|
|
||||||
preferLocalBuild = true;
|
AWS_DEFAULT_REGION = region;
|
||||||
|
} // credentialAttrs) (if postFetch != null then ''
|
||||||
AWS_DEFAULT_REGION = region;
|
downloadedFile="$(mktemp)"
|
||||||
} // credentialAttrs) (if postFetch != null then ''
|
aws s3 cp ${s3url} $downloadedFile
|
||||||
downloadedFile="$(mktemp)"
|
${postFetch}
|
||||||
aws s3 cp ${s3url} $downloadedFile
|
'' else ''
|
||||||
${postFetch}
|
aws s3 cp ${s3url} $out
|
||||||
'' else ''
|
'')
|
||||||
aws s3 cp ${s3url} $out
|
)
|
||||||
'')
|
|
||||||
|
Loading…
Reference in New Issue
Block a user