on iko/ghcjs-patch-master help sign in
Add `project.plan-nix.freeze` (#1055)

Issues with `cabal.project.freeze` files can be tricky to debug. While it is possible to run without a freeze file and look at the `plan-nix` or `plan-nix.json` (the `plan.json`) created when haskell.nix configured the project, it would be nice to also have the output of `cabal freeze` as it will be in the correct format and contains a different subset of `plan.json` than the `plan-nix`. This might also be useful for automating updating of `.freeze` files.

commitcb264f6f6ad8522a24ecf2ee8d4ad71bfb90baf5 authorHamish Mackenzie <Hamish.Mackenzie@iohk.io> dateThu 4 Mar 2021, 16:46 (6 years ago) parentf9aab92
1 file changed+15−2
lib/call-cabal-project-to-nix.nix+15−2
lib/call-cabal-project-to-nix.nix+15−2
@@ -385,7 +385,11 @@ let
385385 LANG = "en_US.UTF-8";
386386 meta.platforms = pkgs.lib.platforms.all;
387387 preferLocalBuild = false;
388− outputs = ["out" "json"];
388+ outputs = [
389+ "out" # The results of plan-to-nix
390+ "json" # The `plan.json` file generated by cabal and used for `plan-to-nix` input
391+ "freeze" # The `cabal.project.freeze` file created by `cabal v2-freeze`
392+ ];
389393 } ''
390394 tmp=$(mktemp -d)
391395 cd $tmp
@@ -421,10 +425,15 @@ let
421425 ${pkgs.lib.optionalString (cabalProjectFreeze != null) ''
422426 cp ${pkgs.evalPackages.writeText "cabal.project.freeze" cabalProjectFreeze} \
423427 cabal.project.freeze
428+ chmod +w cabal.project.freeze
424429 ''}
425430 export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt
426431 export GIT_SSL_CAINFO=${cacert}/etc/ssl/certs/ca-bundle.crt
427432
433+ # Using `cabal v2-freeze` will configure the project (since
434+ # it is not configured yet), taking the existing `cabal.project.freeze`
435+ # file into account. Then it "writes out a freeze file which
436+ # records all of the versions and flags that are picked" (from cabal docs).
428437 echo "Using index-state ${index-state-found}"
429438 HOME=${
430439 # This creates `.cabal` directory that is as it would have
@@ -436,7 +445,7 @@ let
436445 index-state = cached-index-state;
437446 sha256 = index-sha256-found;
438447 }
439− } cabal v2-configure \
448+ } cabal v2-freeze \
440449 --index-state=${
441450 # Setting the desired `index-state` here in case it was not
442451 # from the cabal.project file. This will further restrict the
@@ -453,6 +462,10 @@ let
453462 "--ghcjs --with-ghcjs=js-unknown-ghcjs-ghc --with-ghcjs-pkg=js-unknown-ghcjs-ghc-pkg"} \
454463 ${configureArgs}
455464
465+ cp cabal.project.freeze $freeze
466+ # Not needed any more (we don't want it to wind up in the $out hash)
467+ rm cabal.project.freeze
468+
456469 mkdir -p $out
457470
458471 # ensure we have all our .cabal files (also those generated from package.yaml) files.