git.iko.soy/typeable/stackage2nix
on master help sign in
Handle empty default stack.yaml package
commit55e2222b76861739b4a66a9194036a3bd86ac0e1 authorDmitry Bushev <bushevdv@gmail.com> dateSun 25 Jun 2017, 20:11 (9 years ago) parente268fb7
2 files changed+16−9
src/Distribution/Nixpkgs/Haskell/Stack/PrettyPrinting.hs+7−4 src/Stack/Config.hs+9−5
src/Distribution/Nixpkgs/Haskell/Stack/PrettyPrinting.hs+7−4
@@ -3,6 +3,9 @@
33module Distribution.Nixpkgs.Haskell.Stack.PrettyPrinting where
44
55import Control.Lens
6+import Data.Foldable as F
7+import Data.List as L
8+import Data.List.NonEmpty as NE
69import Data.Maybe
710import Data.String
811import Distribution.Nixpkgs.Haskell.Derivation
@@ -24,8 +27,8 @@ makeLenses ''OverrideConfig
2427hasField :: Lens' a (Maybe b) -> a -> Bool
2528hasField p = views p isJust
2629
27−overridePackages :: [Derivation] -> Doc
28−overridePackages = PP.packageSetConfig . PP.cat . fmap callPackage
30+overridePackages :: (Foldable t, Functor t) => t Derivation -> Doc
31+overridePackages = PP.packageSetConfig . PP.cat . F.toList . fmap callPackage
2932 where
3033 drvNameQuoted = PP.doubleQuotes . disp . pkgName . view pkgid
3134 callPackage drv = hang
@@ -51,7 +54,7 @@ callStackageConfig :: FilePath -> Doc
5154callStackageConfig path = hsep
5255 [ "callPackage", disp (fromString path :: Nix.FilePath), "{}"]
5356
54−overrideHaskellPackages :: OverrideConfig -> [Derivation] -> Doc
57+overrideHaskellPackages :: OverrideConfig -> NonEmpty Derivation -> Doc
5558overrideHaskellPackages oc packages = vcat
5659 [ funargs ["nixpkgs ? import <nixpkgs> {}"]
5760 , ""
@@ -81,4 +84,4 @@ overrideHaskellPackages oc packages = vcat
8184
8285toNixGhcVersion :: Version -> Doc
8386toNixGhcVersion =
84− (<>) "ghc" . text . filter (/= '.') . show . disp
87+ (<>) "ghc" . text . L.filter (/= '.') . show . disp
src/Stack/Config.hs+9−5
@@ -6,6 +6,8 @@ import Control.Lens
66import Data.Bifunctor
77import Data.ByteString as BS
88import Data.Coerce
9+import Data.Foldable as F
10+import Data.List.NonEmpty as NE
911import Data.Maybe
1012import Data.Text as T
1113import Data.Yaml
@@ -48,7 +50,7 @@ makeLenses ''StackPackage
4850
4951data StackConfig = StackConfig
5052 { _scResolver :: !StackResolver
51− , _scPackages :: ![StackPackage]
53+ , _scPackages :: !(NonEmpty StackPackage)
5254 } deriving (Eq, Ord, Show)
5355
5456makeLenses ''StackConfig
@@ -56,10 +58,12 @@ makeLenses ''StackConfig
5658fromYamlConfig :: Yaml.Config -> StackConfig
5759fromYamlConfig c = StackConfig{..}
5860 where
59− _scResolver = coerce $ c ^. cResolver
60− _scPackages =
61− (fromYamlPackage <$> c ^. cPackages . to (fromMaybe mempty)) ++
62− (fromYamlExtraDep <$> c ^. cExtraDeps . to (fromMaybe mempty))
61+ _scResolver = coerce $ c ^. cResolver
62+ _scPackages = F.foldr (NE.<|) neYamlPackages yamlExtraDeps
63+ neYamlPackages = fromMaybe (pure defaultPackage) $ NE.nonEmpty yamlPackages
64+ yamlPackages = fromYamlPackage <$> fromMaybe mempty (c ^. cPackages)
65+ yamlExtraDeps = fromYamlExtraDep <$> fromMaybe mempty (c ^. cExtraDeps)
66+ defaultPackage = StackPackage (StackFilePath ".") False
6367
6468fromYamlPackage :: Yaml.Package -> StackPackage
6569fromYamlPackage = \case