Skip to content

Commit c8c5e6a

Browse files
authored
Fix handling of packages with no planned components. (#110)
If a package is local to the project, but none of the components are in the plan, then there will be an empty `components` attribute and no `component-name`. Currently this causes an error as we look for a `component-name` when the `components` attribute is empty. This change will make it so that we only look for the `component-name` when there is no `components` attribute at all.
1 parent 16c3c38 commit c8c5e6a

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

plan2nix/Plan2Nix.hs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,15 @@ value2plan plan = Plan { packages, components, extras, compilerVersion, compiler
261261
nixComponentAttr = Text.pack . componentNameToHaskellNixAttr pkgName . Text.unpack
262262
in
263263
map ((quoted pkgName <> ".components.") <>) $
264-
case (pkg ^. key "type" . _String, Map.keys (pkg ^. key "components" . _Object)) of
265-
("pre-existing", _) -> [ "library" ]
266-
(_, []) -> [ nixComponentAttr $ pkg ^. key "component-name" . _String ]
267-
(_, c) -> map nixComponentAttr c)
264+
if pkg ^. key "type" . _String == "pre-existing"
265+
then [ "library" ]
266+
else
267+
-- If a `components` attribute exists then the keys of that are the component names.
268+
-- If it does not exist then look for `component-name` instead.
269+
maybe
270+
[nixComponentAttr $ pkg ^. key "component-name" . _String]
271+
(map nixComponentAttr . Map.keys)
272+
(pkg ^? key "components" . _Object))
268273
$ Vector.toList (plan ^. key "install-plan" . _Array)
269274

270275
-- Convert a cabal style component name to the haskell.nix attribute path.

0 commit comments

Comments
 (0)