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