this repo has no description
at main 175 lines 4.4 kB view raw
1# this is really just a fork of fetchFromGitHub, but with a few changes due to 2# incompatibilities. furthermore, there is no such concept of private in 3# atproto, so all the private stuff has been removed. 4 5{ 6 lib, 7 repoRevToNameMaybe, 8 fetchgit, 9 fetchzip, 10}: 11 12let 13 14 useFetchGitArgsDefault = { 15 deepClone = false; 16 fetchSubmodules = false; # This differs from fetchgit's default 17 fetchLFS = false; 18 forceFetchGit = false; 19 leaveDotGit = null; 20 postCheckout = ""; 21 rootDir = ""; 22 sparseCheckout = null; 23 }; 24 useFetchGitArgsDefaultNullable = { 25 leaveDotGit = false; 26 sparseCheckout = [ ]; 27 }; 28 useFetchGitargsDefaultNonNull = useFetchGitArgsDefault // useFetchGitArgsDefaultNullable; 29 excludeUseFetchGitArgNames = [ 30 "forceFetchGit" 31 ]; 32 33 faUseFetchGit = lib.mapAttrs (_: _: true) useFetchGitArgsDefault; 34 35 adjustFunctionArgs = f: lib.setFunctionArgs f (faUseFetchGit // lib.functionArgs f); 36 37 decorate = f: lib.makeOverridable (adjustFunctionArgs f); 38 39in 40 41decorate ( 42 { 43 domain ? "tangled.org", 44 owner, 45 repo, 46 rev ? null, 47 tag ? null, 48 49 # TODO: add back when doing FP 50 # name ? repoRevToNameMaybe repo (lib.revOrTag rev tag) "tangled", 51 52 passthru ? { }, 53 meta ? { }, 54 ... 55 }@args: 56 57 assert lib.assertMsg (lib.xor (tag != null) ( 58 rev != null 59 )) "fetchFromTangled requires one of either `rev` or `tag` to be provided (not both)."; 60 61 let 62 63 useFetchGit = 64 lib.mapAttrs ( 65 name: nonNullDefault: 66 if args ? ${name} && (useFetchGitArgsDefaultNullable ? ${name} -> args.${name} != null) then 67 args.${name} 68 else 69 nonNullDefault 70 ) useFetchGitargsDefaultNonNull != useFetchGitargsDefaultNonNull; 71 72 useFetchGitArgsWDPassing = lib.overrideExisting (removeAttrs useFetchGitArgsDefault excludeUseFetchGitArgNames) args; 73 74 position = ( 75 if args.meta.description or null != null then 76 builtins.unsafeGetAttrPos "description" args.meta 77 else if tag != null then 78 builtins.unsafeGetAttrPos "tag" args 79 else 80 builtins.unsafeGetAttrPos "rev" args 81 ); 82 83 baseUrl = "https://${domain}/${owner}/${repo}"; 84 85 newMeta = 86 meta 87 // { 88 homepage = meta.homepage or baseUrl; 89 } 90 // lib.optionalAttrs (position != null) { 91 # to indicate where derivation originates, similar to make-derivation.nix's mkDerivation 92 position = "${position.file}:${toString position.line}"; 93 }; 94 95 passthruAttrs = removeAttrs args ( 96 [ 97 "domain" 98 "owner" 99 "repo" 100 "tag" 101 "rev" 102 "fetchSubmodules" 103 "forceFetchGit" 104 ] 105 ++ (if useFetchGit then excludeUseFetchGitArgNames else lib.attrNames faUseFetchGit) 106 ); 107 108 # We prefer fetchzip in cases we don't need submodules as the hash 109 # is more stable in that case. 110 fetcher = 111 if useFetchGit then 112 fetchgit 113 # fetchzip may not be overridable when using external tools, for example nix-prefetch 114 else if fetchzip ? override then 115 fetchzip.override { withUnzip = false; } 116 else 117 fetchzip; 118 119 fetcherArgs = 120 finalAttrs: 121 passthruAttrs 122 // ( 123 if useFetchGit then 124 useFetchGitArgsWDPassing 125 // { 126 inherit tag rev; 127 url = baseUrl; 128 inherit passthru; 129 derivationArgs = { 130 inherit 131 domain 132 owner 133 repo 134 ; 135 }; 136 } 137 else 138 let 139 revWithTag = finalAttrs.rev; 140 in 141 { 142 url = "${baseUrl}/archive/${revWithTag}"; 143 extension = "tar.gz"; 144 145 derivationArgs = { 146 inherit 147 domain 148 owner 149 repo 150 tag 151 ; 152 rev = fetchgit.getRevWithTag { 153 inherit (finalAttrs) tag; 154 rev = finalAttrs.revCustom; 155 }; 156 revCustom = rev; 157 }; 158 159 passthru = { 160 gitRepoUrl = baseUrl; 161 } 162 // passthru; 163 } 164 ) 165 // { 166 name = 167 args.name or (repoRevToNameMaybe finalAttrs.repo (lib.revOrTag finalAttrs.revCustom finalAttrs.tag) 168 "tangled" 169 ); 170 meta = newMeta; 171 }; 172 in 173 174 fetcher fetcherArgs 175)