git.iko.soy/typeable/stackage2nix
on master help sign in
Add flags to override Nix derivations
commite268fb7f6b78da11258d15cd9ea1c75e563906de authorDmitry Bushev <bushevdv@gmail.com> dateSun 25 Jun 2017, 18:59 (9 years ago) parent1bbc1b8
6 files changed+81−53
.gitignore−2 src/Distribution/Nixpkgs/Haskell/Stack.hs+27−40 src/Runner.hs+25−10 src/Runner/Cli.hs+28 stack.yaml+1−1 nix-test → stack2nix-test
.gitignore−2
@@ -1,3 +1 @@
11.stack-work
2−default.nix
3−/nix
src/Distribution/Nixpkgs/Haskell/Stack.hs+27−40
@@ -6,14 +6,13 @@ 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
109import Distribution.Nixpkgs.Haskell.PackageSourceSpec as PackageSourceSpec
1110import Distribution.PackageDescription as PackageDescription
1211import Distribution.System as System
13−import Language.Nix as Nix
1412import Network.URI as URI
1513import Stack.Config
1614
15+
1716newtype HackageDb = HackageDb { fromHackageDB :: T.Text }
1817 deriving (Eq, Ord, Show)
1918
@@ -22,24 +21,19 @@ makePrisms ''HackageDb
2221unHackageDb :: HackageDb -> String
2322unHackageDb = T.unpack . fromHackageDB
2423
25−data PackageConfig = PackageConfig
26− { _pcHaskellResolver :: !HaskellResolver
27− , _pcNixpkgsResolver :: !NixpkgsResolver
28− , _pcTargetPlatform :: !Platform
29− , _pcTargetCompiler :: !CompilerInfo
30− , _pcFlagAssignment :: !FlagAssignment
24+data StackPackagesConfig = StackPackagesConfig
25+ { _spcHaskellResolver :: !HaskellResolver
26+ , _spcNixpkgsResolver :: !NixpkgsResolver
27+ , _spcTargetPlatform :: !Platform
28+ , _spcTargetCompiler :: !CompilerInfo
29+ , _spcFlagAssignment :: !FlagAssignment
30+ , _spcDoCheckPackages :: !Bool
31+ , _spcDoHaddockPackages :: !Bool
32+ , _spcDoCheckStackage :: !Bool
33+ , _spcDoHaddockStackage :: !Bool
3134 }
3235
33−makeLenses ''PackageConfig
34−
35−mkPackageConfig :: Platform -> CompilerId -> PackageConfig
36−mkPackageConfig platform compilerId = PackageConfig
37− { _pcHaskellResolver = const True
38− , _pcNixpkgsResolver = \i -> Just (Nix.binding # (i, Nix.path # [i]))
39− , _pcTargetPlatform = platform
40− , _pcTargetCompiler = unknownCompilerInfo compilerId NoAbiTag
41− , _pcFlagAssignment = []
42− }
36+makeLenses ''StackPackagesConfig
4337
4438getStackPackageFromDb
4539 :: Maybe HackageDb
@@ -74,38 +68,31 @@ stackLocationToSource = \case
7468 , sourceCabalDir = mempty }
7569
7670packageDerivation
77− :: PackageConfig
71+ :: StackPackagesConfig
7872 -> Maybe HackageDb
7973 -> StackPackage
8074 -> IO Derivation
8175packageDerivation conf optHackageDb stackPackage = do
8276 pkg <- getStackPackageFromDb optHackageDb stackPackage
83− pure . overrideStackageDerivation
84− $ genericPackageDerivation conf pkg
85− & src .~ pkgSource pkg
86− & doCheck .~ False
87− & runHaddock .~ False
77+ let drv = genericPackageDerivation conf pkg & src .~ pkgSource pkg
78+ return $ if stackPackage ^. spExtraDep
79+ then drv
80+ & doCheck &&~ conf ^. spcDoCheckStackage
81+ & runHaddock &&~ conf ^. spcDoHaddockStackage
82+ else drv
83+ & doCheck &&~ conf ^. spcDoCheckPackages
84+ & runHaddock &&~ conf ^. spcDoHaddockPackages
8885
8986genericPackageDerivation
90− :: PackageConfig
87+ :: StackPackagesConfig
9188 -> Package
9289 -> Derivation
9390genericPackageDerivation conf pkg =
9491 FromCabal.fromGenericPackageDescription
95− (conf ^. pcHaskellResolver)
96− (conf ^. pcNixpkgsResolver)
97− (conf ^. pcTargetPlatform)
98− (conf ^. pcTargetCompiler)
99− (conf ^. pcFlagAssignment)
92+ (conf ^. spcHaskellResolver)
93+ (conf ^. spcNixpkgsResolver)
94+ (conf ^. spcTargetPlatform)
95+ (conf ^. spcTargetCompiler)
96+ (conf ^. spcFlagAssignment)
10097 []
10198 (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+25−10
@@ -7,12 +7,15 @@ import Distribution.Nixpkgs.Haskell.FromStack.Package
77import Distribution.Nixpkgs.Haskell.Stack
88import Distribution.Nixpkgs.Haskell.Stack.PrettyPrinting as PP
99import Distribution.Version (Version(..))
10−import System.FilePath as Path
10+import Distribution.Compiler (AbiTag(..), unknownCompilerInfo)
11+import Language.Nix as Nix
1112import Options.Applicative
1213import Runner.Cli
1314import Stack.Config
15+import Stack.Types
1416import Stackage.Types
15−import System.IO (withFile, IOMode(..), hPutStrLn)
17+import System.FilePath as Path
18+import System.IO (withFile, IOMode(..), hPutStrLn, hPrint)
1619import Text.PrettyPrint.HughesPJClass (render)
1720
1821import qualified Data.Map as Map
@@ -31,24 +34,33 @@ run = do
3134 (buildPlan, packageSetConfig) <- S2n.run s2nOpts
3235 -- generate haskell packages override
3336 let
34− pkgConfig = mkPackageConfig (opts ^. optPlatform) (opts ^. optCompilerId)
3537 overrideConfig = mkOverrideConfig opts (siGhcVersion $ bpSystemInfo buildPlan)
38+ pkgConfig = StackPackagesConfig
39+ { _spcHaskellResolver = const True
40+ , _spcNixpkgsResolver = \i -> Just (Nix.binding # (i, Nix.path # [i]))
41+ , _spcTargetPlatform = opts ^. optPlatform
42+ , _spcTargetCompiler = unknownCompilerInfo (opts ^. optCompilerId) NoAbiTag
43+ , _spcFlagAssignment = []
44+ , _spcDoCheckPackages = opts ^. optDoCheckPackages
45+ , _spcDoHaddockPackages = opts ^. optDoHaddockPackages
46+ , _spcDoCheckStackage = opts ^. optDoCheckStackage
47+ , _spcDoHaddockStackage = opts ^. optDoHaddockStackage
48+ }
3649 packages <- traverse (packageDerivation pkgConfig (opts ^. optHackageDb))
3750 $ stackConf ^. scPackages
38− let
39− out = PP.overrideHaskellPackages overrideConfig packages
40− writeFile (opts ^. optOutDerivation) (show out)
51+ let out = PP.overrideHaskellPackages overrideConfig packages
52+ withFile (opts ^. optOutDerivation) WriteMode $ \h -> do
53+ hPutStrLn h ("# Generated by stack2nix from " ++ stackYaml ^. syFilePath)
54+ hPrint h out
4155 -- generate stackage packages
42− nodes <- traverse (fmap overrideStackageNode . uncurry (buildNodeM packageSetConfig))
56+ nodes <- traverse (uncurry (buildNodeM packageSetConfig))
4357 $ Map.toList (bpPackages buildPlan)
44− -- let nodes = reachableDependencies (mkNode <$> packages) allNodes
4558 withFile (opts ^. optOutStackagePackages) WriteMode $ \h -> do
4659 hPutStrLn h ("# Generated by stack2nix from " ++ S2n.optBuildPlanFile s2nOpts)
4760 hPutStrLn h $ render $ pPrintOutPackages (view nodeDerivation <$> nodes)
4861 withFile (opts ^. optOutStackageConfig) WriteMode $ \h -> do
4962 hPutStrLn h ("# Generated by stack2nix from " ++ S2n.optBuildPlanFile s2nOpts)
5063 hPutStrLn h $ render $ pPrintOutConfig (bpSystemInfo buildPlan) nodes
51− putStrLn $ "Derivation was written to " ++ opts ^. optOutDerivation
5264
5365mkOverrideConfig :: Options -> Version -> OverrideConfig
5466mkOverrideConfig opts ghcVersion = OverrideConfig
@@ -66,4 +78,7 @@ mkS2nOptions conf opts = S2n.Options
6678 , S2n.optNixpkgsRepository = opts ^. optNixpkgsRepository
6779 , S2n.optNixpkgsMap = Nothing
6880 , S2n.optOutPackages = opts ^. optOutStackagePackages
69− , S2n.optOutConfig = opts ^. optOutStackageConfig }
81+ , S2n.optOutConfig = opts ^. optOutStackageConfig
82+ , S2n.optDoCheck = opts ^. optDoCheckStackage
83+ , S2n.optDoHaddock = opts ^. optDoHaddockStackage
84+ }
src/Runner/Cli.hs+28
@@ -20,6 +20,10 @@ data Options = Options
2020 , _optOutStackagePackages :: !FilePath
2121 , _optOutStackageConfig :: !FilePath
2222 , _optOutDerivation :: !FilePath
23+ , _optDoCheckPackages :: !Bool
24+ , _optDoHaddockPackages :: !Bool
25+ , _optDoCheckStackage :: !Bool
26+ , _optDoHaddockStackage :: !Bool
2327 , _optHackageDb :: !(Maybe HackageDb)
2428 , _optNixpkgsRepository :: !FilePath
2529 , _optCompilerId :: !CompilerId
@@ -49,6 +53,10 @@ options = Options
4953 <*> outStackagePackages
5054 <*> outStackageConfig
5155 <*> outDerivation
56+ <*> doCheckPackages
57+ <*> doHaddockPackages
58+ <*> doCheckStackage
59+ <*> doHaddockStackage
5260 <*> optional hackageDb
5361 <*> nixpkgsRepository
5462 <*> compilerId
@@ -106,6 +114,26 @@ outDerivation = option str
106114 <> value "default.nix"
107115 <> showDefaultWith id )
108116
117+doCheckPackages :: Parser Bool
118+doCheckPackages = flag True False
119+ ( long "no-check"
120+ <> help "disable tests for project packages")
121+
122+doHaddockPackages :: Parser Bool
123+doHaddockPackages = flag True False
124+ ( long "no-haddock"
125+ <> help "disable haddock for project packages")
126+
127+doCheckStackage :: Parser Bool
128+doCheckStackage = switch
129+ ( long "do-check-stackage"
130+ <> help "enable tests for Stackage packages" )
131+
132+doHaddockStackage :: Parser Bool
133+doHaddockStackage = switch
134+ ( long "do-haddock-stackage"
135+ <> help "enable haddock for Stackage packages" )
136+
109137stackYamlArg :: Parser FilePath
110138stackYamlArg = Opts.argument str
111139 ( metavar "STACK_YAML"
stack.yaml+1−1
@@ -3,7 +3,7 @@ packages:
33- '.'
44- location:
55 git: https://github.com/4e6/cabal2nix.git
6− commit: 2a87207751b4f4949987c995c3962e142172312a
6+ commit: d4f48bd655e523dcef2cc3860cf1ab171ae4a225
77 extra-dep: true
88extra-deps:
99- distribution-nixpkgs-1.1
nix-test → stack2nix-testrenamed

The content is the same.