git.iko.soy/typeable/stackage2nix
on master help sign in
Handle empty default stack.yaml package
55e2222Dmitry Bushev
src/Distribution/Nixpkgs/Haskell/Stack/PrettyPrinting.hs+7−4
@@ -3,6 +3,9 @@
3module Distribution.Nixpkgs.Haskell.Stack.PrettyPrinting where
3module Distribution.Nixpkgs.Haskell.Stack.PrettyPrinting where
4
4
5import Control.Lens
5import Control.Lens
6+import Data.Foldable as F
7+import Data.List as L
8+import Data.List.NonEmpty as NE
6import Data.Maybe
9import Data.Maybe
7import Data.String
10import Data.String
8import Distribution.Nixpkgs.Haskell.Derivation
11import Distribution.Nixpkgs.Haskell.Derivation
@@ -24,8 +27,8 @@ makeLenses ''OverrideConfig
24hasField :: Lens' a (Maybe b) -> a -> Bool
27hasField :: Lens' a (Maybe b) -> a -> Bool
25hasField p = views p isJust
28hasField p = views p isJust
26
29
27−overridePackages :: [Derivation] -> Doc
30+overridePackages :: (Foldable t, Functor t) => t Derivation -> Doc
28−overridePackages = PP.packageSetConfig . PP.cat . fmap callPackage
31+overridePackages = PP.packageSetConfig . PP.cat . F.toList . fmap callPackage
29 where
32 where
30 drvNameQuoted = PP.doubleQuotes . disp . pkgName . view pkgid
33 drvNameQuoted = PP.doubleQuotes . disp . pkgName . view pkgid
31 callPackage drv = hang
34 callPackage drv = hang
@@ -51,7 +54,7 @@ callStackageConfig :: FilePath -> Doc
51callStackageConfig path = hsep
54callStackageConfig path = hsep
52 [ "callPackage", disp (fromString path :: Nix.FilePath), "{}"]
55 [ "callPackage", disp (fromString path :: Nix.FilePath), "{}"]
53
56
54−overrideHaskellPackages :: OverrideConfig -> [Derivation] -> Doc
57+overrideHaskellPackages :: OverrideConfig -> NonEmpty Derivation -> Doc
55overrideHaskellPackages oc packages = vcat
58overrideHaskellPackages oc packages = vcat
56 [ funargs ["nixpkgs ? import <nixpkgs> {}"]
59 [ funargs ["nixpkgs ? import <nixpkgs> {}"]
57 , ""
60 , ""
@@ -81,4 +84,4 @@ overrideHaskellPackages oc packages = vcat
81
84
82toNixGhcVersion :: Version -> Doc
85toNixGhcVersion :: Version -> Doc
83toNixGhcVersion =
86toNixGhcVersion =
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
6import Data.Bifunctor
6import Data.Bifunctor
7import Data.ByteString as BS
7import Data.ByteString as BS
8import Data.Coerce
8import Data.Coerce
9+import Data.Foldable as F
10+import Data.List.NonEmpty as NE
9import Data.Maybe
11import Data.Maybe
10import Data.Text as T
12import Data.Text as T
11import Data.Yaml
13import Data.Yaml
@@ -48,7 +50,7 @@ makeLenses ''StackPackage
48
50
49data StackConfig = StackConfig
51data StackConfig = StackConfig
50 { _scResolver :: !StackResolver
52 { _scResolver :: !StackResolver
51− , _scPackages :: ![StackPackage]
53+ , _scPackages :: !(NonEmpty StackPackage)
52 } deriving (Eq, Ord, Show)
54 } deriving (Eq, Ord, Show)
53
55
54makeLenses ''StackConfig
56makeLenses ''StackConfig
@@ -56,10 +58,12 @@ makeLenses ''StackConfig
56fromYamlConfig :: Yaml.Config -> StackConfig
58fromYamlConfig :: Yaml.Config -> StackConfig
57fromYamlConfig c = StackConfig{..}
59fromYamlConfig c = StackConfig{..}
58 where
60 where
59− _scResolver = coerce $ c ^. cResolver
61+ _scResolver = coerce $ c ^. cResolver
60− _scPackages =
62+ _scPackages = F.foldr (NE.<|) neYamlPackages yamlExtraDeps
63+ neYamlPackages = fromMaybe (pure defaultPackage) $ NE.nonEmpty yamlPackages
61− (fromYamlPackage <$> c ^. cPackages . to (fromMaybe mempty)) ++
64+ yamlPackages = fromYamlPackage <$> fromMaybe mempty (c ^. cPackages)
62− (fromYamlExtraDep <$> c ^. cExtraDeps . to (fromMaybe mempty))
65+ yamlExtraDeps = fromYamlExtraDep <$> fromMaybe mempty (c ^. cExtraDeps)
66+ defaultPackage = StackPackage (StackFilePath ".") False
63
67
64fromYamlPackage :: Yaml.Package -> StackPackage
68fromYamlPackage :: Yaml.Package -> StackPackage
65fromYamlPackage = \case
69fromYamlPackage = \case