1{ 2 lib, 3 repoRevToNameMaybe, 4 fetchgit, 5 fetchhg, 6 fetchzip, 7}: 8 9let 10 inherit (lib) 11 assertOneOf 12 makeOverridable 13 optionalString 14 ; 15in 16 17makeOverridable ( 18 { 19 owner, 20 repo, 21 rev ? null, 22 tag ? null, 23 name ? repoRevToNameMaybe repo (lib.revOrTag rev tag) "sourcehut", 24 domain ? "sr.ht", 25 vc ? "git", 26 fetchSubmodules ? false, 27 ... # For hash agility 28 }@args: 29 30 assert ( 31 lib.assertMsg (lib.xor (tag == null) ( 32 rev == null 33 )) "fetchFromSourcehut requires one of either `rev` or `tag` to be provided (not both)." 34 ); 35 36 assert ( 37 assertOneOf "vc" vc [ 38 "hg" 39 "git" 40 ] 41 ); 42 43 let 44 urlFor = resource: "https://${resource}.${domain}/${owner}/${repo}"; 45 rev' = if tag != null then tag else rev; 46 baseUrl = urlFor vc; 47 baseArgs = { 48 inherit name; 49 } 50 // removeAttrs args [ 51 "owner" 52 "repo" 53 "rev" 54 "tag" 55 "domain" 56 "vc" 57 "name" 58 "fetchSubmodules" 59 ]; 60 vcArgs = baseArgs // { 61 rev = rev'; 62 url = baseUrl; 63 }; 64 fetcher = if fetchSubmodules then vc else "zip"; 65 cases = { 66 git = { 67 fetch = fetchgit; 68 arguments = vcArgs // { 69 fetchSubmodules = true; 70 }; 71 }; 72 hg = { 73 fetch = fetchhg; 74 arguments = vcArgs // { 75 fetchSubrepos = true; 76 }; 77 }; 78 zip = { 79 fetch = fetchzip; 80 arguments = baseArgs // { 81 url = "${baseUrl}/archive/${rev'}.tar.gz"; 82 postFetch = optionalString (vc == "hg") '' 83 rm -f "$out/.hg_archival.txt" 84 ''; # impure file; see #12002 85 passthru = (args.passthru or { }) // { 86 gitRepoUrl = urlFor "git"; 87 }; 88 }; 89 }; 90 }; 91 in 92 cases.${fetcher}.fetch cases.${fetcher}.arguments 93 // { 94 rev = rev'; 95 meta.homepage = "${baseUrl}"; 96 } 97)