Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ lib, fetchgit, fetchzip }: 2 3lib.makeOverridable ( 4{ owner, repo, rev, name ? "source" 5, fetchSubmodules ? false, leaveDotGit ? null 6, deepClone ? false, private ? false, forceFetchGit ? false 7, sparseCheckout ? [] 8, githubBase ? "github.com", varPrefix ? null 9, meta ? { } 10, ... # For hash agility 11}@args: 12 13let 14 15 position = (if args.meta.description or null != null 16 then builtins.unsafeGetAttrPos "description" args.meta 17 else builtins.unsafeGetAttrPos "rev" args 18 ); 19 baseUrl = "https://${githubBase}/${owner}/${repo}"; 20 newMeta = meta // { 21 homepage = meta.homepage or baseUrl; 22 23 # to indicate where derivation originates, similar to make-derivation.nix's mkDerivation 24 position = "${position.file}:${toString position.line}"; 25 }; 26 passthruAttrs = removeAttrs args [ "owner" "repo" "rev" "fetchSubmodules" "forceFetchGit" "private" "githubBase" "varPrefix" ]; 27 varBase = "NIX${if varPrefix == null then "" else "_${varPrefix}"}_GITHUB_PRIVATE_"; 28 useFetchGit = fetchSubmodules || (leaveDotGit == true) || deepClone || forceFetchGit || !(sparseCheckout == "" || sparseCheckout == []); 29 # We prefer fetchzip in cases we don't need submodules as the hash 30 # is more stable in that case. 31 fetcher = if useFetchGit then fetchgit else fetchzip; 32 privateAttrs = lib.optionalAttrs private { 33 netrcPhase = '' 34 if [ -z "''$${varBase}USERNAME" -o -z "''$${varBase}PASSWORD" ]; then 35 echo "Error: Private fetchFromGitHub requires the nix building process (nix-daemon in multi user mode) to have the ${varBase}USERNAME and ${varBase}PASSWORD env vars set." >&2 36 exit 1 37 fi 38 cat > netrc <<EOF 39 machine ${githubBase} 40 login ''$${varBase}USERNAME 41 password ''$${varBase}PASSWORD 42 EOF 43 ''; 44 netrcImpureEnvVars = [ "${varBase}USERNAME" "${varBase}PASSWORD" ]; 45 }; 46 47 gitRepoUrl = "${baseUrl}.git"; 48 49 fetcherArgs = (if useFetchGit 50 then { 51 inherit rev deepClone fetchSubmodules sparseCheckout; url = gitRepoUrl; 52 } // lib.optionalAttrs (leaveDotGit != null) { inherit leaveDotGit; } 53 else { 54 url = "${baseUrl}/archive/${rev}.tar.gz"; 55 56 passthru = { 57 inherit gitRepoUrl; 58 }; 59 } 60 ) // privateAttrs // passthruAttrs // { inherit name; }; 61in 62 63fetcher fetcherArgs // { meta = newMeta; inherit rev owner repo; } 64)