diff --git a/pkgs/build-support/fetchgitiles/default.nix b/pkgs/build-support/fetchgitiles/default.nix index 7dc26dfdf2f9e..409f2f4e2bd61 100644 --- a/pkgs/build-support/fetchgitiles/default.nix +++ b/pkgs/build-support/fetchgitiles/default.nix @@ -3,24 +3,36 @@ lib.makeOverridable ( { url, - rev, + rev ? null, + tag ? null, name ? "source", ... }@args: + assert ( + lib.assertMsg (lib.xor (tag == null) ( + rev == null + )) "fetchFromGitiles requires one of either `rev` or `tag` to be provided (not both)." + ); + + let + realrev = (if tag != null then "refs/tags/" + tag else rev); + in + fetchzip ( { inherit name; - url = "${url}/+archive/${rev}.tar.gz"; + url = "${url}/+archive/${realrev}.tar.gz"; stripRoot = false; meta.homepage = url; } // removeAttrs args [ "url" + "tag" "rev" ] ) // { - inherit rev; + inherit rev tag; } ) diff --git a/pkgs/build-support/fetchgitlab/default.nix b/pkgs/build-support/fetchgitlab/default.nix index 749883f2365eb..aef76270d5ec4 100644 --- a/pkgs/build-support/fetchgitlab/default.nix +++ b/pkgs/build-support/fetchgitlab/default.nix @@ -1,36 +1,103 @@ -{ lib, fetchgit, fetchzip }: +{ + lib, + fetchgit, + fetchzip, +}: lib.makeOverridable ( -# gitlab example -{ owner, repo, rev, protocol ? "https", domain ? "gitlab.com", name ? "source", group ? null -, fetchSubmodules ? false, leaveDotGit ? false -, deepClone ? false, forceFetchGit ? false -, sparseCheckout ? [] -, ... # For hash agility -} @ args: - -let - slug = lib.concatStringsSep "/" ((lib.optional (group != null) group) ++ [ owner repo ]); - escapedSlug = lib.replaceStrings [ "." "/" ] [ "%2E" "%2F" ] slug; - escapedRev = lib.replaceStrings [ "+" "%" "/" ] [ "%2B" "%25" "%2F" ] rev; - passthruAttrs = removeAttrs args [ "protocol" "domain" "owner" "group" "repo" "rev" "fetchSubmodules" "forceFetchGit" "leaveDotGit" "deepClone" ]; - - useFetchGit = fetchSubmodules || leaveDotGit || deepClone || forceFetchGit || (sparseCheckout != []); - fetcher = if useFetchGit then fetchgit else fetchzip; - - gitRepoUrl = "${protocol}://${domain}/${slug}.git"; - - fetcherArgs = (if useFetchGit then { - inherit rev deepClone fetchSubmodules sparseCheckout leaveDotGit; - url = gitRepoUrl; - } else { - url = "${protocol}://${domain}/api/v4/projects/${escapedSlug}/repository/archive.tar.gz?sha=${escapedRev}"; - - passthru = { - inherit gitRepoUrl; - }; - }) // passthruAttrs // { inherit name; }; -in - -fetcher fetcherArgs // { meta.homepage = "${protocol}://${domain}/${slug}/"; inherit rev owner repo; } + # gitlab example + { + owner, + repo, + rev ? null, + tag ? null, + protocol ? "https", + domain ? "gitlab.com", + name ? "source", + group ? null, + fetchSubmodules ? false, + leaveDotGit ? false, + deepClone ? false, + forceFetchGit ? false, + sparseCheckout ? [ ], + ... # For hash agility + }@args: + + assert ( + lib.assertMsg (lib.xor (tag == null) ( + rev == null + )) "fetchFromGitLab requires one of either `rev` or `tag` to be provided (not both)." + ); + + let + slug = lib.concatStringsSep "/" ( + (lib.optional (group != null) group) + ++ [ + owner + repo + ] + ); + escapedSlug = lib.replaceStrings [ "." "/" ] [ "%2E" "%2F" ] slug; + escapedRev = lib.replaceStrings [ "+" "%" "/" ] [ "%2B" "%25" "%2F" ] ( + if tag != null then "refs/tags/" + tag else rev + ); + passthruAttrs = removeAttrs args [ + "protocol" + "domain" + "owner" + "group" + "repo" + "rev" + "tag" + "fetchSubmodules" + "forceFetchGit" + "leaveDotGit" + "deepClone" + ]; + + useFetchGit = + fetchSubmodules || leaveDotGit || deepClone || forceFetchGit || (sparseCheckout != [ ]); + fetcher = if useFetchGit then fetchgit else fetchzip; + + gitRepoUrl = "${protocol}://${domain}/${slug}.git"; + + fetcherArgs = + ( + if useFetchGit then + { + inherit + rev + deepClone + tag + fetchSubmodules + sparseCheckout + leaveDotGit + ; + url = gitRepoUrl; + } + else + { + url = "${protocol}://${domain}/api/v4/projects/${escapedSlug}/repository/archive.tar.gz?sha=${escapedRev}"; + + passthru = { + inherit gitRepoUrl; + }; + } + ) + // passthruAttrs + // { + inherit name; + }; + in + + fetcher fetcherArgs + // { + meta.homepage = "${protocol}://${domain}/${slug}/"; + inherit + tag + rev + owner + repo + ; + } )