git.iko.soy/typeable/stackage2nix
on master help sign in
Build StackConfig relative to yaml file
commit1bbc1b8b8618657fe3ca3f2243907a1e35829b20 authorDmitry Bushev <bushevdv@gmail.com> dateSun 25 Jun 2017, 02:22 (9 years ago) parent35e0601
6 files changed+56−19
src/Distribution/Nixpkgs/Haskell/Stack.hs+15−1 src/Runner.hs+2−2 src/Runner/Cli.hs+12−11 src/Stack/Config.hs+13−4 src/Stack/Types.hs+13 stack.yaml+1−1
src/Distribution/Nixpkgs/Haskell/Stack.hs+15−1
@@ -6,6 +6,7 @@ import Distribution.Compiler as Compiler
66import Distribution.Nixpkgs.Fetch
77import Distribution.Nixpkgs.Haskell.Derivation
88import Distribution.Nixpkgs.Haskell.FromCabal as FromCabal
9+import Distribution.Nixpkgs.Haskell.FromStack.Package as FromStack
910import Distribution.Nixpkgs.Haskell.PackageSourceSpec as PackageSourceSpec
1011import Distribution.PackageDescription as PackageDescription
1112import Distribution.System as System
@@ -79,8 +80,11 @@ packageDerivation
7980 -> IO Derivation
8081packageDerivation conf optHackageDb stackPackage = do
8182 pkg <- getStackPackageFromDb optHackageDb stackPackage
82− pure $ genericPackageDerivation conf pkg
83+ pure . overrideStackageDerivation
84+ $ genericPackageDerivation conf pkg
8385 & src .~ pkgSource pkg
86+ & doCheck .~ False
87+ & runHaddock .~ False
8488
8589genericPackageDerivation
8690 :: PackageConfig
@@ -95,3 +99,13 @@ genericPackageDerivation conf pkg =
9599 (conf ^. pcFlagAssignment)
96100 []
97101 (pkgCabal pkg)
102+
103+-- Stackage packages set only consistent for packages with their library and
104+-- executable dependencies and completely ignores test dependencies.
105+overrideStackageDerivation :: Derivation -> Derivation
106+overrideStackageDerivation node = node
107+ & doCheck .~ False
108+ & runHaddock .~ False
109+
110+overrideStackageNode :: Node -> Node
111+overrideStackageNode = over nodeDerivation overrideStackageDerivation
src/Runner.hs+2−2
@@ -39,12 +39,12 @@ run = do
3939 out = PP.overrideHaskellPackages overrideConfig packages
4040 writeFile (opts ^. optOutDerivation) (show out)
4141 -- generate stackage packages
42− nodes <- traverse (uncurry $ buildNodeM packageSetConfig)
42+ nodes <- traverse (fmap overrideStackageNode . uncurry (buildNodeM packageSetConfig))
4343 $ Map.toList (bpPackages buildPlan)
4444 -- let nodes = reachableDependencies (mkNode <$> packages) allNodes
4545 withFile (opts ^. optOutStackagePackages) WriteMode $ \h -> do
4646 hPutStrLn h ("# Generated by stack2nix from " ++ S2n.optBuildPlanFile s2nOpts)
47− hPutStrLn h $ render $ pPrintOutPackages (nodeDerivation <$> nodes)
47+ hPutStrLn h $ render $ pPrintOutPackages (view nodeDerivation <$> nodes)
4848 withFile (opts ^. optOutStackageConfig) WriteMode $ \h -> do
4949 hPutStrLn h ("# Generated by stack2nix from " ++ S2n.optBuildPlanFile s2nOpts)
5050 hPutStrLn h $ render $ pPrintOutConfig (bpSystemInfo buildPlan) nodes
src/Runner/Cli.hs+12−11
@@ -29,17 +29,18 @@ data Options = Options
2929
3030makeLenses ''Options
3131
32−envStackYaml :: IO (Maybe FilePath)
33−envStackYaml = lookupEnv "STACK_YAML"
34−
35−optStackYaml :: Getter Options FilePath
36−optStackYaml = optStackYamlArg . to stackYamlFile
37− where
38− stackYamlFile p = case splitFileName p of
39− (dir, "") -> dir </> "stack.yaml"
40− (dir, ".") -> dir </> "stack.yaml"
41− (_ , "..") -> p </> "stack.yaml"
42− _ -> p
32+envStackYaml :: IO (Maybe StackYaml)
33+envStackYaml = fmap mkStackYaml <$> lookupEnv "STACK_YAML"
34+
35+optStackYaml :: Getter Options StackYaml
36+optStackYaml = optStackYamlArg . to mkStackYaml
37+
38+mkStackYaml :: FilePath -> StackYaml
39+mkStackYaml p = case splitFileName p of
40+ (dir, "") -> StackYaml dir "stack.yaml"
41+ (dir, ".") -> StackYaml dir "stack.yaml"
42+ (_ , "..") -> StackYaml p "stack.yaml"
43+ _ -> StackYaml "." p
4344
4445options :: Parser Options
4546options = Options
src/Stack/Config.hs+13−4
@@ -9,8 +9,11 @@ import Data.Coerce
99import Data.Maybe
1010import Data.Text as T
1111import Data.Yaml
12−import Stack.Config.Yaml as Yaml
1312import Network.URI
13+import Stack.Config.Yaml as Yaml
14+import Stack.Types
15+import System.FilePath
16+
1417
1518newtype StackResolver = StackResolver { fromStackResolver :: Text }
1619 deriving (Eq, Ord, Show)
@@ -78,6 +81,12 @@ fromYamlGit yg = RepoGit{..}
7881 _rgUri = yg ^. gGit
7982 _rgCommit = yg ^. gCommit
8083
81−readStackConfig :: FilePath -> IO (Either String StackConfig)
82−readStackConfig stackYaml =
83− second fromYamlConfig . decodeEither <$> BS.readFile stackYaml
84+readStackConfig :: StackYaml -> IO (Either String StackConfig)
85+readStackConfig stackYaml = do
86+ let
87+ relativeToStackYaml = \case
88+ StackFilePath p -> StackFilePath $ stackYaml ^. syDirName </> p
89+ packageLocation -> packageLocation
90+ mkStackConfig = over (scPackages . traversed . spLocation) relativeToStackYaml
91+ . fromYamlConfig
92+ second mkStackConfig . decodeEither <$> BS.readFile (stackYaml ^. syFilePath)
src/Stack/Types.hs+13
@@ -4,6 +4,19 @@ module Stack.Types where
44
55import Control.Lens
66import Data.Text as T
7+import System.FilePath
8+
9+
10+data StackYaml = StackYaml
11+ { _syDirName :: !FilePath
12+ , _syFileName :: !FilePath }
13+
14+makeLenses ''StackYaml
15+
16+syFilePath :: Getter StackYaml FilePath
17+syFilePath = to stackYamlPath
18+ where
19+ stackYamlPath sy = sy ^. syDirName </> sy ^. syFileName
720
821newtype CabalFlag = CabalFlag { fromCabalFlag :: Text }
922 deriving (Ord, Eq, Show)
stack.yaml+1−1
@@ -3,7 +3,7 @@ packages:
33- '.'
44- location:
55 git: https://github.com/4e6/cabal2nix.git
6− commit: e57728fbc5e81ff49225f257e08b970fb9088e48
6+ commit: 2a87207751b4f4949987c995c3962e142172312a
77 extra-dep: true
88extra-deps:
99- distribution-nixpkgs-1.1