3
0
Fork 0
forked from mirrors/nixpkgs
nixpkgs/pkgs/build-support/fetchs3/default.nix

37 lines
950 B
Nix
Raw Normal View History

2021-01-27 05:50:30 +00:00
{ lib, stdenvNoCC, runCommand, awscli }:
2017-04-26 03:01:18 +01:00
{ s3url
, name ? builtins.baseNameOf s3url
2017-04-26 03:01:18 +01:00
, sha256
, region ? "us-east-1"
, credentials ? null # Default to looking at local EC2 metadata service
, recursiveHash ? false
, postFetch ? null
}:
let
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 03:01:18 +01:00
};
2021-01-27 05:50:30 +00:00
credentialAttrs = lib.optionalAttrs (credentials != null) (mkCredentials credentials);
in runCommand name ({
nativeBuildInputs = [ awscli ];
2017-04-26 03:01:18 +01:00
outputHashAlgo = "sha256";
outputHash = sha256;
outputHashMode = if recursiveHash then "recursive" else "flat";
preferLocalBuild = true;
AWS_DEFAULT_REGION = region;
2017-04-26 03:01:18 +01:00
} // credentialAttrs) (if postFetch != null then ''
downloadedFile="$(mktemp)"
aws s3 cp ${s3url} $downloadedFile
${postFetch}
'' else ''
aws s3 cp ${s3url} $out
'')