From 020a0dd7e3033bc3a3abee787b810c282733de9a Mon Sep 17 00:00:00 2001 From: isabel Date: Sat, 8 Nov 2025 12:37:13 +0000 Subject: [PATCH] WIP --- fetcher.nix | 220 ++++++++++++++++++++++++++++------------------------ 1 file changed, 117 insertions(+), 103 deletions(-) diff --git a/fetcher.nix b/fetcher.nix index 5cfbcc4..a3ab490 100644 --- a/fetcher.nix +++ b/fetcher.nix @@ -10,119 +10,133 @@ { lib, repoRevToNameMaybe, + stdenvNoCC, fetchgit, fetchzip, }: lib.makeOverridable ( - { - domain ? "tangled.sh", - owner, - repo, - rev ? null, - tag ? null, - name ? repoRevToNameMaybe repo (lib.revOrTag rev tag) "tangled", - - # fetchgit stuff - fetchSubmodules ? false, - leaveDotGit ? false, - deepClone ? false, - forceFetchGit ? false, - fetchLFS ? false, - sparseCheckout ? [ ], - - meta ? { }, - ... - }@args: - - assert lib.assertMsg (lib.xor (tag != null) ( - rev != null - )) "fetchFromTangled requires one of either `rev` or `tag` to be provided (not both)."; - - let - - position = ( - if args.meta.description or null != null then - builtins.unsafeGetAttrPos "description" args.meta - else if tag != null then - builtins.unsafeGetAttrPos "tag" args - else - builtins.unsafeGetAttrPos "rev" args - ); - - baseUrl = "https://${domain}/${owner}/${repo}"; - - newMeta = - meta - // { - homepage = meta.homepage or baseUrl; - } - // lib.optionalAttrs (position != null) { - # to indicate where derivation originates, similar to make-derivation.nix's mkDerivation - position = "${position.file}:${toString position.line}"; - }; + lib.extendMkDerivation { + constructDrv = stdenvNoCC.mkDerivation; + + excludeDrvArgNames = [ + # Additional stdenv.mkDerivation arguments from derived fetchers. + "derivationArgs" - passthruAttrs = removeAttrs args [ - "domain" - "owner" - "repo" - "tag" - "rev" - "fetchSubmodules" - "forceFetchGit" + "hash" ]; - useFetchGit = - fetchSubmodules || leaveDotGit || deepClone || forceFetchGit || fetchLFS || (sparseCheckout != [ ]); - - # We prefer fetchzip in cases we don't need submodules as the hash - # is more stable in that case. - fetcher = - if useFetchGit then - fetchgit - # fetchzip may not be overridable when using external tools, for example nix-prefetch - else if fetchzip ? override then - fetchzip.override { withUnzip = false; } - else - fetchzip; - - revWithTag = if tag != null then "refs%2Ftags%2F${tag}" else rev; - - fetcherArgs = - ( - if useFetchGit then - { - inherit - tag - rev - deepClone - fetchSubmodules - sparseCheckout - fetchLFS - leaveDotGit - ; - url = baseUrl; + extendDrvArgs = + finalAttrs: + { + domain ? "tangled.sh", + owner, + repo, + rev ? null, + tag ? null, + name ? repoRevToNameMaybe repo (lib.revOrTag rev tag) "tangled", + + # fetchgit stuff + fetchSubmodules ? false, + leaveDotGit ? false, + deepClone ? false, + forceFetchGit ? false, + fetchLFS ? false, + sparseCheckout ? [ ], + + meta ? { }, + ... + }@args: + + assert lib.assertMsg (lib.xor (tag != null) ( + rev != null + )) "fetchFromTangled requires one of either `rev` or `tag` to be provided (not both)."; + + let + + position = ( + if args.meta.description or null != null then + builtins.unsafeGetAttrPos "description" args.meta + else if tag != null then + builtins.unsafeGetAttrPos "tag" args + else + builtins.unsafeGetAttrPos "rev" args + ); + + baseUrl = "https://${domain}/${owner}/${repo}"; + + newMeta = + meta + // { + homepage = meta.homepage or baseUrl; } - else - { - url = "${baseUrl}/archive/${revWithTag}"; - extension = "tar.gz"; - - passthru = { - gitRepoUrl = baseUrl; - }; - } - ) - // passthruAttrs + // lib.optionalAttrs (position != null) { + # to indicate where derivation originates, similar to make-derivation.nix's mkDerivation + position = "${position.file}:${toString position.line}"; + }; + + passthruAttrs = removeAttrs args [ + "domain" + "owner" + "repo" + "tag" + "rev" + "fetchSubmodules" + "forceFetchGit" + ]; + + useFetchGit = + fetchSubmodules || leaveDotGit || deepClone || forceFetchGit || fetchLFS || (sparseCheckout != [ ]); + + # We prefer fetchzip in cases we don't need submodules as the hash + # is more stable in that case. + fetcher = + if useFetchGit then + fetchgit + # fetchzip may not be overridable when using external tools, for example nix-prefetch + else if fetchzip ? override then + fetchzip.override { withUnzip = false; } + else + fetchzip; + + revWithTag = if tag != null then "refs%2Ftags%2F${tag}" else rev; + + fetcherArgs = + ( + if useFetchGit then + { + inherit + tag + rev + deepClone + fetchSubmodules + sparseCheckout + fetchLFS + leaveDotGit + ; + url = baseUrl; + } + else + { + url = "${baseUrl}/archive/${revWithTag}"; + extension = "tar.gz"; + + passthru = { + gitRepoUrl = baseUrl; + }; + } + ) + // passthruAttrs + // { + inherit name; + }; + in + + fetcher fetcherArgs // { - inherit name; + meta = newMeta; + inherit owner repo tag; + rev = revWithTag; }; - in - - fetcher fetcherArgs - // { - meta = newMeta; - inherit owner repo tag; - rev = revWithTag; } ) -- 2.43.0