From 741285611f08230f44b443f0b2788dd93c4ba8d0 Mon Sep 17 00:00:00 2001 From: Jonathan Ringer Date: Fri, 4 Dec 2020 23:32:48 -0800 Subject: [PATCH] fetchgit: add lfs support --- pkgs/build-support/fetchgit/builder.sh | 1 + pkgs/build-support/fetchgit/default.nix | 9 ++++++--- pkgs/build-support/fetchgit/nix-prefetch-git | 7 +++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pkgs/build-support/fetchgit/builder.sh b/pkgs/build-support/fetchgit/builder.sh index 6ae46469738a..0047a335c76c 100644 --- a/pkgs/build-support/fetchgit/builder.sh +++ b/pkgs/build-support/fetchgit/builder.sh @@ -8,6 +8,7 @@ header "exporting $url (rev $rev) into $out" $SHELL $fetcher --builder --url "$url" --out "$out" --rev "$rev" \ ${leaveDotGit:+--leave-dotGit} \ + ${fetchLFS:+--fetch-lfs} \ ${deepClone:+--deepClone} \ ${fetchSubmodules:+--fetch-submodules} \ ${branchName:+--branch-name "$branchName"} diff --git a/pkgs/build-support/fetchgit/default.nix b/pkgs/build-support/fetchgit/default.nix index 0405951a9e40..5f5ded128de5 100644 --- a/pkgs/build-support/fetchgit/default.nix +++ b/pkgs/build-support/fetchgit/default.nix @@ -1,4 +1,4 @@ -{stdenvNoCC, git, cacert}: let +{stdenvNoCC, git, git-lfs, cacert}: let urlToName = url: rev: let inherit (stdenvNoCC.lib) removeSuffix splitString last; base = last (splitString ":" (baseNameOf (removeSuffix "/" url))); @@ -20,6 +20,7 @@ in # successfully. This can do things like check or transform the file. postFetch ? "" , preferLocalBuild ? true +, fetchLFS ? false }: /* NOTE: @@ -53,13 +54,15 @@ stdenvNoCC.mkDerivation { inherit name; builder = ./builder.sh; fetcher = ./nix-prefetch-git; # This must be a string to ensure it's called with bash. - nativeBuildInputs = [git]; + + nativeBuildInputs = [ git ] + ++ stdenvNoCC.lib.optionals fetchLFS [ git-lfs ]; outputHashAlgo = "sha256"; outputHashMode = "recursive"; outputHash = sha256; - inherit url rev leaveDotGit fetchSubmodules deepClone branchName postFetch; + inherit url rev leaveDotGit fetchLFS fetchSubmodules deepClone branchName postFetch; GIT_SSL_CAINFO = "${cacert}/etc/ssl/certs/ca-bundle.crt"; diff --git a/pkgs/build-support/fetchgit/nix-prefetch-git b/pkgs/build-support/fetchgit/nix-prefetch-git index 43f7c5acd5ad..3cb115c5e6e6 100755 --- a/pkgs/build-support/fetchgit/nix-prefetch-git +++ b/pkgs/build-support/fetchgit/nix-prefetch-git @@ -9,6 +9,7 @@ hashType=$NIX_HASH_ALGO deepClone=$NIX_PREFETCH_GIT_DEEP_CLONE leaveDotGit=$NIX_PREFETCH_GIT_LEAVE_DOT_GIT fetchSubmodules= +fetchLFS= builder= branchName=$NIX_PREFETCH_GIT_BRANCH_NAME @@ -72,6 +73,7 @@ for arg; do --quiet) QUIET=true;; --no-deepClone) deepClone=;; --leave-dotGit) leaveDotGit=true;; + --fetch-lfs) fetchLFS=true;; --fetch-submodules) fetchSubmodules=true;; --builder) builder=true;; -h|--help) usage; exit;; @@ -283,6 +285,11 @@ clone_user_rev() { local url="$2" local rev="${3:-HEAD}" + if [ -n "$fetchLFS" ]; then + HOME=$TMPDIR + git lfs install + fi + # Perform the checkout. case "$rev" in HEAD|refs/*)