fetchFromGitHub: Allow private repos, hosted githubs

+34 -5
+15 -1
pkgs/build-support/fetchurl/default.nix
··· 59 60 , recursiveHash ? false 61 62 , # Shell code executed after the file has been fetched 63 # successfully. This can do things like check or transform the file. 64 postFetch ? "" ··· 118 119 outputHashMode = if (recursiveHash || executable) then "recursive" else "flat"; 120 121 - inherit curlOpts showURLs mirrorsFile impureEnvVars postFetch downloadToTemp executable; 122 123 # Doing the download on a remote machine just duplicates network 124 # traffic, so don't do that. 125 preferLocalBuild = true; 126 127 inherit meta; 128 }
··· 59 60 , recursiveHash ? false 61 62 + , # Shell code to build a netrc file for BASIC auth 63 + netrcPhase ? null 64 + 65 + , # Impure env vars (http://nixos.org/nix/manual/#sec-advanced-attributes) 66 + # needed for netrcPhase 67 + netrcImpureEnvVars ? [] 68 + 69 , # Shell code executed after the file has been fetched 70 # successfully. This can do things like check or transform the file. 71 postFetch ? "" ··· 125 126 outputHashMode = if (recursiveHash || executable) then "recursive" else "flat"; 127 128 + inherit curlOpts showURLs mirrorsFile postFetch downloadToTemp executable; 129 + 130 + impureEnvVars = impureEnvVars ++ netrcImpureEnvVars; 131 132 # Doing the download on a remote machine just duplicates network 133 # traffic, so don't do that. 134 preferLocalBuild = true; 135 + 136 + postHook = if netrcPhase == null then null else '' 137 + ${netrcPhase} 138 + curlOpts="$curlOpts --netrc-file $PWD/netrc" 139 + ''; 140 141 inherit meta; 142 }
+19 -4
pkgs/top-level/all-packages.nix
··· 185 186 fetchFromGitHub = { 187 owner, repo, rev, name ? "${repo}-${rev}-src", 188 - fetchSubmodules ? false, 189 ... # For hash agility 190 - }@args: 191 let 192 - baseUrl = "https://github.com/${owner}/${repo}"; 193 - passthruAttrs = removeAttrs args [ "owner" "repo" "rev" "fetchSubmodules" ]; 194 in if fetchSubmodules then 195 fetchgit ({ 196 inherit name rev fetchSubmodules; ··· 203 inherit name; 204 url = "${baseUrl}/archive/${rev}.tar.gz"; 205 meta.homepage = "${baseUrl}/"; 206 } // passthruAttrs) // { inherit rev; }; 207 208 fetchFromBitbucket = {
··· 185 186 fetchFromGitHub = { 187 owner, repo, rev, name ? "${repo}-${rev}-src", 188 + fetchSubmodules ? false, private ? false, 189 + githubBase ? "github.com", varPrefix ? null, 190 ... # For hash agility 191 + }@args: assert private -> !fetchSubmodules; 192 let 193 + baseUrl = "https://${githubBase}/${owner}/${repo}"; 194 + passthruAttrs = removeAttrs args [ "owner" "repo" "rev" "fetchSubmodules" "private" "githubBase" "varPrefix" ]; 195 + varBase = "NIX${if varPrefix == null then "" else "_${varPrefix}"}_GITHUB_PRIVATE_"; 196 in if fetchSubmodules then 197 fetchgit ({ 198 inherit name rev fetchSubmodules; ··· 205 inherit name; 206 url = "${baseUrl}/archive/${rev}.tar.gz"; 207 meta.homepage = "${baseUrl}/"; 208 + } // lib.optionalAttrs private { 209 + netrcPhase = '' 210 + if [ -z "''$${varBase}USERNAME" -o -z "''$${varBase}PASSWORD" ]; then 211 + 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 212 + exit 1 213 + fi 214 + cat > netrc <<EOF 215 + machine ${githubBase} 216 + login ''$${varBase}USERNAME 217 + password ''$${varBase}PASSWORD 218 + EOF 219 + ''; 220 + netrcImpureEnvVars = [ "${varBase}USERNAME" "${varBase}PASSWORD" ]; 221 } // passthruAttrs) // { inherit rev; }; 222 223 fetchFromBitbucket = {