git.iko.soy/typeable/cabal2nix
on master help sign in
Moved hpack logic from Derivation
d3a536bTom Smalley
src/Cabal2nix.hs+8−2
@@ -17,6 +17,7 @@ import Distribution.Compiler
17import Distribution.Nixpkgs.Fetch
17import Distribution.Nixpkgs.Fetch
18import Distribution.Nixpkgs.Haskell
18import Distribution.Nixpkgs.Haskell
19import Distribution.Nixpkgs.Haskell.FromCabal
19import Distribution.Nixpkgs.Haskell.FromCabal
20+import qualified Distribution.Nixpkgs.Haskell.FromCabal.PostProcess as PP (pkg)
20import Distribution.Nixpkgs.Haskell.PackageSourceSpec
21import Distribution.Nixpkgs.Haskell.PackageSourceSpec
21import Distribution.Nixpkgs.Meta
22import Distribution.Nixpkgs.Meta
22import Distribution.PackageDescription ( mkFlagName, FlagAssignment )
23import Distribution.PackageDescription ( mkFlagName, FlagAssignment )
@@ -120,6 +121,10 @@ main :: IO ()
120main = bracket (return ()) (\() -> hFlush stdout >> hFlush stderr) $ \() ->
121main = bracket (return ()) (\() -> hFlush stdout >> hFlush stderr) $ \() ->
121 cabal2nix =<< getArgs
122 cabal2nix =<< getArgs
122
123
124+hpackOverrides :: Derivation -> Derivation
125+hpackOverrides = over phaseOverrides (++ "preConfigure = \"${hpack}/bin/hpack;\";")
126+ . set (libraryDepends . pkgconfig . contains (PP.pkg "hpack")) True
127+
123cabal2nix' :: [String] -> IO (Either Doc Derivation)
128cabal2nix' :: [String] -> IO (Either Doc Derivation)
124cabal2nix' args = do
129cabal2nix' args = do
125 Options {..} <- handleParseResult $ execParserPure defaultPrefs pinfo args
130 Options {..} <- handleParseResult $ execParserPure defaultPrefs pinfo args
@@ -127,8 +132,10 @@ cabal2nix' args = do
127 pkg <- getPackage optHpack optHackageDb $ Source optUrl (fromMaybe "" optRevision) (maybe UnknownHash Guess optSha256) (fromMaybe "" optSubpath)
132 pkg <- getPackage optHpack optHackageDb $ Source optUrl (fromMaybe "" optRevision) (maybe UnknownHash Guess optSha256) (fromMaybe "" optSubpath)
128
133
129 let
134 let
135+ withHpackOverrides :: Derivation -> Derivation
136+ withHpackOverrides = if pkgRanHpack pkg then hpackOverrides else id
130 deriv :: Derivation
137 deriv :: Derivation
131− deriv = fromGenericPackageDescription (const True)
138+ deriv = withHpackOverrides $ fromGenericPackageDescription (const True)
132 (\i -> Just (binding # (i, path # [i])))
139 (\i -> Just (binding # (i, path # [i])))
133 optSystem
140 optSystem
134 (unknownCompilerInfo optCompiler NoAbiTag)
141 (unknownCompilerInfo optCompiler NoAbiTag)
@@ -138,7 +145,6 @@ cabal2nix' args = do
138 & src .~ pkgSource pkg
145 & src .~ pkgSource pkg
139 & subpath .~ (fromMaybe "." optSubpath)
146 & subpath .~ (fromMaybe "." optSubpath)
140 & runHaddock .~ optHaddock
147 & runHaddock .~ optHaddock
141− & runHpack .~ pkgRanHpack pkg
142 & jailbreak .~ optJailbreak
148 & jailbreak .~ optJailbreak
143 & hyperlinkSource .~ optHyperlinkSource
149 & hyperlinkSource .~ optHyperlinkSource
144 & enableLibraryProfiling .~ (fromMaybe False optEnableProfiling || optEnableLibraryProfiling)
150 & enableLibraryProfiling .~ (fromMaybe False optEnableProfiling || optEnableLibraryProfiling)
src/Distribution/Nixpkgs/Haskell/Derivation.hs+1−5
@@ -6,7 +6,7 @@
6module Distribution.Nixpkgs.Haskell.Derivation
6module Distribution.Nixpkgs.Haskell.Derivation
7 ( Derivation, nullDerivation, pkgid, revision, src, subpath, isLibrary, isExecutable
7 ( Derivation, nullDerivation, pkgid, revision, src, subpath, isLibrary, isExecutable
8 , extraFunctionArgs, libraryDepends, executableDepends, testDepends, configureFlags
8 , extraFunctionArgs, libraryDepends, executableDepends, testDepends, configureFlags
9− , cabalFlags, runHaddock, runHpack, jailbreak, doCheck, testTarget, hyperlinkSource, enableSplitObjs
9+ , cabalFlags, runHaddock, jailbreak, doCheck, testTarget, hyperlinkSource, enableSplitObjs
10 , enableLibraryProfiling, enableExecutableProfiling, phaseOverrides, editedCabalFile, metaSection
10 , enableLibraryProfiling, enableExecutableProfiling, phaseOverrides, editedCabalFile, metaSection
11 , dependencies, setupDepends, benchmarkDepends, enableSeparateDataOutput
11 , dependencies, setupDepends, benchmarkDepends, enableSeparateDataOutput
12 )
12 )
@@ -59,7 +59,6 @@ data Derivation = MkDerivation
59 , _editedCabalFile :: String
59 , _editedCabalFile :: String
60 , _enableSeparateDataOutput :: Bool
60 , _enableSeparateDataOutput :: Bool
61 , _metaSection :: Meta
61 , _metaSection :: Meta
62− , _runHpack :: Bool
63 }
62 }
64 deriving (Show, Eq, Generic)
63 deriving (Show, Eq, Generic)
65
64
@@ -91,7 +90,6 @@ nullDerivation = MkDerivation
91 , _editedCabalFile = error "undefined Derivation.editedCabalFile"
90 , _editedCabalFile = error "undefined Derivation.editedCabalFile"
92 , _enableSeparateDataOutput = error "undefined Derivation.enableSeparateDataOutput"
91 , _enableSeparateDataOutput = error "undefined Derivation.enableSeparateDataOutput"
93 , _metaSection = error "undefined Derivation.metaSection"
92 , _metaSection = error "undefined Derivation.metaSection"
94− , _runHpack = error "undefined Derivation.runHpack"
95 }
93 }
96
94
97makeLenses ''Derivation
95makeLenses ''Derivation
@@ -132,7 +130,6 @@ instance Pretty Derivation where
132 , boolattr "hyperlinkSource" (not _hyperlinkSource) _hyperlinkSource
130 , boolattr "hyperlinkSource" (not _hyperlinkSource) _hyperlinkSource
133 , onlyIf (not (null _phaseOverrides)) $ vcat ((map text . lines) _phaseOverrides)
131 , onlyIf (not (null _phaseOverrides)) $ vcat ((map text . lines) _phaseOverrides)
134 , pPrint _metaSection
132 , pPrint _metaSection
135− , onlyIf _runHpack $ attr "preConfigure" $ string "${hpack}/bin/hpack"
136 ]
133 ]
137 , rbrace
134 , rbrace
138 ]
135 ]
@@ -141,7 +138,6 @@ instance Pretty Derivation where
141 inputs = Set.unions [ Set.map (view (localName . ident)) _extraFunctionArgs
138 inputs = Set.unions [ Set.map (view (localName . ident)) _extraFunctionArgs
142 , setOf (dependencies . each . folded . localName . ident) drv
139 , setOf (dependencies . each . folded . localName . ident) drv
143 , Set.fromList ["fetch" ++ derivKind _src | derivKind _src /= "" && not isHackagePackage]
140 , Set.fromList ["fetch" ++ derivKind _src | derivKind _src /= "" && not isHackagePackage]
144− , if _runHpack then Set.singleton "hpack" else Set.empty
145 ]
141 ]
146
142
147 renderedFlags = [ text "-f" <> (if enable then empty else char '-') <> text (unFlagName f) | (f, enable) <- _cabalFlags ]
143 renderedFlags = [ text "-f" <> (if enable then empty else char '-') <> text (unFlagName f) | (f, enable) <- _cabalFlags ]
src/Distribution/Nixpkgs/Haskell/FromCabal.hs+1−2
@@ -17,7 +17,7 @@ import Distribution.Nixpkgs.Haskell.Constraint
17import Distribution.Nixpkgs.Haskell.FromCabal.License
17import Distribution.Nixpkgs.Haskell.FromCabal.License
18import Distribution.Nixpkgs.Haskell.FromCabal.Name
18import Distribution.Nixpkgs.Haskell.FromCabal.Name
19import Distribution.Nixpkgs.Haskell.FromCabal.Normalize
19import Distribution.Nixpkgs.Haskell.FromCabal.Normalize
20−import Distribution.Nixpkgs.Haskell.FromCabal.PostProcess
20+import Distribution.Nixpkgs.Haskell.FromCabal.PostProcess (postProcess)
21import qualified Distribution.Nixpkgs.Meta as Nix
21import qualified Distribution.Nixpkgs.Meta as Nix
22import Distribution.Package
22import Distribution.Package
23import Distribution.PackageDescription
23import Distribution.PackageDescription
@@ -79,7 +79,6 @@ fromPackageDescription haskellResolver nixpkgsResolver missingDeps flags (Packag
79 & configureFlags .~ mempty
79 & configureFlags .~ mempty
80 & cabalFlags .~ flags
80 & cabalFlags .~ flags
81 & runHaddock .~ maybe True (not . null . exposedModules) library
81 & runHaddock .~ maybe True (not . null . exposedModules) library
82− & runHpack .~ False
83 & jailbreak .~ False
82 & jailbreak .~ False
84 & doCheck .~ True
83 & doCheck .~ True
85 & testTarget .~ mempty
84 & testTarget .~ mempty
src/Distribution/Nixpkgs/Haskell/FromCabal/PostProcess.hs+1−1
@@ -1,6 +1,6 @@
1{-# LANGUAGE OverloadedStrings #-}
1{-# LANGUAGE OverloadedStrings #-}
2
2
3−module Distribution.Nixpkgs.Haskell.FromCabal.PostProcess ( postProcess ) where
3+module Distribution.Nixpkgs.Haskell.FromCabal.PostProcess ( postProcess, pkg ) where
4
4
5import Control.Lens
5import Control.Lens
6import Data.List.Split
6import Data.List.Split