@@ -151,17 +151,8 @@ final: prev: {
151
151
pkg-def = excludeBootPackages compiler-nix-name plan-pkgs . pkgs ;
152
152
patchesModule = ghcHackagePatches . ${ compiler-nix-name' } or { } ;
153
153
package . compiler-nix-name . version = ( compilerSelection final . buildPackages ) . ${ compiler-nix-name' } . version ;
154
- plan . compiler-nix-name . version = ( compilerSelection final . buildPackages ) . ${ (plan-pkgs . pkgs hackage ) . compiler . nix-name } . version ;
155
154
withMsg = final . lib . assertMsg ;
156
155
in
157
- # Check that the GHC version of the selected compiler matches the one of the plan
158
- assert ( withMsg
159
- ( package . compiler-nix-name . version
160
- == plan . compiler-nix-name . version )
161
- ''
162
- The compiler versions for the package (${ package . compiler-nix-name . version } ) and the plan (${ plan . compiler-nix-name . version } ) don't match.
163
- Make sure you didn't forget to update plan-sha256.''
164
- ) ;
165
156
mkPkgSet {
166
157
inherit pkg-def ;
167
158
pkg-def-extras = [ plan-pkgs . extras
@@ -653,11 +644,156 @@ final: prev: {
653
644
{ config , options , ... } :
654
645
let
655
646
inherit ( config ) compiler-nix-name compilerSelection evalPackages ;
656
-
647
+ selectedCompiler = ( compilerSelection final . buildPackages ) . ${ compiler-nix-name } ;
648
+
649
+ plan-json = builtins . fromJSON ( builtins . readFile ( callProjectResults . plan-json + "/plan.json" ) ) ;
650
+ by-id = final . lib . listToAttrs ( map ( x : { name = x . id ; value = x ; } ) plan-json . install-plan ) ;
651
+ to-key = p : if p . type == "pre-existing"
652
+ then p . pkg-name
653
+ else p . id ;
654
+ getComponents = cabal2nixComponents : hsPkgs : p :
655
+ let
656
+ components = p . components or { ${ p . component-name } = { inherit ( p ) depends exe-depends ; } ; } ;
657
+ lookupDependency = hsPkgs : d :
658
+ if by-id . ${ d } . component-name or "lib" == "lib"
659
+ then hsPkgs . ${ to-key by-id . ${ d } }
660
+ else hsPkgs . ${ to-key by-id . ${ d } } . components . sublibs . ${ final . lib . removePrefix "lib:" by-id . ${ d } . component-name } ;
661
+ lookupExeDependency = d :
662
+ hsPkgs . pkgsBuildBuild . ${ to-key by-id . ${ d } } . components . exes . ${ final . lib . removePrefix "exe:" by-id . ${ d } . component-name } ;
663
+ componentsWithPrefix = collectionName : prefix :
664
+ final . lib . listToAttrs ( final . lib . concatLists ( final . lib . mapAttrsToList ( n : c :
665
+ final . lib . optional ( final . lib . hasPrefix "${ prefix } :" n ) (
666
+ let
667
+ name = final . lib . removePrefix "${ prefix } :" n ;
668
+ value = ( if cabal2nixComponents == null then { } else cabal2nixComponents . ${ collectionName } . ${ name } ) // {
669
+ buildable = true ;
670
+ depends = map ( lookupDependency hsPkgs ) c . depends ;
671
+ build-tools = map lookupExeDependency c . exe-depends ;
672
+ } ;
673
+ in { inherit name value ; }
674
+ ) ) components ) ) ;
675
+ in
676
+ final . lib . mapAttrs componentsWithPrefix haskellLib . componentPrefix
677
+ // final . lib . optionalAttrs ( components ? lib ) {
678
+ library = ( if cabal2nixComponents == null then { } else cabal2nixComponents . library ) // {
679
+ buildable = true ;
680
+ depends = map ( lookupDependency hsPkgs ) components . lib . depends ;
681
+ build-tools = map lookupExeDependency components . lib . exe-depends ;
682
+ } ;
683
+ } ;
657
684
callProjectResults = callCabalProjectToNix config ;
658
- plan-pkgs = importAndFilterProject {
659
- inherit ( callProjectResults ) projectNix sourceRepos src ;
660
- } ;
685
+ plan-pkgs = if ! builtins . pathExists ( callProjectResults . plan-json + "/plan.json" )
686
+ then
687
+ # TODO remove this once all the materialized files are updated
688
+ importAndFilterProject {
689
+ projectNix = callProjectResults . plan-json ;
690
+ inherit ( callProjectResults ) sourceRepos src ;
691
+ }
692
+ else {
693
+ pkgs = ( hackage : {
694
+ packages = final . lib . listToAttrs (
695
+ final . lib . concatMap ( p :
696
+ final . lib . optional ( p . type == "pre-existing" || ( p . type == "configured" && ( p . style == "global" || p . style == "inplace" ) ) ) {
697
+ name = to-key p ;
698
+ value . revision =
699
+ { hsPkgs , ...} @args :
700
+ let cabal2nix = ( if builtins . pathExists ( callProjectResults . plan-json + "/cabal-files/${ p . pkg-name } .nix" )
701
+ then import ( callProjectResults . plan-json + "/cabal-files/${ p . pkg-name } .nix" )
702
+ else ( ( ( hackage . ${ p . pkg-name } ) . ${ p . pkg-version } ) . revisions ) . default ) ( args // { hsPkgs = { } ; } ) ;
703
+ in cabal2nix // {
704
+ flags = p . flags ;
705
+ components = getComponents cabal2nix . components hsPkgs p ;
706
+ package = cabal2nix . package // {
707
+ setup-depends = map ( lookupDependency hsPkgs . pkgsBuildBuild ) ( p . setup . depends or [ ] ) ;
708
+ # TODO = map lookupExeDependency (p.setup.exe-depends or []);
709
+ } ;
710
+ } ;
711
+ } ) plan-json . install-plan ) ;
712
+ compiler = {
713
+ inherit ( selectedCompiler ) version ;
714
+ } ;
715
+ } ) ;
716
+ extras = ( hackage : {
717
+ packages = final . lib . listToAttrs (
718
+ final . lib . concatMap ( p :
719
+ final . lib . optional ( p . type == "configured" && p . style == "local" ) {
720
+ name = to-key p ;
721
+ value =
722
+ { hsPkgs , ...} @args :
723
+ let cabal2nix = import ( callProjectResults . plan-json + "/.plan.nix/${ p . pkg-name } .nix" ) ( args // { hsPkgs = { } ; } ) ;
724
+ in builtins . removeAttrs cabal2nix [ "src" ] // {
725
+ flags = p . flags ;
726
+ components = getComponents cabal2nix . components hsPkgs p ;
727
+ package = cabal2nix . package // {
728
+ setup-depends = map ( lookupDependency hsPkgs . pkgsBuildBuild ) ( p . setup . depends or [ ] ) ;
729
+ # TODO = map lookupExeDependency (p.setup.exe-depends or []);
730
+ } ;
731
+ } ;
732
+ } ) plan-json . install-plan ) ;
733
+ } ) ;
734
+ modules = [ {
735
+ preExistingPkgs =
736
+ final . lib . concatMap ( p :
737
+ final . lib . optional ( p . type == "pre-existing" ) p . pkg-name ) plan-json . install-plan ;
738
+ }
739
+ ( { lib , ...} : {
740
+ packages = final . lib . listToAttrs ( map ( p :
741
+ let components =
742
+ if p ? component-name
743
+ then { ${ p . component-name } = { inherit ( p ) depends exe-depends ; } ; }
744
+ else p . components or { } ;
745
+ in {
746
+ name = to-key p ;
747
+ value . components = final . lib . mapAttrs ( type : x :
748
+ if type == "library"
749
+ then { planned = lib . mkOverride 900 true ; }
750
+ else
751
+ final . lib . mapAttrs ( _ : _ : {
752
+ planned = lib . mkOverride 900 true ;
753
+ } ) x
754
+ ) ( getComponents null hsPkgs p ) ;
755
+ } ) plan-json . install-plan ) ;
756
+ } )
757
+ ( { config , ...} : {
758
+ hsPkgs = builtins . removeAttrs ( builtins . mapAttrs ( packageName : packageTargets :
759
+ let
760
+ byVersion = builtins . groupBy ( x : x . pkg-version ) packageTargets ;
761
+ versions = builtins . attrNames byVersion ;
762
+ in if builtins . length versions != 1
763
+ then throw "Multiple versions for ${ packageName } ${ builtins . toJSON versions } "
764
+ else let
765
+ components = builtins . listToAttrs ( map ( x : { name = x . component-name ; value = x . available ; } ) packageTargets ) ;
766
+ lookupComponent = collectionName : name : available :
767
+ let attrPath =
768
+ if collectionName == ""
769
+ then "${ packageName } .components.library"
770
+ else "${ packageName } .components.${ collectionName } .${ name } " ;
771
+ in if builtins . length available != 1
772
+ then throw "Multiple avaialble targets for ${ attrPath } "
773
+ else if builtins . isString ( builtins . head available )
774
+ then throw "${ builtins . head available } looking for ${ attrPath } "
775
+ else if collectionName == ""
776
+ then config . hsPkgs . ${ ( builtins . head available ) . id } . components . library
777
+ else config . hsPkgs . ${ ( builtins . head available ) . id } . components . ${ collectionName } . ${ name } ;
778
+ componentsWithPrefix = collectionName : prefix :
779
+ final . lib . listToAttrs ( final . lib . concatLists ( final . lib . mapAttrsToList ( n : available :
780
+ final . lib . optional ( final . lib . hasPrefix "${ prefix } :" n ) (
781
+ let
782
+ name = final . lib . removePrefix "${ prefix } :" n ;
783
+ value = lookupComponent collectionName name available ;
784
+ in { inherit name value ; }
785
+ ) ) components ) ) ;
786
+ in {
787
+ components =
788
+ final . lib . mapAttrs componentsWithPrefix haskellLib . componentPrefix
789
+ // final . lib . optionalAttrs ( components ? lib ) {
790
+ library = lookupComponent "" "" components . lib ;
791
+ } ;
792
+ } )
793
+ ( builtins . groupBy ( x : x . pkg-name ) plan-json . targets ) ) config . preExistingPkgs ;
794
+ } )
795
+ ] ;
796
+ } ;
661
797
buildProject = if final . stdenv . hostPlatform != final . stdenv . buildPlatform
662
798
then final . pkgsBuildBuild . haskell-nix . cabalProject' projectModule
663
799
else project ;
@@ -682,7 +818,7 @@ final: prev: {
682
818
else if config . ghc != null
683
819
then config . ghc
684
820
else
685
- final . lib . mkDefault ( config . compilerSelection final . buildPackages ) . ${ compiler-nix-name } ;
821
+ final . lib . mkDefault selectedCompiler ;
686
822
compiler . nix-name = final . lib . mkForce config . compiler-nix-name ;
687
823
evalPackages = final . lib . mkDefault evalPackages ;
688
824
} ] ;
0 commit comments