Skip to content

Commit 9f75bfd

Browse files
authored
Avoid use of parseIndexState (#1903)
* Avoid use of `parseIndexState` The `parseIndexState` uses a very simple parser that breaks for `cabal.project` files with more complicated `index-state:` fields. This will have some drawbacks: * There will no longer be a warning in the trace output if an index state was not found. * When `hackage.nix` is bumped the plan will be recomputed even if the `index-state:` in the `cabal.project` has not changed. We do not expect this to be a problem since recomputing the plan is normally relatively fast. * Update change log
1 parent 1dcbcc7 commit 9f75bfd

File tree

2 files changed

+32
-34
lines changed

2 files changed

+32
-34
lines changed

changelog.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
11
This file contains a summary of changes to Haskell.nix and `nix-tools`
22
that will impact users.
33

4+
## Mar 27, 2023
5+
6+
Haskell.nix will no longer parse the `cabal.project` file to
7+
determine the `index-state`. This decision was made due to
8+
the function's inability to handle more than one `index-state`
9+
or a qualified `index-state` as the first `index-state`
10+
field in the file.
11+
12+
As a result, there will be some drawbacks:
13+
14+
* There will no longer be a warning in the trace output
15+
if an index state is not found.
16+
17+
* Even if the `index-state:` in the `cabal.project` has not changed,
18+
the plan will be recomputed when hackage.nix is bumped. However, this
19+
is not expected to be a problem since plan recomputations are typically
20+
quick.
21+
22+
* `project.index-state` cannot be used to obtain the found `index-state`.
23+
However, the parse function is still available if required
24+
(haskell-nix.haskellLib.parseIndexState).
25+
426
## Jul 27, 2022
527
* Removed reliance on `builtins.currentSystem`. It was used it to provide
628
`pkgs.evalPackages` via an overlay that it used to run derivations

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

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -151,46 +151,29 @@ in let
151151
}
152152
'';
153153

154-
cabalProjectIndexState = pkgs.haskell-nix.haskellLib.parseIndexState rawCabalProject;
155-
156-
index-state-found =
154+
index-state-max =
157155
if index-state != null
158156
then index-state
159-
else if cabalProjectIndexState != null
160-
then cabalProjectIndexState
161-
else
162-
let latest-index-state = pkgs.lib.last (builtins.attrNames index-state-hashes);
163-
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;
164-
165-
index-state-pinned = index-state != null || cabalProjectIndexState != null;
157+
else pkgs.lib.last (builtins.attrNames index-state-hashes);
166158

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

169-
in
170-
assert (if index-state-found == null
171-
then throw "No index state passed and none found in ${cabalProjectFileName}" else true);
172-
173-
assert (if index-sha256 == null && !(pkgs.lib.hasSuffix "Z" index-state-found)
174-
then throw "Index state found was ${index-state-found} and no `index-sha256` was provided. "
175-
"The index hash lookup code requires zulu time zone (ends in a Z)" else true);
176-
177-
let
178161
# If a hash was not specified find a suitable cached index state to
179162
# use that will contain all the packages we need. By using the
180163
# first one after the desired index-state we can avoid recalculating
181164
# when new index-state-hashes are added.
182165
# See https://github.com/input-output-hk/haskell.nix/issues/672
183166
cached-index-state = if index-sha256 != null
184-
then index-state-found
167+
then index-state-max
185168
else
186169
let
187170
suitable-index-states =
188171
builtins.filter
189-
(s: s >= index-state-found) # This compare is why we need zulu time
172+
(s: s >= index-state-max) # This compare is why we need zulu time
190173
(builtins.attrNames index-state-hashes);
191174
in
192175
if builtins.length suitable-index-states == 0
193-
then index-state-found
176+
then index-state-max
194177
else pkgs.lib.head suitable-index-states;
195178

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

201184
in
202185
assert (if index-sha256-found == null
203-
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);
186+
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);
204187

205188
let
206189
# Deal with source-repository-packages in a way that will work in
@@ -392,11 +375,6 @@ let
392375
sha256 = plan-sha256;
393376
sha256Arg = "plan-sha256";
394377
this = "project.plan-nix" + (if name != null then " for ${name}" else "");
395-
# Before pinning stuff down we need an index state to use
396-
reasonNotSafe =
397-
if !index-state-pinned
398-
then "index-state is not pinned by an argument or the cabal project file"
399-
else null;
400378
} // pkgs.lib.optionalAttrs (checkMaterialization != null) {
401379
inherit checkMaterialization;
402380
}) (evalPackages.runCommand (nameAndSuffix "plan-to-nix-pkgs") {
@@ -470,12 +448,11 @@ let
470448
export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt
471449
export GIT_SSL_CAINFO=${cacert}/etc/ssl/certs/ca-bundle.crt
472450
473-
echo "Using index-state ${index-state-found}"
474451
CABAL_DIR=${
475452
# This creates `.cabal` directory that is as it would have
476453
# been at the time `cached-index-state`. We may include
477-
# some packages that will be excluded by `index-state-found`
478-
# which is used by cabal (cached-index-state >= index-state-found).
454+
# some packages that will be excluded by `index-state-max`
455+
# which is used by cabal (cached-index-state >= index-state-max).
479456
dotCabal {
480457
inherit cabal-install nix-tools extra-hackage-tarballs;
481458
extra-hackage-repos = fixedProject.repos;
@@ -485,7 +462,7 @@ let
485462
} make-install-plan ${
486463
# Setting the desired `index-state` here in case it is not
487464
# in the cabal.project file. This will further restrict the
488-
# packages used by the solver (cached-index-state >= index-state-found).
465+
# packages used by the solver (cached-index-state >= index-state-max).
489466
pkgs.lib.optionalString (index-state != null) "--index-state=${index-state}"
490467
} \
491468
-w ${
@@ -548,7 +525,6 @@ let
548525
'');
549526
in {
550527
projectNix = plan-nix;
551-
index-state = index-state-found;
552-
inherit src;
528+
inherit index-state-max src;
553529
inherit (fixedProject) sourceRepos extra-hackages;
554530
}

0 commit comments

Comments
 (0)