git.iko.soy/typeable/stackage2nix
on master help sign in
Add flags to override Nix derivations
e268fb7Dmitry Bushev
.gitignore−2
@@ -1,3 +1 @@
1.stack-work
1.stack-work
2−default.nix
3−/nix
src/Distribution/Nixpkgs/Haskell/Stack.hs+27−40
@@ -6,14 +6,13 @@ import Distribution.Compiler as Compiler
6import Distribution.Nixpkgs.Fetch
6import Distribution.Nixpkgs.Fetch
7import Distribution.Nixpkgs.Haskell.Derivation
7import Distribution.Nixpkgs.Haskell.Derivation
8import Distribution.Nixpkgs.Haskell.FromCabal as FromCabal
8import Distribution.Nixpkgs.Haskell.FromCabal as FromCabal
9−import Distribution.Nixpkgs.Haskell.FromStack.Package as FromStack
10import Distribution.Nixpkgs.Haskell.PackageSourceSpec as PackageSourceSpec
9import Distribution.Nixpkgs.Haskell.PackageSourceSpec as PackageSourceSpec
11import Distribution.PackageDescription as PackageDescription
10import Distribution.PackageDescription as PackageDescription
12import Distribution.System as System
11import Distribution.System as System
13−import Language.Nix as Nix
14import Network.URI as URI
12import Network.URI as URI
15import Stack.Config
13import Stack.Config
16
14
15+
17newtype HackageDb = HackageDb { fromHackageDB :: T.Text }
16newtype HackageDb = HackageDb { fromHackageDB :: T.Text }
18 deriving (Eq, Ord, Show)
17 deriving (Eq, Ord, Show)
19
18
@@ -22,24 +21,19 @@ makePrisms ''HackageDb
22unHackageDb :: HackageDb -> String
21unHackageDb :: HackageDb -> String
23unHackageDb = T.unpack . fromHackageDB
22unHackageDb = T.unpack . fromHackageDB
24
23
25−data PackageConfig = PackageConfig
24+data StackPackagesConfig = StackPackagesConfig
26− { _pcHaskellResolver :: !HaskellResolver
25+ { _spcHaskellResolver :: !HaskellResolver
27− , _pcNixpkgsResolver :: !NixpkgsResolver
26+ , _spcNixpkgsResolver :: !NixpkgsResolver
28− , _pcTargetPlatform :: !Platform
27+ , _spcTargetPlatform :: !Platform
29− , _pcTargetCompiler :: !CompilerInfo
28+ , _spcTargetCompiler :: !CompilerInfo
30− , _pcFlagAssignment :: !FlagAssignment
29+ , _spcFlagAssignment :: !FlagAssignment
30+ , _spcDoCheckPackages :: !Bool
31+ , _spcDoHaddockPackages :: !Bool
32+ , _spcDoCheckStackage :: !Bool
33+ , _spcDoHaddockStackage :: !Bool
31 }
34 }
32
35
33−makeLenses ''PackageConfig
36+makeLenses ''StackPackagesConfig
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− }
43
37
44getStackPackageFromDb
38getStackPackageFromDb
45 :: Maybe HackageDb
39 :: Maybe HackageDb
@@ -74,38 +68,31 @@ stackLocationToSource = \case
74 , sourceCabalDir = mempty }
68 , sourceCabalDir = mempty }
75
69
76packageDerivation
70packageDerivation
77− :: PackageConfig
71+ :: StackPackagesConfig
78 -> Maybe HackageDb
72 -> Maybe HackageDb
79 -> StackPackage
73 -> StackPackage
80 -> IO Derivation
74 -> IO Derivation
81packageDerivation conf optHackageDb stackPackage = do
75packageDerivation conf optHackageDb stackPackage = do
82 pkg <- getStackPackageFromDb optHackageDb stackPackage
76 pkg <- getStackPackageFromDb optHackageDb stackPackage
83− pure . overrideStackageDerivation
84− $ genericPackageDerivation conf pkg
77+ let drv = genericPackageDerivation conf pkg & src .~ pkgSource pkg
85− & src .~ pkgSource pkg
78+ return $ if stackPackage ^. spExtraDep
86− & doCheck .~ False
79+ then drv
80+ & doCheck &&~ conf ^. spcDoCheckStackage
81+ & runHaddock &&~ conf ^. spcDoHaddockStackage
82+ else drv
83+ & doCheck &&~ conf ^. spcDoCheckPackages
87− & runHaddock .~ False
84+ & runHaddock &&~ conf ^. spcDoHaddockPackages
88
85
89genericPackageDerivation
86genericPackageDerivation
90− :: PackageConfig
87+ :: StackPackagesConfig
91 -> Package
88 -> Package
92 -> Derivation
89 -> Derivation
93genericPackageDerivation conf pkg =
90genericPackageDerivation conf pkg =
94 FromCabal.fromGenericPackageDescription
91 FromCabal.fromGenericPackageDescription
95− (conf ^. pcHaskellResolver)
92+ (conf ^. spcHaskellResolver)
96− (conf ^. pcNixpkgsResolver)
93+ (conf ^. spcNixpkgsResolver)
97− (conf ^. pcTargetPlatform)
94+ (conf ^. spcTargetPlatform)
98− (conf ^. pcTargetCompiler)
95+ (conf ^. spcTargetCompiler)
99− (conf ^. pcFlagAssignment)
96+ (conf ^. spcFlagAssignment)
100 []
97 []
101 (pkgCabal pkg)
98 (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
7import Distribution.Nixpkgs.Haskell.Stack
7import Distribution.Nixpkgs.Haskell.Stack
8import Distribution.Nixpkgs.Haskell.Stack.PrettyPrinting as PP
8import Distribution.Nixpkgs.Haskell.Stack.PrettyPrinting as PP
9import Distribution.Version (Version(..))
9import Distribution.Version (Version(..))
10−import System.FilePath as Path
10+import Distribution.Compiler (AbiTag(..), unknownCompilerInfo)
11+import Language.Nix as Nix
11import Options.Applicative
12import Options.Applicative
12import Runner.Cli
13import Runner.Cli
13import Stack.Config
14import Stack.Config
15+import Stack.Types
14import Stackage.Types
16import Stackage.Types
17+import System.FilePath as Path
15−import System.IO (withFile, IOMode(..), hPutStrLn)
18+import System.IO (withFile, IOMode(..), hPutStrLn, hPrint)
16import Text.PrettyPrint.HughesPJClass (render)
19import Text.PrettyPrint.HughesPJClass (render)
17
20
18import qualified Data.Map as Map
21import qualified Data.Map as Map
@@ -31,24 +34,33 @@ run = do
31 (buildPlan, packageSetConfig) <- S2n.run s2nOpts
34 (buildPlan, packageSetConfig) <- S2n.run s2nOpts
32 -- generate haskell packages override
35 -- generate haskell packages override
33 let
36 let
34− pkgConfig = mkPackageConfig (opts ^. optPlatform) (opts ^. optCompilerId)
35 overrideConfig = mkOverrideConfig opts (siGhcVersion $ bpSystemInfo buildPlan)
37 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+ }
36 packages <- traverse (packageDerivation pkgConfig (opts ^. optHackageDb))
49 packages <- traverse (packageDerivation pkgConfig (opts ^. optHackageDb))
37 $ stackConf ^. scPackages
50 $ stackConf ^. scPackages
38− let
39− out = PP.overrideHaskellPackages overrideConfig packages
51+ let out = PP.overrideHaskellPackages overrideConfig packages
40− writeFile (opts ^. optOutDerivation) (show out)
52+ withFile (opts ^. optOutDerivation) WriteMode $ \h -> do
53+ hPutStrLn h ("# Generated by stack2nix from " ++ stackYaml ^. syFilePath)
54+ hPrint h out
41 -- generate stackage packages
55 -- generate stackage packages
42− nodes <- traverse (fmap overrideStackageNode . uncurry (buildNodeM packageSetConfig))
56+ nodes <- traverse (uncurry (buildNodeM packageSetConfig))
43 $ Map.toList (bpPackages buildPlan)
57 $ Map.toList (bpPackages buildPlan)
44− -- let nodes = reachableDependencies (mkNode <$> packages) allNodes
45 withFile (opts ^. optOutStackagePackages) WriteMode $ \h -> do
58 withFile (opts ^. optOutStackagePackages) WriteMode $ \h -> do
46 hPutStrLn h ("# Generated by stack2nix from " ++ S2n.optBuildPlanFile s2nOpts)
59 hPutStrLn h ("# Generated by stack2nix from " ++ S2n.optBuildPlanFile s2nOpts)
47 hPutStrLn h $ render $ pPrintOutPackages (view nodeDerivation <$> nodes)
60 hPutStrLn h $ render $ pPrintOutPackages (view nodeDerivation <$> nodes)
48 withFile (opts ^. optOutStackageConfig) WriteMode $ \h -> do
61 withFile (opts ^. optOutStackageConfig) WriteMode $ \h -> do
49 hPutStrLn h ("# Generated by stack2nix from " ++ S2n.optBuildPlanFile s2nOpts)
62 hPutStrLn h ("# Generated by stack2nix from " ++ S2n.optBuildPlanFile s2nOpts)
50 hPutStrLn h $ render $ pPrintOutConfig (bpSystemInfo buildPlan) nodes
63 hPutStrLn h $ render $ pPrintOutConfig (bpSystemInfo buildPlan) nodes
51− putStrLn $ "Derivation was written to " ++ opts ^. optOutDerivation
52
64
53mkOverrideConfig :: Options -> Version -> OverrideConfig
65mkOverrideConfig :: Options -> Version -> OverrideConfig
54mkOverrideConfig opts ghcVersion = OverrideConfig
66mkOverrideConfig opts ghcVersion = OverrideConfig
@@ -66,4 +78,7 @@ mkS2nOptions conf opts = S2n.Options
66 , S2n.optNixpkgsRepository = opts ^. optNixpkgsRepository
78 , S2n.optNixpkgsRepository = opts ^. optNixpkgsRepository
67 , S2n.optNixpkgsMap = Nothing
79 , S2n.optNixpkgsMap = Nothing
68 , S2n.optOutPackages = opts ^. optOutStackagePackages
80 , 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
20 , _optOutStackagePackages :: !FilePath
20 , _optOutStackagePackages :: !FilePath
21 , _optOutStackageConfig :: !FilePath
21 , _optOutStackageConfig :: !FilePath
22 , _optOutDerivation :: !FilePath
22 , _optOutDerivation :: !FilePath
23+ , _optDoCheckPackages :: !Bool
24+ , _optDoHaddockPackages :: !Bool
25+ , _optDoCheckStackage :: !Bool
26+ , _optDoHaddockStackage :: !Bool
23 , _optHackageDb :: !(Maybe HackageDb)
27 , _optHackageDb :: !(Maybe HackageDb)
24 , _optNixpkgsRepository :: !FilePath
28 , _optNixpkgsRepository :: !FilePath
25 , _optCompilerId :: !CompilerId
29 , _optCompilerId :: !CompilerId
@@ -49,6 +53,10 @@ options = Options
49 <*> outStackagePackages
53 <*> outStackagePackages
50 <*> outStackageConfig
54 <*> outStackageConfig
51 <*> outDerivation
55 <*> outDerivation
56+ <*> doCheckPackages
57+ <*> doHaddockPackages
58+ <*> doCheckStackage
59+ <*> doHaddockStackage
52 <*> optional hackageDb
60 <*> optional hackageDb
53 <*> nixpkgsRepository
61 <*> nixpkgsRepository
54 <*> compilerId
62 <*> compilerId
@@ -106,6 +114,26 @@ outDerivation = option str
106 <> value "default.nix"
114 <> value "default.nix"
107 <> showDefaultWith id )
115 <> showDefaultWith id )
108
116
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+
109stackYamlArg :: Parser FilePath
137stackYamlArg :: Parser FilePath
110stackYamlArg = Opts.argument str
138stackYamlArg = Opts.argument str
111 ( metavar "STACK_YAML"
139 ( metavar "STACK_YAML"
stack.yaml+1−1
@@ -3,7 +3,7 @@ packages:
3- '.'
3- '.'
4- location:
4- location:
5 git: https://github.com/4e6/cabal2nix.git
5 git: https://github.com/4e6/cabal2nix.git
6− commit: 2a87207751b4f4949987c995c3962e142172312a
6+ commit: d4f48bd655e523dcef2cc3860cf1ab171ae4a225
7 extra-dep: true
7 extra-dep: true
8extra-deps:
8extra-deps:
9- distribution-nixpkgs-1.1
9- distribution-nixpkgs-1.1
nix-test → stack2nix-testrenamed

The content is the same.