aboutsummaryrefslogtreecommitdiff
path: root/pkgs/build-support/fetchs3
diff options
context:
space:
mode:
authorDan Peebles <pumpkin@me.com>2017-04-25 22:01:18 -0400
committerDan Peebles <pumpkin@me.com>2017-04-25 22:01:32 -0400
commit9e764af72f86a9aff00e977947eeccf445e8bcf3 (patch)
tree4db2c68fb4b183db6a07e7f185db8a423f42172f /pkgs/build-support/fetchs3
parent5aa936d0ee494c3e2e33e3f1790bf9703f7f710a (diff)
fetchs3: init simple S3 downloader
Diffstat (limited to 'pkgs/build-support/fetchs3')
-rw-r--r--pkgs/build-support/fetchs3/default.nix29
1 files changed, 29 insertions, 0 deletions
diff --git a/pkgs/build-support/fetchs3/default.nix b/pkgs/build-support/fetchs3/default.nix
new file mode 100644
index 000000000000..a5cdbd150b8b
--- /dev/null
+++ b/pkgs/build-support/fetchs3/default.nix
@@ -0,0 +1,29 @@
+{ stdenv, runCommand, awscli }:
+
+{ s3url
+, sha256
+, region ? "us-east-1"
+, credentials ? null # Default to looking at local EC2 metadata service
+, executable ? false
+, recursiveHash ? false
+, postFetch ? null
+}:
+
+let
+ credentialAttrs = stdenv.lib.optionalAttrs (credentials != null) {
+ AWS_ACCESS_KEY_ID = credentials.access_key_id;
+ AWS_SECRET_ACCESS_KEY = credentials.secret_access_key;
+ AWS_SESSION_TOKEN = credentials.session_token ? null;
+ };
+in runCommand "foo" ({
+ buildInputs = [ awscli ];
+ outputHashAlgo = "sha256";
+ outputHash = sha256;
+ outputHashMode = if recursiveHash then "recursive" else "flat";
+} // credentialAttrs) (if postFetch != null then ''
+ downloadedFile="$(mktemp)"
+ aws s3 cp ${s3url} $downloadedFile
+ ${postFetch}
+'' else ''
+ aws s3 cp ${s3url} $out
+'')