diff --git a/pkgs/build-support/fetchgit/default.nix b/pkgs/build-support/fetchgit/default.nix index 1b000fb49a99ea..22bf0446b3f926 100644 --- a/pkgs/build-support/fetchgit/default.nix +++ b/pkgs/build-support/fetchgit/default.nix @@ -11,7 +11,10 @@ in "${if matched == null then base else builtins.head matched}${appendShort}"; in lib.makeOverridable (lib.fetchers.withNormalizedHash { } ( -{ url, rev ? "HEAD", leaveDotGit ? deepClone +{ url +, tag ? null +, rev ? if tag != null then tag else "HEAD" # TODO fetching HEAD by default is problematic at best +, leaveDotGit ? deepClone , outputHash ? lib.fakeHash, outputHashAlgo ? null , fetchSubmodules ? true, deepClone ? false , branchName ? null diff --git a/pkgs/build-support/fetchgithub/default.nix b/pkgs/build-support/fetchgithub/default.nix index d27a3df7d3df77..de9912465a9374 100644 --- a/pkgs/build-support/fetchgithub/default.nix +++ b/pkgs/build-support/fetchgithub/default.nix @@ -1,7 +1,10 @@ { lib, fetchgit, fetchzip }: lib.makeOverridable ( -{ owner, repo, rev, name ? "source" +{ owner, repo +, tag ? null +, rev ? if tag != null then "refs/tags/${tag}" else null +, name ? "source" , fetchSubmodules ? false, leaveDotGit ? null , deepClone ? false, private ? false, forceFetchGit ? false , fetchLFS ? false @@ -11,6 +14,8 @@ lib.makeOverridable ( , ... # For hash agility }@args: +assert (lib.assertMsg (rev != null) "You must provide `fetchFromGitHub with a `rev` or `tag`."); + let position = (if args.meta.description or null != null @@ -24,7 +29,7 @@ let # to indicate where derivation originates, similar to make-derivation.nix's mkDerivation position = "${position.file}:${toString position.line}"; }; - passthruAttrs = removeAttrs args [ "owner" "repo" "rev" "fetchSubmodules" "forceFetchGit" "private" "githubBase" "varPrefix" ]; + passthruAttrs = removeAttrs args [ "owner" "repo" "tag" "rev" "fetchSubmodules" "forceFetchGit" "private" "githubBase" "varPrefix" ]; varBase = "NIX${lib.optionalString (varPrefix != null) "_${varPrefix}"}_GITHUB_PRIVATE_"; useFetchGit = fetchSubmodules || (leaveDotGit == true) || deepClone || forceFetchGit || fetchLFS || (sparseCheckout != []); # We prefer fetchzip in cases we don't need submodules as the hash @@ -53,7 +58,7 @@ let fetcherArgs = (if useFetchGit then { - inherit rev deepClone fetchSubmodules sparseCheckout fetchLFS; url = gitRepoUrl; + inherit tag rev deepClone fetchSubmodules sparseCheckout fetchLFS; url = gitRepoUrl; } // lib.optionalAttrs (leaveDotGit != null) { inherit leaveDotGit; } else { url = "${baseUrl}/archive/${rev}.tar.gz";