From c2ec9234e8f7017ee4831ad010e9fd70118fa905 Mon Sep 17 00:00:00 2001 From: Defelo Date: Sat, 30 Aug 2025 15:05:40 +0200 Subject: [PATCH] fetchRadiclePatch: init --- doc/build-helpers/fetchers.chapter.md | 15 +++++++ doc/redirects.json | 3 ++ .../fetchradiclepatch/default.nix | 43 +++++++++++++++++++ pkgs/top-level/all-packages.nix | 1 + 4 files changed, 62 insertions(+) create mode 100644 pkgs/build-support/fetchradiclepatch/default.nix diff --git a/doc/build-helpers/fetchers.chapter.md b/doc/build-helpers/fetchers.chapter.md index 08b978e720dc..866bde570f8a 100644 --- a/doc/build-helpers/fetchers.chapter.md +++ b/doc/build-helpers/fetchers.chapter.md @@ -914,6 +914,21 @@ fetchFromRadicle { } ``` +## `fetchRadiclePatch` {#fetchradiclepatch} + +`fetchRadiclePatch` works very similarly to `fetchFromRadicle` with almost the same arguments +expected. However, instead of a `rev` or `tag` argument, a `revision` argument is expected, which +contains the full revision id of the Radicle patch to fetch. + +```nix +fetchRadiclePatch { + seed = "rosa.radicle.xyz"; + repo = "z4V1sjrXqjvFdnCUbxPFqd5p4DtH5"; # radicle-explorer + revision = "d97d872386c70607beda2fb3fc2e60449e0f4ce4"; # patch: d77e064 + hash = "sha256-ttnNqj0lhlSP6BGzEhhUOejKkkPruM9yMwA5p9Di4bk="; +} +``` + ## `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 7b0841c639b7..a5da63d7d2c2 100644 --- a/doc/redirects.json +++ b/doc/redirects.json @@ -1669,6 +1669,9 @@ "fetchfromradicle": [ "index.html#fetchfromradicle" ], + "fetchradiclepatch": [ + "index.html#fetchradiclepatch" + ], "requirefile": [ "index.html#requirefile" ], diff --git a/pkgs/build-support/fetchradiclepatch/default.nix b/pkgs/build-support/fetchradiclepatch/default.nix new file mode 100644 index 000000000000..22f9ea6c4817 --- /dev/null +++ b/pkgs/build-support/fetchradiclepatch/default.nix @@ -0,0 +1,43 @@ +{ + fetchFromRadicle, + jq, + lib, +}: + +lib.makeOverridable ( + { + revision, + postFetch ? "", + nativeBuildInputs ? [ ], + ... + }@args: + + assert lib.assertMsg ( + !args ? rev && !args ? tag + ) "fetchRadiclePatch does not accept `rev` or `tag` arguments."; + + fetchFromRadicle ( + { + nativeBuildInputs = [ jq ] ++ nativeBuildInputs; + rev = revision; + leaveDotGit = true; + postFetch = '' + { read -r head; read -r base; } < <(jq -r '.oid, .base' $out/0) + git -C $out fetch --depth=1 "$url" "$base" "$head" + git -C $out diff "$base" "$head" > patch + rm -r $out + mv patch $out + ${postFetch} + ''; + } + // removeAttrs args [ + "revision" + "postFetch" + "nativeBuildInputs" + "leaveDotGit" + ] + ) + // { + inherit revision; + } +) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index b61cf0936cf0..e1c6c4433aae 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -702,6 +702,7 @@ with pkgs; fetchFromRepoOrCz = callPackage ../build-support/fetchrepoorcz { }; fetchFromRadicle = callPackage ../build-support/fetchradicle { }; + fetchRadiclePatch = callPackage ../build-support/fetchradiclepatch { }; fetchgx = callPackage ../build-support/fetchgx { };