Skip to content

Avoid use of parseIndexState #1903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
This file contains a summary of changes to Haskell.nix and `nix-tools`
that will impact users.

## Mar 27, 2023

Haskell.nix will no longer parse the `cabal.project` file to
determine the `index-state`. This decision was made due to
the function's inability to handle more than one `index-state`
or a qualified `index-state` as the first `index-state`
field in the file.

As a result, there will be some drawbacks:

* There will no longer be a warning in the trace output
if an index state is not found.

* Even if the `index-state:` in the `cabal.project` has not changed,
the plan will be recomputed when hackage.nix is bumped. However, this
is not expected to be a problem since plan recomputations are typically
quick.

* `project.index-state` cannot be used to obtain the found `index-state`.
However, the parse function is still available if required
(haskell-nix.haskellLib.parseIndexState).

## Jul 27, 2022
* Removed reliance on `builtins.currentSystem`. It was used it to provide
`pkgs.evalPackages` via an overlay that it used to run derivations
Expand Down
44 changes: 10 additions & 34 deletions lib/call-cabal-project-to-nix.nix
Original file line number Diff line number Diff line change
Expand Up @@ -151,46 +151,29 @@ in let
}
'';

cabalProjectIndexState = pkgs.haskell-nix.haskellLib.parseIndexState rawCabalProject;

index-state-found =
index-state-max =
if index-state != null
then index-state
else if cabalProjectIndexState != null
then cabalProjectIndexState
else
let latest-index-state = pkgs.lib.last (builtins.attrNames index-state-hashes);
in builtins.trace ("No index state specified" + (if name == null then "" else " for " + name) + ", using the latest index state that we know about (${latest-index-state})!") latest-index-state;

index-state-pinned = index-state != null || cabalProjectIndexState != null;
else pkgs.lib.last (builtins.attrNames index-state-hashes);

pkgconfPkgs = import ./pkgconf-nixpkgs-map.nix pkgs;

in
assert (if index-state-found == null
then throw "No index state passed and none found in ${cabalProjectFileName}" else true);

assert (if index-sha256 == null && !(pkgs.lib.hasSuffix "Z" index-state-found)
then throw "Index state found was ${index-state-found} and no `index-sha256` was provided. "
"The index hash lookup code requires zulu time zone (ends in a Z)" else true);

let
# If a hash was not specified find a suitable cached index state to
# use that will contain all the packages we need. By using the
# first one after the desired index-state we can avoid recalculating
# when new index-state-hashes are added.
# See https://github.com/input-output-hk/haskell.nix/issues/672
cached-index-state = if index-sha256 != null
then index-state-found
then index-state-max
else
let
suitable-index-states =
builtins.filter
(s: s >= index-state-found) # This compare is why we need zulu time
(s: s >= index-state-max) # This compare is why we need zulu time
(builtins.attrNames index-state-hashes);
in
if builtins.length suitable-index-states == 0
then index-state-found
then index-state-max
else pkgs.lib.head suitable-index-states;

# Lookup hash for the index state we found
Expand All @@ -200,7 +183,7 @@ let

in
assert (if index-sha256-found == null
then throw "Unknown index-state ${index-state-found}, the latest index-state I know about is ${pkgs.lib.last (builtins.attrNames index-state-hashes)}. You may need to update to a newer hackage.nix." else true);
then throw "Unknown index-state ${index-state-max}, the latest index-state I know about is ${pkgs.lib.last (builtins.attrNames index-state-hashes)}. You may need to update to a newer hackage.nix." else true);

let
# Deal with source-repository-packages in a way that will work in
Expand Down Expand Up @@ -392,11 +375,6 @@ let
sha256 = plan-sha256;
sha256Arg = "plan-sha256";
this = "project.plan-nix" + (if name != null then " for ${name}" else "");
# Before pinning stuff down we need an index state to use
reasonNotSafe =
if !index-state-pinned
then "index-state is not pinned by an argument or the cabal project file"
else null;
} // pkgs.lib.optionalAttrs (checkMaterialization != null) {
inherit checkMaterialization;
}) (evalPackages.runCommand (nameAndSuffix "plan-to-nix-pkgs") {
Expand Down Expand Up @@ -470,12 +448,11 @@ let
export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt
export GIT_SSL_CAINFO=${cacert}/etc/ssl/certs/ca-bundle.crt

echo "Using index-state ${index-state-found}"
CABAL_DIR=${
# This creates `.cabal` directory that is as it would have
# been at the time `cached-index-state`. We may include
# some packages that will be excluded by `index-state-found`
# which is used by cabal (cached-index-state >= index-state-found).
# some packages that will be excluded by `index-state-max`
# which is used by cabal (cached-index-state >= index-state-max).
dotCabal {
inherit cabal-install nix-tools extra-hackage-tarballs;
extra-hackage-repos = fixedProject.repos;
Expand All @@ -485,7 +462,7 @@ let
} make-install-plan ${
# Setting the desired `index-state` here in case it is not
# in the cabal.project file. This will further restrict the
# packages used by the solver (cached-index-state >= index-state-found).
# packages used by the solver (cached-index-state >= index-state-max).
pkgs.lib.optionalString (index-state != null) "--index-state=${index-state}"
} \
-w ${
Expand Down Expand Up @@ -548,7 +525,6 @@ let
'');
in {
projectNix = plan-nix;
index-state = index-state-found;
inherit src;
inherit index-state-max src;
inherit (fixedProject) sourceRepos extra-hackages;
}