diff --git a/doc/build-helpers/fetchers.chapter.md b/doc/build-helpers/fetchers.chapter.md index 6a6ebe9013c2..08b978e720dc 100644 --- a/doc/build-helpers/fetchers.chapter.md +++ b/doc/build-helpers/fetchers.chapter.md @@ -896,6 +896,24 @@ If `fetchSubmodules` is `true`, `fetchFromSourcehut` uses `fetchgit` or `fetchhg` with `fetchSubmodules` or `fetchSubrepos` set to `true`, respectively. Otherwise, the fetcher uses `fetchzip`. +## `fetchFromRadicle` {#fetchfromradicle} + +This is used with Radicle repositories. The arguments expected are similar to `fetchgit`. + +Requires a `seed` argument (e.g. `seed.radicle.xyz` or `rosa.radicle.xyz`) and a `repo` argument +(the repository id *without* the `rad:` prefix). Also accepts an optional `node` argument which +contains the id of the node from which to fetch the specified ref. If `node` is `null` (the +default), a canonical ref is fetched instead. + +```nix +fetchFromRadicle { + seed = "seed.radicle.xyz"; + repo = "z3gqcJUoA1n9HaHKufZs5FCSGazv5"; # heartwood + tag = "releases/1.3.0"; + hash = "sha256-4o88BWKGGOjCIQy7anvzbA/kPOO+ZsLMzXJhE61odjw="; +} +``` + ## `requireFile` {#requirefile} `requireFile` allows requesting files that cannot be fetched automatically, but whose content is known. diff --git a/doc/redirects.json b/doc/redirects.json index 685e93538f85..7b0841c639b7 100644 --- a/doc/redirects.json +++ b/doc/redirects.json @@ -1666,6 +1666,9 @@ "fetchfromsourcehut": [ "index.html#fetchfromsourcehut" ], + "fetchfromradicle": [ + "index.html#fetchfromradicle" + ], "requirefile": [ "index.html#requirefile" ], diff --git a/pkgs/build-support/fetchradicle/default.nix b/pkgs/build-support/fetchradicle/default.nix new file mode 100644 index 000000000000..a8102c382c02 --- /dev/null +++ b/pkgs/build-support/fetchradicle/default.nix @@ -0,0 +1,44 @@ +{ lib, fetchgit }: + +lib.makeOverridable ( + { + seed, + repo, + node ? null, + rev ? null, + tag ? null, + ... + }@args: + + assert lib.assertMsg (lib.xor (tag != null) ( + rev != null + )) "fetchFromRadicle requires one of either `rev` or `tag` to be provided (not both)."; + + let + namespacePrefix = lib.optionalString (node != null) "refs/namespaces/${node}/"; + rev' = if tag != null then "refs/tags/${tag}" else rev; + in + + fetchgit ( + { + url = "https://${seed}/${repo}.git"; + rev = "${namespacePrefix}${rev'}"; + } + // removeAttrs args [ + "seed" + "repo" + "node" + "rev" + "tag" + ] + ) + // { + inherit + seed + repo + node + rev + tag + ; + } +) diff --git a/pkgs/by-name/ra/radicle-explorer/package.nix b/pkgs/by-name/ra/radicle-explorer/package.nix index 6c467f96b1e1..15686e7c5a94 100644 --- a/pkgs/by-name/ra/radicle-explorer/package.nix +++ b/pkgs/by-name/ra/radicle-explorer/package.nix @@ -1,7 +1,6 @@ { radicle-httpd, fetchFromGitHub, - fetchgit, lib, buildNpmPackage, writeText, @@ -75,9 +74,9 @@ lib.fix ( # same repo. For this reason we pin the sources to each other, but due to # radicle-httpd using a more limited sparse checkout we need to carry a # separate hash. - src = fetchgit { - inherit (radicle-httpd.src) url rev; - hash = "sha256-HRSrLdiDETTWNF+Rzvlg1XQerXcCE2xaY+6Xbq5pItI="; + src = radicle-httpd.src.override { + hash = "sha256-1OhZ0x21NlZIiTPCRpvdUsx5UmeLecTjVzH8DWllPr8="; + sparseCheckout = [ ]; }; postPatch = '' diff --git a/pkgs/by-name/ra/radicle-httpd/package.nix b/pkgs/by-name/ra/radicle-httpd/package.nix index d4067fff8029..7ff24edcab0d 100644 --- a/pkgs/by-name/ra/radicle-httpd/package.nix +++ b/pkgs/by-name/ra/radicle-httpd/package.nix @@ -1,6 +1,6 @@ { asciidoctor, - fetchgit, + fetchFromRadicle, git, installShellFiles, lib, @@ -16,11 +16,13 @@ rustPlatform.buildRustPackage rec { env.RADICLE_VERSION = version; # You must update the radicle-explorer source hash when changing this. - src = fetchgit { - url = "https://seed.radicle.xyz/z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git"; - rev = "refs/namespaces/z6MkireRatUThvd3qzfKht1S44wpm4FEWSSa4PRMTSQZ3voM/refs/tags/v${version}"; - hash = "sha256-9rJH4ECqOJ9wnYxCbEFHXo3PlhbPdeOnF+Pf1MzX25c="; + src = fetchFromRadicle { + seed = "seed.radicle.xyz"; + repo = "z4V1sjrXqjvFdnCUbxPFqd5p4DtH5"; + node = "z6MkireRatUThvd3qzfKht1S44wpm4FEWSSa4PRMTSQZ3voM"; + tag = "v${version}"; sparseCheckout = [ "radicle-httpd" ]; + hash = "sha256-9rJH4ECqOJ9wnYxCbEFHXo3PlhbPdeOnF+Pf1MzX25c="; }; sourceRoot = "${src.name}/radicle-httpd"; diff --git a/pkgs/by-name/ra/radicle-node/package.nix b/pkgs/by-name/ra/radicle-node/package.nix index 15da4c6ec221..347044035a06 100644 --- a/pkgs/by-name/ra/radicle-node/package.nix +++ b/pkgs/by-name/ra/radicle-node/package.nix @@ -1,6 +1,6 @@ { asciidoctor, - fetchgit, + fetchFromRadicle, git, installShellFiles, jq, @@ -22,9 +22,11 @@ rustPlatform.buildRustPackage rec { version = "1.3.0"; env.RADICLE_VERSION = version; - src = fetchgit { - url = "https://seed.radicle.xyz/z3gqcJUoA1n9HaHKufZs5FCSGazv5.git"; - rev = "refs/namespaces/z6MkireRatUThvd3qzfKht1S44wpm4FEWSSa4PRMTSQZ3voM/refs/tags/v${version}"; + src = fetchFromRadicle { + seed = "seed.radicle.xyz"; + repo = "z3gqcJUoA1n9HaHKufZs5FCSGazv5"; + node = "z6MkireRatUThvd3qzfKht1S44wpm4FEWSSa4PRMTSQZ3voM"; + tag = "v${version}"; hash = "sha256-0gK+fM/YGGpxlcR1HQixbLK0/sv+HH29h6ajEP2w2pI="; leaveDotGit = true; postFetch = '' diff --git a/pkgs/by-name/ra/radicle-tui/package.nix b/pkgs/by-name/ra/radicle-tui/package.nix index 46f954274414..0135691e39dd 100644 --- a/pkgs/by-name/ra/radicle-tui/package.nix +++ b/pkgs/by-name/ra/radicle-tui/package.nix @@ -1,7 +1,7 @@ { lib, rustPlatform, - fetchgit, + fetchFromRadicle, stdenv, libiconv, zlib, @@ -13,9 +13,11 @@ rustPlatform.buildRustPackage (finalAttrs: { pname = "radicle-tui"; version = "0.6.0"; - src = fetchgit { - url = "https://seed.radicle.xyz/z39mP9rQAaGmERfUMPULfPUi473tY.git"; - rev = "refs/namespaces/z6MkswQE8gwZw924amKatxnNCXA55BMupMmRg7LvJuim2C1V/refs/tags/${finalAttrs.version}"; + src = fetchFromRadicle { + seed = "seed.radicle.xyz"; + repo = "z39mP9rQAaGmERfUMPULfPUi473tY"; + node = "z6MkswQE8gwZw924amKatxnNCXA55BMupMmRg7LvJuim2C1V"; + tag = finalAttrs.version; hash = "sha256-rz9l9GtycqZoROUI6Hn0Fv5Br0YCIrcHlEWLMP4hasQ="; leaveDotGit = true; postFetch = '' diff --git a/pkgs/by-name/ra/radicle-tui/update.sh b/pkgs/by-name/ra/radicle-tui/update.sh index 2f423909a9de..36a50daf217f 100755 --- a/pkgs/by-name/ra/radicle-tui/update.sh +++ b/pkgs/by-name/ra/radicle-tui/update.sh @@ -6,13 +6,10 @@ set -euo pipefail dirname="$(dirname "${BASH_SOURCE[0]}")" url=$(nix-instantiate --eval --raw -A radicle-tui.src.url) -old_ref=$(nix-instantiate --eval --raw -A radicle-tui.src.rev) -new_ref=$(git ls-remote "$url" 'refs/namespaces/*/refs/tags/*' | cut -f2 | tail -1) +old_node=$(nix-instantiate --eval --raw -A radicle-tui.src.node) -[[ "$old_ref" =~ ^refs/namespaces/([^/]+)/refs/tags/([^/]+)$ ]] -old_node="${BASH_REMATCH[1]}" - -[[ "$new_ref" =~ ^refs/namespaces/([^/]+)/refs/tags/([^/]+)$ ]] +ref=$(git ls-remote "$url" 'refs/namespaces/*/refs/tags/*' | cut -f2 | tail -1) +[[ "$ref" =~ ^refs/namespaces/([^/]+)/refs/tags/([^/]+)$ ]] new_node="${BASH_REMATCH[1]}" version="${BASH_REMATCH[2]}" diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 5a8280e600fa..3072866de458 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -697,6 +697,8 @@ with pkgs; fetchFromRepoOrCz = callPackage ../build-support/fetchrepoorcz { }; + fetchFromRadicle = callPackage ../build-support/fetchradicle { }; + fetchgx = callPackage ../build-support/fetchgx { }; fetchPypi = callPackage ../build-support/fetchpypi { };