nix-helpers: 07bf3f26b2402c74ed4edc5354543613ddbfc997

     1: { cacert, git, runCmd, sanitiseName }:
     2: 
     3: with builtins;
     4: with rec {
     5:   rev = { url, ref ? "HEAD", ... }:
     6:     with rec {
     7:       # The 'REPO_REFS' env var makes it easy to specify a bunch of revs at once
     8:       repoRefStr = getEnv "REPO_REFS";
     9:       repoRefs = if repoRefStr == "" then { } else fromJSON repoRefStr;
    10: 
    11:       # The 'nix_git_rev_...' env vars make it easy to specify an individual rev
    12:       key = "${hashString "sha256" url}_${hashString "sha256" ref}";
    13:       keyRev = getEnv "nix_git_rev_${key}";
    14: 
    15:       fetchRev = runCmd "repo-${sanitiseName ref}-${sanitiseName url}" {
    16:         inherit ref url;
    17:         __noChroot = true;
    18:         cacheBuster = toString currentTime;
    19:         GIT_SSL_CAINFO = "${cacert}/etc/ssl/certs/ca-bundle.crt";
    20:         buildInputs = [ git ];
    21:       } ''
    22:         set -o pipefail
    23:         # Commit ID is first awk 'field' in the first 'record'. Wrap in quotes.
    24:         git ls-remote "$url" $ref | awk 'NR==1 {print "\""$1"\""}' > "$out"
    25:       '';
    26: 
    27:       # Get commit ID for the given ref in the given repo. Takes a few seconds.
    28:       newRev = import fetchRev;
    29:     };
    30:     # 'rev' can be given by the env vars 'REPO_REFS' or 'nix_git_rev_...'. If
    31:     # not found in either, we run 'newRev' to query the URL for the latest
    32:     # version.
    33:     if hasAttr url repoRefs then
    34:       getAttr url repoRefs
    35:     else if keyRev == "" then
    36:       newRev
    37:     else
    38:       keyRev;
    39: };
    40: rev

Generated by git2html.