Skip to content

Commit

Permalink
Make cabalProjectIndexState not break with CHaP
Browse files Browse the repository at this point in the history
When the second line is added to cabal.project:
```
index-state: 2022-09-27T00:00:00Z
index-state: cardano-haskell-packages 2022-10-25T20:00:00Z
```

we still need to be able to extract the index state.
  • Loading branch information
Anviking committed Nov 29, 2022
1 parent 5efe75a commit 5944941
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions nix/overlays/common-lib.nix
Expand Up @@ -39,13 +39,24 @@ in {
go;

# Get the index-state and ghc version out of a cabal.project file.
#
# TODO: It would be better to re-use functions from haskell.nix like:
# https://github.com/input-output-hk/haskell.nix/blob/a30665693a1991341d067df55bbf2bec1124bddd/lib/cabal-project-parser.nix
cabalProjectIndexState = cabalProject: let
awkProgram = builtins.replaceStrings ["\n"] [" "] ''
BEGIN { print "{"; }
END { print "}"; }
{ if (($1=="index-state:" || $1=="with-compiler:") && $2!="cardano-haskell-packages")
{ gsub(/:/, "", $1); print" " $1 " = \"" $2 "\";"; }
}
'';

parsed = import (self.runCommandNoCC "cabal-project-index-state.nix" {
preferLocalBuild = true;
allowSubstitutes = false;
} ''
awk 'BEGIN { print "{"; } END { print "}"; } /^(index-state|with-compiler)/ { gsub(/:/, "", $1); print" " $1 " = \"" $2 "\";"; }' < ${cabalProject} > $out
'');
} (''
awk '${awkProgram}' < ${cabalProject} > $out
'' ));
in {
index-state = parsed.index-state or null;
compiler-nix-name = if parsed ? with-compiler
Expand Down

0 comments on commit 5944941

Please sign in to comment.