nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
fork

Configure Feed

Select the types of activity you want to include in your feed.

at 23.05 111 lines 3.9 kB view raw
1{lib, stdenvNoCC, git, git-lfs, cacert}: let 2 urlToName = url: rev: let 3 inherit (lib) removeSuffix splitString last; 4 base = last (splitString ":" (baseNameOf (removeSuffix "/" url))); 5 6 matched = builtins.match "(.*)\\.git" base; 7 8 short = builtins.substring 0 7 rev; 9 10 appendShort = lib.optionalString ((builtins.match "[a-f0-9]*" rev) != null) "-${short}"; 11 in "${if matched == null then base else builtins.head matched}${appendShort}"; 12in 13lib.makeOverridable ( 14{ url, rev ? "HEAD", md5 ? "", sha256 ? "", hash ? "", leaveDotGit ? deepClone 15, fetchSubmodules ? true, deepClone ? false 16, branchName ? null 17, sparseCheckout ? [] 18, nonConeMode ? false 19, name ? urlToName url rev 20, # Shell code executed after the file has been fetched 21 # successfully. This can do things like check or transform the file. 22 postFetch ? "" 23, preferLocalBuild ? true 24, fetchLFS ? false 25, # Shell code to build a netrc file for BASIC auth 26 netrcPhase ? null 27, # Impure env vars (https://nixos.org/nix/manual/#sec-advanced-attributes) 28 # needed for netrcPhase 29 netrcImpureEnvVars ? [] 30, meta ? {} 31, allowedRequisites ? null 32}: 33 34/* NOTE: 35 fetchgit has one problem: git fetch only works for refs. 36 This is because fetching arbitrary (maybe dangling) commits creates garbage collection risks 37 and checking whether a commit belongs to a ref is expensive. This may 38 change in the future when some caching is added to git (?) 39 Usually refs are either tags (refs/tags/*) or branches (refs/heads/*) 40 Cloning branches will make the hash check fail when there is an update. 41 But not all patches we want can be accessed by tags. 42 43 The workaround is getting the last n commits so that it's likely that they 44 still contain the hash we want. 45 46 for now : increase depth iteratively (TODO) 47 48 real fix: ask git folks to add a 49 git fetch $HASH contained in $BRANCH 50 facility because checking that $HASH is contained in $BRANCH is less 51 expensive than fetching --depth $N. 52 Even if git folks implemented this feature soon it may take years until 53 server admins start using the new version? 54*/ 55 56assert deepClone -> leaveDotGit; 57assert nonConeMode -> !(sparseCheckout == "" || sparseCheckout == []); 58 59if md5 != "" then 60 throw "fetchgit does not support md5 anymore, please use sha256" 61else if hash != "" && sha256 != "" then 62 throw "Only one of sha256 or hash can be set" 63else 64# Added 2022-11-12 65lib.warnIf (builtins.isString sparseCheckout) 66 "Please provide directories/patterns for sparse checkout as a list of strings. Support for passing a (multi-line) string is deprecated and will be removed in the next release." 67stdenvNoCC.mkDerivation { 68 inherit name; 69 builder = ./builder.sh; 70 fetcher = ./nix-prefetch-git; 71 72 nativeBuildInputs = [ git ] 73 ++ lib.optionals fetchLFS [ git-lfs ]; 74 75 outputHashAlgo = if hash != "" then null else "sha256"; 76 outputHashMode = "recursive"; 77 outputHash = if hash != "" then 78 hash 79 else if sha256 != "" then 80 sha256 81 else 82 lib.fakeSha256; 83 84 # git-sparse-checkout(1) says: 85 # > When the --stdin option is provided, the directories or patterns are read 86 # > from standard in as a newline-delimited list instead of from the arguments. 87 sparseCheckout = if builtins.isString sparseCheckout then sparseCheckout else builtins.concatStringsSep "\n" sparseCheckout; 88 89 inherit url rev leaveDotGit fetchLFS fetchSubmodules deepClone branchName nonConeMode postFetch; 90 91 postHook = if netrcPhase == null then null else '' 92 ${netrcPhase} 93 # required that git uses the netrc file 94 mv {,.}netrc 95 export HOME=$PWD 96 ''; 97 98 GIT_SSL_CAINFO = "${cacert}/etc/ssl/certs/ca-bundle.crt"; 99 100 impureEnvVars = lib.fetchers.proxyImpureEnvVars ++ netrcImpureEnvVars ++ [ 101 "GIT_PROXY_COMMAND" "NIX_GIT_SSL_CAINFO" "SOCKS_SERVER" 102 ]; 103 104 105 inherit preferLocalBuild meta allowedRequisites; 106 107 passthru = { 108 gitRepoUrl = url; 109 }; 110} 111)