on iko/ghcjs-patch-master help sign in
Run the nightly scripts to also update the index-state-hashes (#146)

* Run the nightly scripts to also update the index-state-hashes This moves the index-state-hashes to `hackage.nix` as well. Thus we need to have a least one hackage.nix update in. * fix import * Update update-index-state-hashes.nix Add comments.

commit03fd50f0b75e3e49e1d427197d08f1266d5c335d authorMoritz Angermann <moritz.angermann@gmail.com> dateSat 8 Jun 2019, 15:21 (7 years ago) parent2db7ade
5 files changed+57−72
default.nix+8−14 lib/cabalProjectToNix.nix+2−2 lib/index-state-hashes.nix−55 scripts/update-hackage.nix+5−1 scripts/update-index-state-hashes.nix+42
default.nix+8−14
@@ -50,6 +50,10 @@ let
5050 };
5151 hackage = import hackageSrc;
5252
53+ # Contains the hashes of the cabal 01-index.tar.gz for given
54+ # index states. Starting from April 1st 2019.
55+ indexStateHashesPath = hackageSrc + "/index-state-hashes.nix";
56+
5357 # The set of all Stackage snapshots
5458 stackageSrc = fetchExternal {
5559 name = "stackage-snapshot-source";
@@ -130,7 +134,9 @@ let
130134
131135 # Snapshots of Hackage and Stackage, converted to Nix expressions,
132136 # regularly updated.
137+ inherit hackageSrc stackageSrc;
133138 inherit hackage stackage;
139+ inherit indexStateHashesPath;
134140
135141 # Make this handy overridable fetch function available.
136142 inherit fetchExternal;
@@ -167,24 +173,12 @@ let
167173 HOME=$out cabal new-update cached
168174 '';
169175
170− generateHackageIndexStateHashes = pkgs.runCommand "index-state-hashes" {} ''
171− truncate=${self.nix-tools}/bin/truncate-index
172− start=${let ls = builtins.attrNames (import ./lib/index-state-hashes.nix); in builtins.elemAt ls (builtins.length ls - 1)}
173− cat ${./lib/index-state-hashes.nix} | head -n -1 >> $out
174− for d in $(seq -f '%.f' $(date -u +%s -d $start) 86400 $(date -u +%s)) ; do
175− dt=$(date -u +%Y-%m-%d -d @$d)
176− if [[ "''${dt}T00:00:00Z" != "$start" ]]; then
177− ''${truncate} -o ''${dt}-01-index.tar.gz -i ${builtins.fetchurl "https://hackage.haskell.org/01-index.tar.gz"} -s "''${dt}T00:00:00Z"
178− sha256=$(${pkgs.nix}/bin/nix-hash --flat --type sha256 ''${dt}-01-index.tar.gz)
179− echo " \"''${dt}T00:00:00Z\" = \"''${sha256}\";" >> $out
180− fi
181− done
182− echo '}' >> $out
183− '';
176+ update-index-state-hashes = self.callPackage ./scripts/update-index-state-hashes.nix {};
184177
185178 # Takes a haskell src directory runs cabal new-configure and plan-to-nix.
186179 # Resulting nix files are added to nix-plan subdirectory.
187180 callCabalProjectToNix = import ./lib/cabalProjectToNix.nix {
181+ index-state-hashes = import indexStateHashesPath;
188182 inherit (self) dotCabal;
189183 inherit pkgs;
190184 inherit (pkgs) runCommand cabal-install ghc symlinkJoin cacert;
lib/cabalProjectToNix.nix+2−2
@@ -1,7 +1,7 @@
1−{ dotCabal, pkgs, runCommand, nix-tools, cabal-install, ghc, hpack, symlinkJoin, cacert }:
1+{ dotCabal, pkgs, runCommand, nix-tools, cabal-install, ghc, hpack, symlinkJoin, cacert, index-state-hashes }:
22let defaultGhc = ghc;
33 defaultCabalInstall = cabal-install;
4−in { index-state, index-sha256 ? (import ./index-state-hashes.nix).${index-state} or null, src, ghc ? defaultGhc, cabal-install ? defaultCabalInstall }:
4+in { index-state, index-sha256 ? index-state-hashes.${index-state} or null, src, ghc ? defaultGhc, cabal-install ? defaultCabalInstall }:
55
66# better error message than just assert failed.
77assert (if index-sha256 == null then throw "provided sha256 for index-state ${index-state} is null!" else true);
lib/index-state-hashes.nixdeleted−55
@@ -1,55 +0,0 @@
1−{
2− "2019-04-01T00:00:00Z" = "c474efaba33ac2e6b737a2ac694a74e326884eacd01708eb1f42200854c7a8c9";
3− "2019-04-02T00:00:00Z" = "f720c323879e5b5f4d6fe23ff5aa6a93b9f0f828096096523b48d8c718d3893c";
4− "2019-04-03T00:00:00Z" = "eedd2c025b5a59037698d24dc2a035cc93f1f464a1d738bf0b9a70c20837b485";
5− "2019-04-04T00:00:00Z" = "78dd777f80a34c9ad01783bbae7fe648e564d838bed971126596d52aba8faee7";
6− "2019-04-05T00:00:00Z" = "3f892e7be48e2723910aa5b3f7ed8c5e7ca247275a3e03ccc3ce84eb5e239a90";
7− "2019-04-06T00:00:00Z" = "5698ef0c65688760b8a5fb97acd4f7e85f904f6d150fdf72b401c1b6c40846bd";
8− "2019-04-07T00:00:00Z" = "0800715fcdbbd83fba59f38e2b2f27d6a5ababd477bcfa89d13b27961522a6fe";
9− "2019-04-08T00:00:00Z" = "a7b73aa3891079ebcc42d8ce8d2e05624ff3ea3cec81f199731f4a88b5eaf17b";
10− "2019-04-09T00:00:00Z" = "75bffd47f7c6f3cb80b0808f0bda19dbc7f2e1dfdb0bc867259d4e0d0ffcc6fe";
11− "2019-04-10T00:00:00Z" = "35aae6a9fcb71b98a1e6a84511e40769cf6ed141a22778235770e5d1c7e46982";
12− "2019-04-11T00:00:00Z" = "094321bbafa5150b3e397b2fee0052e441e16c971357d182b12628e24475b03c";
13− "2019-04-12T00:00:00Z" = "29092b8546eea6f22e1169216bcefd3544d15f7f3f1549cb0d0f7a6717a2d2cb";
14− "2019-04-13T00:00:00Z" = "e7cd063aaeb24d0a4604db4a7f827259852a9fe4f1bc67f3c171a8fbcb5b8707";
15− "2019-04-14T00:00:00Z" = "e1db5ce15198d5c98473d32dd74d9532fb064a042d71cb078d0c4f97daa05351";
16− "2019-04-15T00:00:00Z" = "7df0a5d157b6e730c68f614644ae7863de32d19260730683ad685cc24691ed93";
17− "2019-04-16T00:00:00Z" = "76763ec23fd99e41a42d6a6c06afebc34c8319ba7bb03433cc7db868cab31d8b";
18− "2019-04-17T00:00:00Z" = "96232013324793960158bf7512fc0cc4855afbefdcc98e510bcbaae99ec11feb";
19− "2019-04-18T00:00:00Z" = "605c20dc88f98e0821ad8913f198e690a6a9ff4128d13cc91cfb695ee5d25b3f";
20− "2019-04-19T00:00:00Z" = "a5bad701ce83d51a0d4de910d6502ae835bdffd947bbbbbac8adf9cfd3e1e9ce";
21− "2019-04-20T00:00:00Z" = "5727553a452213ed41bde3eb651b78998dfd1fa5a19fedaecf3c28462e8bb175";
22− "2019-04-21T00:00:00Z" = "81dbfcfa7f33beee9f6e2d57f07b7757e1390d2d389c4763e8e7b3f767ec7b60";
23− "2019-04-22T00:00:00Z" = "9c0051b3d1023e7118087f0c8914fbf8dcae1e62545cae47c82c12a37012a00a";
24− "2019-04-23T00:00:00Z" = "52232c52172f61113a839ac3511051cfb13ba91089fe458360fde193d00e86ca";
25− "2019-04-24T00:00:00Z" = "f8c9eb039f16c95c825109469937c1a8ef270f56f0d376ca1cd19f6b61ba8ab4";
26− "2019-04-25T00:00:00Z" = "b67e1a5e9a88beb2c741e47349cbc74fec01f2cb3279f982161e3f63e51a4576";
27− "2019-04-26T00:00:00Z" = "4de880d417d118fe296121b2f3ac3bb2d4b08d56ed5490f30b81ae0ac2388016";
28− "2019-04-27T00:00:00Z" = "20dd0ba939636081482b9bbc6fac0bcb2b1f5710ad70713945e7af2e9ee1b510";
29− "2019-04-28T00:00:00Z" = "33df24a7827a6504944a6546fb32c22bee1af05e8d441f30d0a7abe6487eb65f";
30− "2019-04-29T00:00:00Z" = "50fe3ffa024e0a131ac9440b3fec099ca83d298163f71731b25bbdb84b7681ac";
31− "2019-04-30T00:00:00Z" = "f0dedbd5e75d581fc163d94ddba92a62f785a90183ccfaa426131de6218ad7cb";
32− "2019-05-01T00:00:00Z" = "6ee044506ff9befb4709526f15e2858fce30a0c40b27ca1e518f9466f0f81c5e";
33− "2019-05-02T00:00:00Z" = "0077eb4cdd1a9649dad8196dfd2d8f9db9183b66f0049e0f7c4fd843f43a4664";
34− "2019-05-03T00:00:00Z" = "c1a0e3c1c3854911ffa5e49d9e1aa6b43235cbc5ec272ff5be675c8f8d231b4a";
35− "2019-05-04T00:00:00Z" = "7c2e4bec642de2e6b5afd3aa57ee53323f6b1bec36d9af78a432199034abe254";
36− "2019-05-05T00:00:00Z" = "b4ff7a89b7f93c88597119656cf938fdf2b72454991fd8b683b5f7a5bdba0fd4";
37− "2019-05-06T00:00:00Z" = "822220587de7ee36d633e9bc72df760064237b13c286d0c52efdc5d5048297de";
38− "2019-05-07T00:00:00Z" = "2927619e7b636780296f06d3f816c159d121b507bb2c81c7abda40926d76df12";
39− "2019-05-08T00:00:00Z" = "05e3bed075a0a9095a7ddfee1a096e56bea41948eeec1a7d3a673980a257d4a3";
40− "2019-05-09T00:00:00Z" = "501bddbc5cdac16f85724066df5be4e2f40e327b5f5fe0999e70c2901ce2d89a";
41− "2019-05-10T00:00:00Z" = "4e6e357aa2f820ca3883dee8f2af7e359f640e1639036408d6e2b8af9751a028";
42− "2019-05-11T00:00:00Z" = "8203d571863706fb4fa5ec121b689d8601135a63ca12456c86554029270b9ad0";
43− "2019-05-12T00:00:00Z" = "99fb942cabcda72770adec289d4f138a985e76fb2e36dea39f54734ef74c5bb5";
44− "2019-05-13T00:00:00Z" = "fef0a5e9170ac226ed47a483057f7e3f84ae374102431e5f46165140c516aa1f";
45− "2019-05-14T00:00:00Z" = "2c08a3a145485279f396521374ebe1efd2022497809ae957259fea2bdb5cf829";
46− "2019-05-15T00:00:00Z" = "864143953a41b64d5263ce67ec476396adafc92e77f77748916cefa76b9dd849";
47− "2019-05-16T00:00:00Z" = "d5bb19b8019b617794dcb2a4cff72ebfb8edb96b232f040c486dd570e1785528";
48− "2019-05-17T00:00:00Z" = "4c06e58c1698f650eb28ed545f9d243a564b30a4c0e3097df62e18dfffe9c72b";
49− "2019-05-18T00:00:00Z" = "a3fd7461d73c2c393e9ed37c029b4b92482b9aa9df7790c826cb0a0408fb4522";
50− "2019-05-19T00:00:00Z" = "84b578c748049bcba2b5ab35fea77d1278662b4fb003ee1c903aa88c167c19ab";
51− "2019-05-20T00:00:00Z" = "87e8c61faf75005929650fde538d3a63d0db9e28ea3a40db79dc4f3ab9a5347f";
52− "2019-05-21T00:00:00Z" = "27f4ad652a0880a26d8f8242611f6112296f078b45868f704cf628f9b6610d00";
53− "2019-05-22T00:00:00Z" = "f6c2c8a3b3c44a893138042eb7ff8470511156ea2fabafc633eb7cb4b53af236";
54− "2019-05-23T00:00:00Z" = "9587cd6b2a317e608e8b34bafc13e0ef9d22b5332f21cc5544cea0d765223cba";
55−}
scripts/update-hackage.nix+5−1
@@ -1,4 +1,4 @@
1−{ stdenv, writeScript, coreutils, glibc, git, openssh, nix-tools, cabal-install, nix-prefetch-git }@args:
1+{ stdenv, writeScript, coreutils, glibc, git, openssh, nix-tools, cabal-install, nix-prefetch-git, update-index-state-hashes }@args:
22
33import ./update-external.nix args {
44 name = "hackage";
@@ -20,6 +20,10 @@ import ./update-external.nix args {
2020
2121 hackage-to-nix hackage.nix
2222
23+ echo "Running update-index-state-hashes..."
24+
25+ ${update-index-state-hashes}/bin/update-index-state-hashes > ./index-state-hashes.nix
26+
2327 cd hackage.nix
2428 '';
2529}
scripts/update-index-state-hashes.nixnew file+42
@@ -0,0 +1,42 @@
1+{ indexStateHashesPath, nix-tools, coreutils, nix, writeShellScriptBin, stdenv }:
2+with builtins;
3+with stdenv.lib;
4+writeShellScriptBin "update-index-state-hashes" ''
5+ # get all the tools we need. I wonder if there is a better way? But I couldn't find
6+ # any buildInputs for writeShellScriptBin :-/
7+ export PATH="${getBin coreutils}/bin:${getBin nix-tools}/bin:${getBin nix}/bin:$PATH"
8+
9+ # We'll take the last element from the indexStatesHashes file via nix and get the name.
10+ # This is the last timestamp recorded in the file (implicit assumption: the file is
11+ # ordered, and nix preserved that order when parsing it into a attributeset).
12+ start=${let ls = attrNames (import indexStateHashesPath); in elemAt ls (length ls - 1)}
13+
14+ # The indexStatesHashesPath looks like
15+ # {
16+ # ...
17+ # }
18+ # Idea: take everything but drop the last line, and can then just append each new
19+ # entry and finally close the file with "}". We'll do this by echoing to STDOUT!
20+
21+ # Old file without the closing curly brace.
22+ cat ${indexStateHashesPath} | head -n -1
23+
24+ # Parse the $start date, and now into seconds with the date command. Then walk
25+ # them by 86400 (24*60*60) days. We need to format the output with '%.f' as we
26+ # don't want fractional values.
27+ for d in $(seq -f '%.f' $(date -u +%s -d $start) 86400 $(date -u +%s)) ; do
28+ # turn the step date $d into a YYYY-MM-DD string, and generate the truncated
29+ # index, compute it's hash and echo "$dT00:00:00Z" = "$sha256"; to STDOUT.
30+ dt=$(date -u +%Y-%m-%d -d @$d)
31+
32+ # ensure we don't generate the $start date twice (skip the first invocation).
33+ if [[ "''${dt}T00:00:00Z" != "$start" ]]; then
34+ truncate-index -o ''${dt}-01-index.tar.gz -i ${fetchurl "https://hackage.haskell.org/01-index.tar.gz"} -s "''${dt}T00:00:00Z"
35+ sha256=$(nix-hash --flat --type sha256 ''${dt}-01-index.tar.gz)
36+ echo " \"''${dt}T00:00:00Z\" = \"''${sha256}\";"
37+ fi
38+ done
39+
40+ # emit the finall closing brace.
41+ echo '}'
42+ ''