|
133 | 133 | # defaultLocalPkgFilter: pkgName: path: type: true
|
134 | 134 | # ```
|
135 | 135 | localPkgFilter ?
|
136 |
| - defaultLocalPkgFilter: pkgName: path: type: defaultLocalPkgFilter path type |
| 136 | + defaultLocalPkgFilter: pkgName: path: type: defaultLocalPkgFilter path type, |
| 137 | + # A function to generate a cabal file for a local package. |
| 138 | + # Normally this is handled by `cabal2nix`, but in special cases we might want |
| 139 | + # to do this ourselves, eg, when using hpack `!include`s. |
| 140 | + # |
| 141 | + # |
| 142 | + # generateCabalFile :: String -> String -> Path -> Path |
| 143 | + generateCabalFile ? |
| 144 | + pkgName: subdir: filteredSrc: filteredSrc |
137 | 145 | }:
|
138 | 146 |
|
139 | 147 | # The stack.yaml path can be computed from the stack.yaml.lock path, or
|
@@ -558,15 +566,19 @@ let
|
558 | 566 | # Example: `"my-cool-pkg"`
|
559 | 567 | pkgNameFromPackageYaml =
|
560 | 568 | let
|
561 |
| - packageYaml = readYAML (justCabalFilePath + "/package.yaml"); |
562 |
| - in |
563 |
| - if packageYaml ? name then |
564 |
| - packageYaml.name |
565 |
| - else |
566 |
| - throw |
567 |
| - ("Could not find read a .name field from the package.yaml file in package ${localPkgPathStr}. " + |
568 |
| - "This is unexpected. All package.yaml files should have a top-level .name field. " + |
569 |
| - "package.yaml file: ${builtins.toJSON packageYaml}"); |
| 569 | + packageYamlName = builtins.readFile |
| 570 | + (runCommand "read-package-name" {} |
| 571 | + '' |
| 572 | + function fail { |
| 573 | + echo "Could not find read a .name field from the package.yaml file in package ${localPkgPathStr}." |
| 574 | + echo "This is unexpected. All package.yaml files should have a top-level .name field." |
| 575 | + echo "package.yaml file: " |
| 576 | + cat package.yaml |
| 577 | + exit 1 |
| 578 | + } |
| 579 | + (sed -nr 's/name:\s*\"?(.*)\"?\s*/\1/p' ${justCabalFilePath + "/package.yaml"} | tr -d '\n' >$out) || fail'' |
| 580 | + ); |
| 581 | + in packageYamlName; |
570 | 582 |
|
571 | 583 | # Whether or not this package has at least one .cabal file.
|
572 | 584 | #
|
@@ -626,12 +638,25 @@ let
|
626 | 638 |
|
627 | 639 | # Path to the Haskell package.
|
628 | 640 | #
|
629 |
| - # pkgPath :: Path |
630 |
| - pkgPath = lib.cleanSourceWith { |
| 641 | + # filteredPkgPath :: Path |
| 642 | + filteredPkgPath = lib.cleanSourceWith { |
631 | 643 | src = rawPkgPath;
|
632 | 644 | filter = path: type: localPkgFilter localPkgDefaultFilter pkgName path type;
|
633 | 645 | name = "stacklock2nix-pkg-sources-" + pkgName;
|
634 | 646 | };
|
| 647 | + |
| 648 | + # Path to the Haskell package, |
| 649 | + # but if it doesn't contain a .cabal file |
| 650 | + # then we call the `generateCabalFile` function to potentially pre-generate |
| 651 | + # the .cabal file. This is useful if the `package.yaml` file needs special |
| 652 | + # treatment, eg, because of includes. |
| 653 | + # |
| 654 | + # pkgPath :: Path |
| 655 | + pkgPath = |
| 656 | + if hasSingleCabalFile then |
| 657 | + filteredPkgPath |
| 658 | + else |
| 659 | + generateCabalFile pkgName localPkgPathStr filteredPkgPath; |
635 | 660 | in
|
636 | 661 | { inherit pkgPath pkgName; };
|
637 | 662 |
|
|
0 commit comments