From ef0cdab2483080236da1090515df9823ac6a7d74 Mon Sep 17 00:00:00 2001 From: wxt <3264117476@qq.com> Date: Sun, 22 Dec 2024 16:13:56 +0800 Subject: [PATCH 1/3] fetchgitlab: nixfmt --- pkgs/build-support/fetchgitlab/default.nix | 105 +++++++++++++++------ 1 file changed, 78 insertions(+), 27 deletions(-) diff --git a/pkgs/build-support/fetchgitlab/default.nix b/pkgs/build-support/fetchgitlab/default.nix index 749883f2365eb..62a8c88d3fe68 100644 --- a/pkgs/build-support/fetchgitlab/default.nix +++ b/pkgs/build-support/fetchgitlab/default.nix @@ -1,36 +1,87 @@ -{ 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: + # 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" ]; + 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; + useFetchGit = + fetchSubmodules || leaveDotGit || deepClone || forceFetchGit || (sparseCheckout != [ ]); + fetcher = if useFetchGit then fetchgit else fetchzip; - gitRepoUrl = "${protocol}://${domain}/${slug}.git"; + 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}"; + 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 + passthru = { + inherit gitRepoUrl; + }; + } + ) + // passthruAttrs + // { + inherit name; + }; + in -fetcher fetcherArgs // { meta.homepage = "${protocol}://${domain}/${slug}/"; inherit rev owner repo; } + fetcher fetcherArgs + // { + meta.homepage = "${protocol}://${domain}/${slug}/"; + inherit rev owner repo; + } ) From 4616db6469a88b99875e7804b8a21448e6ba61ef Mon Sep 17 00:00:00 2001 From: wxt <3264117476@qq.com> Date: Sun, 22 Dec 2024 16:15:05 +0800 Subject: [PATCH 2/3] fetchgitlab: add tag argument --- pkgs/build-support/fetchgitlab/default.nix | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/pkgs/build-support/fetchgitlab/default.nix b/pkgs/build-support/fetchgitlab/default.nix index 62a8c88d3fe68..aef76270d5ec4 100644 --- a/pkgs/build-support/fetchgitlab/default.nix +++ b/pkgs/build-support/fetchgitlab/default.nix @@ -9,7 +9,8 @@ lib.makeOverridable ( { owner, repo, - rev, + rev ? null, + tag ? null, protocol ? "https", domain ? "gitlab.com", name ? "source", @@ -22,6 +23,12 @@ lib.makeOverridable ( ... # 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) @@ -31,7 +38,9 @@ lib.makeOverridable ( ] ); escapedSlug = lib.replaceStrings [ "." "/" ] [ "%2E" "%2F" ] slug; - escapedRev = lib.replaceStrings [ "+" "%" "/" ] [ "%2B" "%25" "%2F" ] rev; + escapedRev = lib.replaceStrings [ "+" "%" "/" ] [ "%2B" "%25" "%2F" ] ( + if tag != null then "refs/tags/" + tag else rev + ); passthruAttrs = removeAttrs args [ "protocol" "domain" @@ -39,6 +48,7 @@ lib.makeOverridable ( "group" "repo" "rev" + "tag" "fetchSubmodules" "forceFetchGit" "leaveDotGit" @@ -58,6 +68,7 @@ lib.makeOverridable ( inherit rev deepClone + tag fetchSubmodules sparseCheckout leaveDotGit @@ -82,6 +93,11 @@ lib.makeOverridable ( fetcher fetcherArgs // { meta.homepage = "${protocol}://${domain}/${slug}/"; - inherit rev owner repo; + inherit + tag + rev + owner + repo + ; } ) From e64344cb7e53990eeb94728c37fb126cd05423b5 Mon Sep 17 00:00:00 2001 From: wxt <3264117476@qq.com> Date: Sun, 22 Dec 2024 16:12:06 +0800 Subject: [PATCH 3/3] fetchgitiles: add tag argument --- pkgs/build-support/fetchgitiles/default.nix | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) 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; } )