Skip to content

Commit efad04e

Browse files
authored
Fix index-sha256 bit rot (#2390)
* Fix `index-sha256` bit rot If an new package is deployed to `hackage.haskell.org`, to use it before it is captured by the `hackage.nix` update add the following to the project arguments: ```nix index-state="2025-06-16T00:00:00Z"; # Use current time here # This hash in not valid, the error message will give the correct hash index-sha256="sha256-NS28jJYko/tNUKVhncntu/mV8tsQmTA52T000000000="; ``` This change PR fixes some "bit rot" issues: * A warning about `--index-state` argument being out of range is now an error. * The sha256 might now be in base16 or base32. * Add comment * Doc change to trigger hydra CI * Fix cross compilation shells * Use hackage.nix/index-state.nix * Support for older hackage.nix versions
1 parent bd2866b commit efad04e

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

docs/reference/library.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,8 @@ needed for `importAndFilterProject`.
273273
|----------------------|------|---------------------|
274274
| `name` | String | Optional name for better error messages. |
275275
| `src` | Path | Location of the cabal project files. |
276-
| `compiler-nix-name` | String | The name of the ghc compiler to use eg. "ghc884" |
277-
| `index-state` | Timestamp | Optional hackage index-state, eg. "2019-10-10T00:00:00Z". |
276+
| `compiler-nix-name` | String | The name of the ghc compiler to use eg. "ghc9122" |
277+
| `index-state` | Timestamp | Optional hackage index-state, eg. "2025-01-10T00:00:00Z". |
278278
| `index-sha256` | Sha256 | Optional hash of the truncated hackage index-state. |
279279
| `plan-sha256` | Sha256 | Optional hash of the plan-to-nix output (makes the plan-to-nix step a fixed output derivation). |
280280
| `cabalProject` | String | Optional cabal project file contents (defaults to readFile "${src}/cabal.project"). |

lib/call-cabal-project-to-nix.nix

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,9 @@ let
678678
# Setting the desired `index-state` here in case it is not
679679
# in the cabal.project file. This will further restrict the
680680
# packages used by the solver (cached-index-state >= index-state-max).
681-
pkgs.lib.optionalString (index-state != null) "--index-state=${index-state}"
681+
# Cabal treats `--index-state` > the last known package as an error,
682+
# so we only include this if it is < cached-index-state.
683+
pkgs.lib.optionalString (index-state != null && index-state < cached-index-state) "--index-state=${index-state}"
682684
} \
683685
-w ${
684686
# We are using `-w` rather than `--with-ghc` here to override

mk-local-hackage-repo/default.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
pkgs:
1818
{ name, index }:
1919

20-
pkgs.buildPackages.runCommand "hackage-repo-${name}" { preferLocalBuild = true; } ''
20+
pkgs.pkgsBuildBuild.runCommand "hackage-repo-${name}" { preferLocalBuild = true; } ''
2121
mkdir -p $out
2222
export expires="4000-01-01T00:00:00Z"
2323
@@ -29,7 +29,7 @@ ${
2929
# of the index derivation (when the `extra-hackages` feature is used the index
3030
# may not have an outputHash).
3131
pkgs.lib.optionalString (index ? outputHash) ''
32-
if [[ "${index.outputHash}" != "$index_sha256" ]]; then
32+
if [[ "$(${pkgs.pkgsBuildBuild.nix}/bin/nix-hash --type sha256 --to-base16 ${index.outputHash})" != "$index_sha256" ]]; then
3333
echo "ERROR See https://github.com/input-output-hk/haskell.nix/issues/884"
3434
exit 1
3535
fi

0 commit comments

Comments
 (0)