at master 212 lines 7.0 kB view raw
1{ 2 runCommand, 3 testers, 4 fetchgit, 5 nix-prefetch-git, 6 jq, 7 cacert, 8 nix, 9 closureInfo, 10 ... 11}: 12{ 13 simple = testers.invalidateFetcherByDrvHash fetchgit { 14 name = "simple-nix-source"; 15 url = "https://github.com/NixOS/nix"; 16 rev = "9d9dbe6ed05854e03811c361a3380e09183f4f4a"; 17 sha256 = "sha256-7DszvbCNTjpzGRmpIVAWXk20P0/XTrWZ79KSOGLrUWY="; 18 }; 19 20 sparseCheckout = testers.invalidateFetcherByDrvHash fetchgit { 21 name = "sparse-checkout-nix-source"; 22 url = "https://github.com/NixOS/nix"; 23 rev = "9d9dbe6ed05854e03811c361a3380e09183f4f4a"; 24 sparseCheckout = [ 25 "src" 26 "tests" 27 ]; 28 sha256 = "sha256-g1PHGTWgAcd/+sXHo1o6AjVWCvC6HiocOfMbMh873LQ="; 29 }; 30 31 sparseCheckoutNonConeMode = testers.invalidateFetcherByDrvHash fetchgit { 32 name = "sparse-checkout-non-cone-nix-source"; 33 url = "https://github.com/NixOS/nix"; 34 rev = "9d9dbe6ed05854e03811c361a3380e09183f4f4a"; 35 sparseCheckout = [ 36 "src" 37 "tests" 38 ]; 39 nonConeMode = true; 40 sha256 = "sha256-FknO6C/PSnMPfhUqObD4vsW4PhkwdmPa9blNzcNvJQ4="; 41 }; 42 43 leave-git = testers.invalidateFetcherByDrvHash fetchgit { 44 name = "leave-git-nix-source"; 45 url = "https://github.com/NixOS/nix"; 46 rev = "9d9dbe6ed05854e03811c361a3380e09183f4f4a"; 47 sha256 = "sha256-VmQ38+lr+rNPaTnjjV41uC2XSN4fkfZAfytE2uKyLfo="; 48 leaveDotGit = true; 49 }; 50 51 submodule-simple = testers.invalidateFetcherByDrvHash fetchgit { 52 name = "submodule-simple-source"; 53 url = "https://github.com/pineapplehunter/nix-test-repo-with-submodule"; 54 rev = "26473335b84ead88ee0a3b649b1c7fa4a91cfd4a"; 55 sha256 = "sha256-rmP8PQT0wJBopdtr/hsB7Y/L1G+ZPdHC2r9LB05Qrj4="; 56 fetchSubmodules = true; 57 }; 58 59 submodule-leave-git = testers.invalidateFetcherByDrvHash fetchgit { 60 name = "submodule-leave-git-source"; 61 url = "https://github.com/pineapplehunter/nix-test-repo-with-submodule"; 62 rev = "26473335b84ead88ee0a3b649b1c7fa4a91cfd4a"; 63 sha256 = "sha256-EC2PMEEtA7f5OFdsluHn7pi4QXhCZuFML8tib4pV7Ek="; 64 leaveDotGit = true; 65 fetchSubmodules = true; 66 }; 67 68 submodule-deep = testers.invalidateFetcherByDrvHash fetchgit { 69 name = "submodule-deep-source"; 70 url = "https://github.com/pineapplehunter/nix-test-repo-with-submodule"; 71 rev = "26473335b84ead88ee0a3b649b1c7fa4a91cfd4a"; 72 sha256 = "sha256-3zWogs6EZBnzUfz6gBnigETTKGYl9KFKFgsy6Bl4DME="; 73 deepClone = true; 74 fetchSubmodules = true; 75 # deepClone implies leaveDotGit, so delete the .git directory after 76 # fetching to distinguish from the submodule-leave-git-deep test. 77 postFetch = "rm -r $out/.git"; 78 }; 79 80 submodule-leave-git-deep = testers.invalidateFetcherByDrvHash fetchgit { 81 name = "submodule-leave-git-deep-source"; 82 url = "https://github.com/pineapplehunter/nix-test-repo-with-submodule"; 83 rev = "26473335b84ead88ee0a3b649b1c7fa4a91cfd4a"; 84 sha256 = "sha256-ieYn9I/0RgeSwQkSqwKaU3RgjKFlRqMg7zw0Nvu3azA="; 85 deepClone = true; 86 leaveDotGit = true; 87 fetchSubmodules = true; 88 }; 89 90 dumb-http-signed-tag = testers.invalidateFetcherByDrvHash fetchgit { 91 name = "dumb-http-signed-tag-source"; 92 url = "https://git.scottworley.com/pub/git/pinch"; 93 rev = "v3.0.14"; 94 sha256 = "sha256-bd0Lx75Gd1pcBJtwz5WGki7XoYSpqhinCT3a77wpY2c="; 95 }; 96 97 fetchTags = testers.invalidateFetcherByDrvHash fetchgit { 98 name = "fetchgit-fetch-tags-test"; 99 url = "https://github.com/NixOS/nix"; 100 rev = "9d9dbe6ed05854e03811c361a3380e09183f4f4a"; 101 fetchTags = true; 102 leaveDotGit = true; 103 sha256 = "sha256-y7l+46lVP2pzJwGON5qEV0EoxWofRoWAym5q9VXvpc8="; 104 postFetch = '' 105 cd $out && git describe --tags --always > describe-output.txt 2>&1 || echo "git describe failed" > describe-output.txt 106 # See https://github.com/NixOS/nixpkgs/issues/412967#issuecomment-2927452118 107 rm -rf .git 108 ''; 109 }; 110 111 rootDir = testers.invalidateFetcherByDrvHash fetchgit { 112 name = "fetchgit-with-rootdir"; 113 url = "https://github.com/NixOS/nix"; 114 rev = "9d9dbe6ed05854e03811c361a3380e09183f4f4a"; 115 rootDir = "misc/systemd"; 116 sha256 = "sha256-UhxHk4SrXYq7ZDMtXLig5SigpbITrVgkpFTmryuvpcM="; 117 }; 118 119 # Make sure that if an expected hash is given and the corresponding store path exists already, no fetch is done 120 cached-prefetch-avoids-fetch = 121 let 122 name = "cached-prefetch-avoids-fetch"; 123 url = "https://github.com/NixOS/nix"; 124 rev = "9d9dbe6ed05854e03811c361a3380e09183f4f4a"; 125 sha256 = "sha256-7DszvbCNTjpzGRmpIVAWXk20P0/XTrWZ79KSOGLrUWY="; 126 fetched = fetchgit { 127 inherit 128 name 129 url 130 rev 131 sha256 132 ; 133 }; 134 in 135 runCommand "cached-prefetch-avoids-fetch" 136 { 137 nativeBuildInputs = [ 138 nix-prefetch-git 139 nix 140 ]; 141 } 142 '' 143 export NIX_REMOTE=local?root=$(mktemp -d) 144 nix-store --load-db < ${closureInfo { rootPaths = fetched; }}/registration 145 nix-prefetch-git --name "${name}" "${url}" "${rev}" "${sha256}" > $out 146 ''; 147 148 prefetch-git-no-add-path = 149 testers.invalidateFetcherByDrvHash 150 ( 151 { 152 name, 153 url, 154 rev, 155 hash, 156 ... 157 }: 158 runCommand name 159 { 160 buildInputs = [ 161 nix-prefetch-git 162 nix 163 cacert 164 jq 165 ]; 166 outputHashMode = "recursive"; 167 outputHashAlgo = null; 168 outputHash = hash; 169 inherit url rev; 170 } 171 '' 172 store_root="$(mktemp -d)" 173 prefetch() { NIX_REMOTE="local?root=$store_root" nix-prefetch-git $@ "$url" --rev "$rev" | jq -r .path; } 174 path="$(prefetch --no-add-path)" 175 if test -e "$store_root/$path"; then 176 echo "$path exists in $NIX_REMOTE when it shouldn't" >&2 177 exit 1 178 fi 179 path_added="$(prefetch)" 180 if ! test -e "$store_root/$path"; then 181 echo "$path_added doesn't exist in NIX_REMOTE when it should" >&2 182 exit 1 183 fi 184 if test "$path" != "$path_added"; then 185 echo "Paths are different with and without --no-add-path: $path != $path_added" >&2 186 exit 1 187 fi 188 cp -r "$store_root/$path_added" "$out" 189 '' 190 ) 191 { 192 name = "nix-prefetch-git-no-add-path"; 193 url = "https://github.com/NixOS/nix"; 194 rev = "9d9dbe6ed05854e03811c361a3380e09183f4f4a"; 195 hash = "sha256-7DszvbCNTjpzGRmpIVAWXk20P0/XTrWZ79KSOGLrUWY="; 196 }; 197 198 withGitConfig = 199 let 200 pkgs = import ../../.. { 201 config.gitConfig = { 202 url."https://github.com".insteadOf = "https://doesntexist.forsure"; 203 }; 204 }; 205 in 206 pkgs.testers.invalidateFetcherByDrvHash pkgs.fetchgit { 207 name = "fetchgit-with-config"; 208 url = "https://doesntexist.forsure/NixOS/nix"; 209 rev = "9d9dbe6ed05854e03811c361a3380e09183f4f4a"; 210 sha256 = "sha256-7DszvbCNTjpzGRmpIVAWXk20P0/XTrWZ79KSOGLrUWY="; 211 }; 212}