Merge pull request #131047 from SuperSandro2000/fetchfromgitlab

fetchgitlab: add deepClone, fetchSubmodules, leaveDotGit arguments

authored by Sandro and committed by GitHub 65c0fdf2 4846390c

+16 -12
+16 -12
pkgs/build-support/fetchgitlab/default.nix
··· 1 - { fetchzip, lib }: 1 + { fetchgit, fetchzip, lib }: 2 2 3 3 # gitlab example 4 4 { owner, repo, rev, domain ? "gitlab.com", name ? "source", group ? null 5 + , fetchSubmodules ? false, leaveDotGit ? false, deepClone ? false 5 6 , ... # For hash agility 6 7 } @ args: 7 8 8 - with lib; 9 - 10 9 let 11 - slug = concatStringsSep "/" 12 - ((optional (group != null) group) ++ [ owner repo ]); 10 + slug = lib.concatStringsSep "/" ((lib.optional (group != null) group) ++ [ owner repo ]); 11 + escapedSlug = lib.replaceStrings [ "." "/" ] [ "%2E" "%2F" ] slug; 12 + escapedRev = lib.replaceStrings [ "+" "%" "/" ] [ "%2B" "%25" "%2F" ] rev; 13 + passthruAttrs = removeAttrs args [ "domain" "owner" "group" "repo" "rev" ]; 13 14 14 - escapedSlug = replaceStrings ["." "/"] ["%2E" "%2F"] slug; 15 - escapedRev = replaceStrings ["+" "%" "/"] ["%2B" "%25" "%2F"] rev; 15 + useFetchGit = deepClone || fetchSubmodules || leaveDotGit; 16 + fetcher = if useFetchGit then fetchgit else fetchzip; 17 + 18 + fetcherArgs = (if useFetchGit then { 19 + inherit rev deepClone fetchSubmodules leaveDotGit; 20 + url = "https://${domain}/${slug}.git"; 21 + } else { 22 + url = "https://${domain}/api/v4/projects/${escapedSlug}/repository/archive.tar.gz?sha=${escapedRev}"; 23 + }) // passthruAttrs // { inherit name; }; 16 24 in 17 25 18 - fetchzip ({ 19 - inherit name; 20 - url = "https://${domain}/api/v4/projects/${escapedSlug}/repository/archive.tar.gz?sha=${escapedRev}"; 21 - meta.homepage = "https://${domain}/${slug}/"; 22 - } // removeAttrs args [ "domain" "owner" "group" "repo" "rev" ]) // { inherit rev; } 26 + fetcher fetcherArgs // { meta.homepage = "https://${domain}/${slug}/"; inherit rev; }