From 94848bd430750f523706a42371bb0b268e75c695 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Thu, 22 Jul 2021 11:29:02 +0200 Subject: [PATCH] fetchgitlab: add deepClone, fetchSubmodules, leaveDotGit arguments --- pkgs/build-support/fetchgitlab/default.nix | 28 ++++++++++++---------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/pkgs/build-support/fetchgitlab/default.nix b/pkgs/build-support/fetchgitlab/default.nix index 77512510a7c..5b9dbd71c59 100644 --- a/pkgs/build-support/fetchgitlab/default.nix +++ b/pkgs/build-support/fetchgitlab/default.nix @@ -1,22 +1,26 @@ -{ fetchzip, lib }: +{ fetchgit, fetchzip, lib }: # gitlab example { owner, repo, rev, domain ? "gitlab.com", name ? "source", group ? null +, fetchSubmodules ? false, leaveDotGit ? false, deepClone ? false , ... # For hash agility } @ args: -with lib; - let - slug = concatStringsSep "/" - ((optional (group != null) group) ++ [ owner repo ]); + 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 [ "domain" "owner" "group" "repo" "rev" ]; - escapedSlug = replaceStrings ["." "/"] ["%2E" "%2F"] slug; - escapedRev = replaceStrings ["+" "%" "/"] ["%2B" "%25" "%2F"] rev; + useFetchGit = deepClone || fetchSubmodules || leaveDotGit; + fetcher = if useFetchGit then fetchgit else fetchzip; + + fetcherArgs = (if useFetchGit then { + inherit rev deepClone fetchSubmodules leaveDotGit; + url = "https://${domain}/${slug}.git"; + } else { + url = "https://${domain}/api/v4/projects/${escapedSlug}/repository/archive.tar.gz?sha=${escapedRev}"; + }) // passthruAttrs // { inherit name; }; in -fetchzip ({ - inherit name; - url = "https://${domain}/api/v4/projects/${escapedSlug}/repository/archive.tar.gz?sha=${escapedRev}"; - meta.homepage = "https://${domain}/${slug}/"; -} // removeAttrs args [ "domain" "owner" "group" "repo" "rev" ]) // { inherit rev; } +fetcher fetcherArgs // { meta.homepage = "https://${domain}/${slug}/"; inherit rev; }