summary refs log tree commit diff
path: root/pkgs/build-support/fetchs3
diff options
context:
space:
mode:
authorzimbatm <zimbatm@zimbatm.com>2018-05-03 11:08:25 +0100
committerGitHub <noreply@github.com>2018-05-03 11:08:25 +0100
commitf7abcb0752c044c59766d53dc48a28d213214fb7 (patch)
treeec2a36af1339d633db2141c5911136bcf88e3b0d /pkgs/build-support/fetchs3
parent42b59439e7660997bb4a9011071df4547324f744 (diff)
downloadnixpkgs-f7abcb0752c044c59766d53dc48a28d213214fb7.tar
nixpkgs-f7abcb0752c044c59766d53dc48a28d213214fb7.tar.gz
nixpkgs-f7abcb0752c044c59766d53dc48a28d213214fb7.tar.bz2
nixpkgs-f7abcb0752c044c59766d53dc48a28d213214fb7.tar.lz
nixpkgs-f7abcb0752c044c59766d53dc48a28d213214fb7.tar.xz
nixpkgs-f7abcb0752c044c59766d53dc48a28d213214fb7.tar.zst
nixpkgs-f7abcb0752c044c59766d53dc48a28d213214fb7.zip
fetchs3: allow to name the derivation output (#39823)
* fetchs3: add configurable name

Change the default from "foo" to the basename of the s3 URL and make it
configurable.

* fetchs3: fix error on missing credentials.session_token

The session token should default to null instead of failing

* fetchs3: make use of the region argument

Set it to null if you don't want to use it

* fetchs3: prefer local build

Fetcher-types spend more time on network than CPU
Diffstat (limited to 'pkgs/build-support/fetchs3')
-rw-r--r--pkgs/build-support/fetchs3/default.nix18
1 files changed, 13 insertions, 5 deletions
diff --git a/pkgs/build-support/fetchs3/default.nix b/pkgs/build-support/fetchs3/default.nix
index e6b7a3418c0..14dac9997d9 100644
--- a/pkgs/build-support/fetchs3/default.nix
+++ b/pkgs/build-support/fetchs3/default.nix
@@ -1,6 +1,7 @@
 { stdenvNoCC, runCommand, awscli }:
 
 { s3url
+, name ? builtins.baseNameOf s3url
 , sha256
 , region ? "us-east-1"
 , credentials ? null # Default to looking at local EC2 metadata service
@@ -10,16 +11,23 @@
 }:
 
 let
-  credentialAttrs = stdenvNoCC.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;
+  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;
   };
-in runCommand "foo" ({
+
+  credentialAttrs = stdenvNoCC.lib.optionalAttrs (credentials != null) (mkCredentials credentials);
+in runCommand name ({
   nativeBuildInputs = [ awscli ];
+
   outputHashAlgo = "sha256";
   outputHash = sha256;
   outputHashMode = if recursiveHash then "recursive" else "flat";
+
+  preferLocalBuild = true;
+
+  AWS_DEFAULT_REGION = region;
 } // credentialAttrs) (if postFetch != null then ''
   downloadedFile="$(mktemp)"
   aws s3 cp ${s3url} $downloadedFile