summary refs log tree commit diff
path: root/pkgs/build-support/fetchs3/default.nix
blob: b3b6aed9c551310f24a31122a3b9e52f500926ec (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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" ({
  nativeBuildInputs = [ 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
'')