git.iko.soy/typeable/stackage2nix
on master help sign in
Honour stack.yaml's subdirs (#31)

Closes #30.

commit89af70dee760cb714f59715dd0c7a9ed0e3ce5bc authorMateusz Kowalczyk <fuuzetsu@fuuzetsu.co.uk> dateMon 4 Sep 2017, 14:49 (9 years ago) parentc523d22
5 files changed+60−25
src/Distribution/Nixpkgs/Haskell/Stack.hs+15−7 src/LtsHaskell.hs+1−1 src/Stack/Config.hs+28−14 src/Stack/Config/Yaml.hs+1 test/Stack/Config/YamlSpec.hs+15−3
src/Distribution/Nixpkgs/Haskell/Stack.hs+15−7
@@ -1,6 +1,7 @@
11module Distribution.Nixpkgs.Haskell.Stack where
22
33import Control.Lens
4+import Data.Maybe (fromMaybe)
45import Data.Text as T
56import Distribution.Compiler as Compiler
67import Distribution.Nixpkgs.Fetch
@@ -42,30 +43,36 @@ getStackPackageFromDb
4243getStackPackageFromDb optHackageDb stackPackage =
4344 PackageSourceSpec.getPackage
4445 (unHackageDb <$> optHackageDb)
45− (stackLocationToSource $ stackPackage ^. spLocation)
46+ (stackLocationToSource (stackPackage ^. spLocation) (stackPackage ^. spDir))
4647
47−stackLocationToSource :: PackageLocation -> Source
48−stackLocationToSource = \case
48+stackLocationToSource
49+ :: PackageLocation
50+ -- | Subdirectory in the package containing cabal file.
51+ -> Maybe FilePath
52+ -> Source
53+stackLocationToSource pl mCabalDir = case pl of
4954 HackagePackage p -> Source
5055 { sourceUrl = "cabal://" ++ T.unpack p
5156 , sourceRevision = mempty
5257 , sourceHash = UnknownHash
53− , sourceCabalDir = mempty }
58+ , sourceCabalDir = cabalDir }
5459 StackFilePath p -> Source
5560 { sourceUrl = p
5661 , sourceRevision = mempty
5762 , sourceHash = UnknownHash
58− , sourceCabalDir = mempty }
63+ , sourceCabalDir = cabalDir }
5964 StackUri uri -> Source
6065 { sourceUrl = URI.uriToString id uri mempty
6166 , sourceRevision = mempty
6267 , sourceHash = UnknownHash
63− , sourceCabalDir = mempty }
68+ , sourceCabalDir = cabalDir }
6469 StackRepo r -> Source
6570 { sourceUrl = T.unpack $ r ^. rUri
6671 , sourceRevision = T.unpack $ r ^. rCommit
6772 , sourceHash = UnknownHash
68− , sourceCabalDir = mempty }
73+ , sourceCabalDir = cabalDir }
74+ where
75+ cabalDir = fromMaybe mempty mCabalDir
6976
7077packageDerivation
7178 :: StackPackagesConfig
@@ -79,6 +86,7 @@ packageDerivation conf optHackageDb stackPackage = do
7986 & src .~ pkgSource pkg
8087 -- TODO: remove after Nixos/Nixpkgs #27196 released
8188 & enableSeparateDataOutput .~ False
89+ & subpath %~ flip fromMaybe (stackPackage ^. spDir)
8290 return $ if stackPackage ^. spExtraDep
8391 then drv
8492 & doCheck &&~ conf ^. spcDoCheckStackage
src/LtsHaskell.hs+1−1
@@ -51,7 +51,7 @@ getPackageFromRepo allCabalHashesPath mSha1Hash pkgId = do
5151getPackageFromDb :: PackageIdentifier -> IO Package
5252getPackageFromDb pkgId =
5353 getStackPackageFromDb Nothing
54− $ StackPackage (HackagePackage (T.pack $ Text.display pkgId)) True
54+ $ StackPackage (HackagePackage (T.pack $ Text.display pkgId)) True Nothing
5555
5656loadPackage :: FilePath -> Maybe SHA1Hash -> PackageIdentifier -> IO Package
5757loadPackage allCabalHashesPath mSha1Hash pkgId =
src/Stack/Config.hs+28−14
@@ -9,6 +9,7 @@ import Data.Coerce
99import Data.Foldable as F
1010import Data.List.NonEmpty as NE
1111import Data.Maybe
12+import Data.Semigroup (sconcat)
1213import Data.Text as T
1314import Data.Yaml
1415import Network.URI
@@ -48,6 +49,8 @@ makePrisms ''PackageLocation
4849data StackPackage = StackPackage
4950 { _spLocation :: !PackageLocation
5051 , _spExtraDep :: !Bool
52+ -- | Subdirectory containing the cabal file if any specified.
53+ , _spDir :: !(Maybe FilePath)
5154 } deriving (Eq, Ord, Show)
5255
5356makeLenses ''StackPackage
@@ -62,28 +65,39 @@ makeLenses ''StackConfig
6265fromYamlConfig :: Yaml.Config -> StackConfig
6366fromYamlConfig c = StackConfig{..}
6467 where
65− _scResolver = coerce $ c ^. cResolver
66− _scPackages = F.foldr (NE.<|) neYamlPackages yamlExtraDeps
67− neYamlPackages = fromMaybe (pure defaultPackage) $ NE.nonEmpty yamlPackages
68− yamlPackages = fromYamlPackage <$> fromMaybe mempty (c ^. cPackages)
68+ _scResolver = coerce $ c ^. cResolver
69+ _scPackages = F.foldr (NE.<|) neYamlPackages yamlExtraDeps
70+ neYamlPackages = fromMaybe (pure defaultPackage)
71+ . fmap sconcat $ NE.nonEmpty yamlPackages
72+ yamlPackages = fromYamlPackage <$> (fromMaybe mempty (c ^. cPackages))
6973 yamlExtraDeps = fromYamlExtraDep <$> fromMaybe mempty (c ^. cExtraDeps)
70− defaultPackage = StackPackage (StackFilePath ".") False
74+ defaultPackage = StackPackage (StackFilePath ".") False Nothing
7175
72−fromYamlPackage :: Yaml.Package -> StackPackage
76+
77+fromYamlPackage
78+ :: Yaml.Package
79+ -- | A single 'Yaml.Package' can result in multiple actual
80+ -- packages if it has multiple subdirs specified.
81+ -> NonEmpty StackPackage
7382fromYamlPackage = \case
7483 Yaml.Simple p ->
75− StackPackage (parseSimplePath p) False
76− Yaml.LocationSimple (Yaml.Location p extraDep) ->
77− StackPackage (parseSimplePath p) (fromMaybe False extraDep)
78− Yaml.LocationGit (Location git extraDep) ->
79− StackPackage (StackRepo $ fromYamlGit git) (fromMaybe False extraDep)
80− Yaml.LocationHg (Location hg extraDep) ->
81− StackPackage (StackRepo $ fromYamlHg hg) (fromMaybe False extraDep)
84+ unroll Nothing $ StackPackage (parseSimplePath p) False
85+ Yaml.LocationSimple (Location p extraDep ms) ->
86+ unroll ms $ StackPackage (parseSimplePath p) (fromMaybe False extraDep)
87+ Yaml.LocationGit (Location git extraDep ms) ->
88+ unroll ms $ StackPackage (StackRepo $ fromYamlGit git) (fromMaybe False extraDep)
89+ Yaml.LocationHg (Location hg extraDep ms) ->
90+ unroll ms $ StackPackage (StackRepo $ fromYamlHg hg) (fromMaybe False extraDep)
8291 where
8392 parseSimplePath (T.unpack -> p) = maybe (StackFilePath p) StackUri $ parseURI p
93+ -- Each package gets a single directory with cabal file in it. If
94+ -- it's not specified, path is empty.
95+ unroll subs p = case subs of
96+ Just (x : xs) -> NE.map (p . Just) (x :| xs)
97+ _ -> p Nothing :| []
8498
8599fromYamlExtraDep :: Text -> StackPackage
86−fromYamlExtraDep = flip StackPackage True . HackagePackage
100+fromYamlExtraDep t = StackPackage (HackagePackage t) True Nothing
87101
88102fromYamlGit :: Yaml.Git -> Repo
89103fromYamlGit yg = Repo{..}
src/Stack/Config/Yaml.hs+1
@@ -10,6 +10,7 @@ import Stack.Config.TH
1010data Location a = Location
1111 { _lLocation :: !a
1212 , _lExtraDep :: !(Maybe Bool)
13+ , _lSubdirs :: !(Maybe [FilePath])
1314 } deriving (Eq, Show)
1415
1516makeLenses ''Location
test/Stack/Config/YamlSpec.hs+15−3
@@ -28,6 +28,12 @@ packages:
2828 - location:
2929 git: git@github.com:commercialhaskell/stack.git
3030 commit: 6a86ee32e5b869a877151f74064572225e1a0398
31+ - location:
32+ git: git@github.com:example/mega-repo
33+ commit: 6a86ee32e5b869a877151f74064572225e1a0000
34+ subdirs:
35+ - subdir1
36+ - subdir2
3137# Comment
3238extra-deps:
3339- acme-missiles-0.3
@@ -45,13 +51,19 @@ config = Config
4551 { _cResolver = "lts-3.7"
4652 , _cPackages = Just
4753 [ Simple "."
48− , LocationSimple (Location "dir1/dir2" Nothing)
49− , LocationSimple (Location "https://example.com/foo/bar/baz-0.0.2.tar.gz" (Just True))
54+ , LocationSimple (Location "dir1/dir2" Nothing Nothing)
55+ , LocationSimple (Location "https://example.com/foo/bar/baz-0.0.2.tar.gz" (Just True) Nothing)
5056 , LocationGit $ Location
5157 (Git
5258 "git@github.com:commercialhaskell/stack.git"
5359 "6a86ee32e5b869a877151f74064572225e1a0398")
54− Nothing]
60+ Nothing Nothing
61+ , LocationGit (Location
62+ (Git
63+ "git@github.com:example/mega-repo"
64+ "6a86ee32e5b869a877151f74064572225e1a0000")
65+ Nothing (Just ["subdir1", "subdir2"]))
66+ ]
5567 , _cExtraDeps = Just
5668 ["acme-missiles-0.3"]
5769 }