git.iko.soy/typeable/cabal2nix
on master help sign in
Commit to Cabal 3.x.
5efdfe0Peter Simons
cabal2nix.cabal+2−2
@@ -1,5 +1,5 @@
1name: cabal2nix
1name: cabal2nix
2−version: 2.14.4
2+version: 2.15.0
3synopsis: Convert Cabal files into Nix build instructions.
3synopsis: Convert Cabal files into Nix build instructions.
4description:
4description:
5 Convert Cabal files into Nix build instructions. Users of Nix can install the latest
5 Convert Cabal files into Nix build instructions. Users of Nix can install the latest
@@ -108,7 +108,7 @@ library
108 other-modules: Paths_cabal2nix
108 other-modules: Paths_cabal2nix
109 hs-source-dirs: src
109 hs-source-dirs: src
110 build-depends: base > 4.11
110 build-depends: base > 4.11
111− , Cabal > 2.4
111+ , Cabal > 3
112 , aeson > 1
112 , aeson > 1
113 , ansi-wl-pprint
113 , ansi-wl-pprint
114 , bytestring
114 , bytestring
hackage2nix/Main.hs+8−7
@@ -23,6 +23,7 @@ import Distribution.Nixpkgs.Haskell.Constraint
23import Distribution.Nixpkgs.Haskell.FromCabal
23import Distribution.Nixpkgs.Haskell.FromCabal
24import Distribution.Nixpkgs.Haskell.FromCabal.Configuration as Config
24import Distribution.Nixpkgs.Haskell.FromCabal.Configuration as Config
25import Distribution.Nixpkgs.Haskell.FromCabal.Flags
25import Distribution.Nixpkgs.Haskell.FromCabal.Flags
26+import Distribution.Nixpkgs.Haskell.OrphanInstances ( )
26import Distribution.Nixpkgs.Meta
27import Distribution.Nixpkgs.Meta
27import Distribution.Nixpkgs.PackageMap
28import Distribution.Nixpkgs.PackageMap
28import Distribution.Package
29import Distribution.Package
@@ -62,7 +63,7 @@ main = do
62 pinfo :: ParserInfo CLI
63 pinfo :: ParserInfo CLI
63 pinfo = info
64 pinfo = info
64 ( helper
65 ( helper
65− <*> infoOption ("hackage2nix " ++ display Main.version) (long "version" <> help "Show version number")
66+ <*> infoOption ("hackage2nix " ++ prettyShow Main.version) (long "version" <> help "Show version number")
66 <*> cliOptions
67 <*> cliOptions
67 )
68 )
68 ( fullDesc
69 ( fullDesc
@@ -92,7 +93,7 @@ main = do
92 latestVersionSet = Map.map Set.findMax (Map.filter (not . Set.null) (Map.mapWithKey (enforcePreferredVersions preferredVersions) hackage))
93 latestVersionSet = Map.map Set.findMax (Map.filter (not . Set.null) (Map.mapWithKey (enforcePreferredVersions preferredVersions) hackage))
93
94
94 defaultPackageOverridesSet :: PackageSet
95 defaultPackageOverridesSet :: PackageSet
95− defaultPackageOverridesSet = Map.fromList [ (name, resolveConstraint c hackage) | c@(Dependency name _) <- defaultPackageOverrides config ]
96+ defaultPackageOverridesSet = Map.fromList [ (name, resolveConstraint c hackage) | c@(Dependency name _ _) <- defaultPackageOverrides config ]
96
97
97 generatedDefaultPackageSet :: PackageSet
98 generatedDefaultPackageSet :: PackageSet
98 generatedDefaultPackageSet = (defaultPackageOverridesSet `Map.union` latestVersionSet) `Map.difference` corePackageSet
99 generatedDefaultPackageSet = (defaultPackageOverridesSet `Map.union` latestVersionSet) `Map.difference` corePackageSet
@@ -105,7 +106,7 @@ main = do
105
106
106 extraPackageSet :: PackageMultiSet
107 extraPackageSet :: PackageMultiSet
107 extraPackageSet = Map.unionsWith Set.union
108 extraPackageSet = Map.unionsWith Set.union
108− [ Map.singleton name (Set.singleton (resolveConstraint c hackage)) | c@(Dependency name _) <- extraPackages config ]
109+ [ Map.singleton name (Set.singleton (resolveConstraint c hackage)) | c@(Dependency name _ _) <- extraPackages config ]
109
110
110 db :: PackageMultiSet
111 db :: PackageMultiSet
111 db = Map.unionsWith Set.union [ Map.map Set.singleton generatedDefaultPackageSet
112 db = Map.unionsWith Set.union [ Map.map Set.singleton generatedDefaultPackageSet
@@ -115,7 +116,7 @@ main = do
115 ]
116 ]
116
117
117 haskellResolver :: Dependency -> Bool
118 haskellResolver :: Dependency -> Bool
118− haskellResolver (Dependency name vrange)
119+ haskellResolver (Dependency name vrange _)
119 | Just v <- Map.lookup name corePackageSet = v `withinRange` vrange
120 | Just v <- Map.lookup name corePackageSet = v `withinRange` vrange
120 | Just v <- Map.lookup name generatedDefaultPackageSet = v `withinRange` vrange
121 | Just v <- Map.lookup name generatedDefaultPackageSet = v `withinRange` vrange
121 | otherwise = False
122 | otherwise = False
@@ -137,7 +138,7 @@ main = do
137 let isInDefaultPackageSet, isHydraEnabled, isBroken :: Bool
138 let isInDefaultPackageSet, isHydraEnabled, isBroken :: Bool
138 isInDefaultPackageSet = (== Just v) (Map.lookup name generatedDefaultPackageSet)
139 isInDefaultPackageSet = (== Just v) (Map.lookup name generatedDefaultPackageSet)
139 isHydraEnabled = isInDefaultPackageSet && not (isBroken || name `Set.member` dontDistributePackages config)
140 isHydraEnabled = isInDefaultPackageSet && not (isBroken || name `Set.member` dontDistributePackages config)
140− isBroken = any (withinRange v) [ vr | Dependency pn vr <- brokenPackages config, pn == name ]
141+ isBroken = any (withinRange v) [ vr | Dependency pn vr _ <- brokenPackages config, pn == name ]
141
142
142 droppedPlatforms :: Set Platform
143 droppedPlatforms :: Set Platform
143 droppedPlatforms = Map.findWithDefault mempty name (unsupportedPlatforms config)
144 droppedPlatforms = Map.findWithDefault mempty name (unsupportedPlatforms config)
@@ -164,7 +165,7 @@ main = do
164 & metaSection.homepage .~ ""
165 & metaSection.homepage .~ ""
165
166
166 overrides :: Doc
167 overrides :: Doc
167− overrides = fcat $ punctuate space [ disp b <> semi | b <- Set.toList (view (dependencies . each) drv `Set.union` view extraFunctionArgs drv), not (isFromHackage b) ]
168+ overrides = fcat $ punctuate space [ pPrint b <> semi | b <- Set.toList (view (dependencies . each) drv `Set.union` view extraFunctionArgs drv), not (isFromHackage b) ]
168 return $ render $ nest 2 $
169 return $ render $ nest 2 $
169 hang (doubleQuotes (text attr) <+> equals <+> text "callPackage") 2 (parens (pPrint drv)) <+> (braces overrides <> semi)
170 hang (doubleQuotes (text attr) <+> equals <+> text "callPackage") 2 (parens (pPrint drv)) <+> (braces overrides <> semi)
170
171
@@ -204,7 +205,7 @@ resolveConstraint c = fromMaybe (error msg) . resolveConstraint' c
204 ]
205 ]
205
206
206resolveConstraint' :: Constraint -> Hackage -> Maybe Version
207resolveConstraint' :: Constraint -> Hackage -> Maybe Version
207−resolveConstraint' (Dependency name vrange) hackage
208+resolveConstraint' (Dependency name vrange _) hackage
208 | Just vset' <- Map.lookup name hackage
209 | Just vset' <- Map.lookup name hackage
209 , vset <- Set.filter (`withinRange` vrange) vset'
210 , vset <- Set.filter (`withinRange` vrange) vset'
210 , not (Set.null vset) = Just (Set.findMax vset)
211 , not (Set.null vset) = Just (Set.findMax vset)
src/Cabal2nix.hs+8−10
@@ -18,7 +18,6 @@ import Data.Monoid ( (<>) )
18import qualified Data.Set as Set
18import qualified Data.Set as Set
19import Data.String
19import Data.String
20import Data.Time
20import Data.Time
21−import qualified Distribution.Compat.ReadP as P
22import Distribution.Compiler
21import Distribution.Compiler
23import Distribution.Nixpkgs.Fetch
22import Distribution.Nixpkgs.Fetch
24import Distribution.Nixpkgs.Haskell
23import Distribution.Nixpkgs.Haskell
@@ -26,13 +25,14 @@ import Distribution.Nixpkgs.Haskell.FromCabal
26import Distribution.Nixpkgs.Haskell.FromCabal.Flags
25import Distribution.Nixpkgs.Haskell.FromCabal.Flags
27import qualified Distribution.Nixpkgs.Haskell.FromCabal.PostProcess as PP (pkg)
26import qualified Distribution.Nixpkgs.Haskell.FromCabal.PostProcess as PP (pkg)
28import qualified Distribution.Nixpkgs.Haskell.Hackage as DB
27import qualified Distribution.Nixpkgs.Haskell.Hackage as DB
28+import Distribution.Nixpkgs.Haskell.OrphanInstances ( )
29import Distribution.Nixpkgs.Haskell.PackageSourceSpec
29import Distribution.Nixpkgs.Haskell.PackageSourceSpec
30import Distribution.Nixpkgs.Meta
30import Distribution.Nixpkgs.Meta
31−import Distribution.PackageDescription ( mkFlagName, mkFlagAssignment, FlagAssignment )
32import Distribution.Package ( packageId )
31import Distribution.Package ( packageId )
32+import Distribution.PackageDescription ( mkFlagName, mkFlagAssignment, FlagAssignment )
33+import Distribution.Parsec as P
33import Distribution.Simple.Utils ( lowercase )
34import Distribution.Simple.Utils ( lowercase )
34import Distribution.System
35import Distribution.System
35−import Distribution.Text
36import Language.Nix
36import Language.Nix
37import Options.Applicative
37import Options.Applicative
38import Paths_cabal2nix ( version )
38import Paths_cabal2nix ( version )
@@ -94,8 +94,8 @@ options = Options
94 <*> optional (strOption $ long "hackage-db" <> metavar "PATH" <> help "path to the local hackage db in tar format")
94 <*> optional (strOption $ long "hackage-db" <> metavar "PATH" <> help "path to the local hackage db in tar format")
95 <*> switch (long "shell" <> help "generate output suitable for nix-shell")
95 <*> switch (long "shell" <> help "generate output suitable for nix-shell")
96 <*> many (strOption $ short 'f' <> long "flag" <> help "Cabal flag (may be specified multiple times)")
96 <*> many (strOption $ short 'f' <> long "flag" <> help "Cabal flag (may be specified multiple times)")
97− <*> option (readP parse) (long "compiler" <> help "compiler to use when evaluating the Cabal file" <> value buildCompilerId <> showDefaultWith display)
97+ <*> option parseCabal (long "compiler" <> help "compiler to use when evaluating the Cabal file" <> value buildCompilerId <> showDefaultWith prettyShow)
98− <*> option (maybeReader parsePlatform) (long "system" <> help "host system (in either short Nix format or full LLVM style) to use when evaluating the Cabal file" <> value buildPlatform <> showDefaultWith display)
98+ <*> option (maybeReader parsePlatform) (long "system" <> help "host system (in either short Nix format or full LLVM style) to use when evaluating the Cabal file" <> value buildPlatform <> showDefaultWith prettyShow)
99 <*> optional (strOption $ long "subpath" <> metavar "PATH" <> help "Path to Cabal file's directory relative to the URI (default is root directory)")
99 <*> optional (strOption $ long "subpath" <> metavar "PATH" <> help "Path to Cabal file's directory relative to the URI (default is root directory)")
100 <*> optional (option utcTimeReader (long "hackage-snapshot" <> help "hackage snapshot time, ISO format"))
100 <*> optional (option utcTimeReader (long "hackage-snapshot" <> help "hackage snapshot time, ISO format"))
101 <*> pure (\i -> Just (binding # (i, path # [ident # "pkgs", i])))
101 <*> pure (\i -> Just (binding # (i, path # [ident # "pkgs", i])))
@@ -110,10 +110,8 @@ utcTimeReader = eitherReader $ \arg ->
110 Nothing -> Left $ "Cannot parse date, ISO format used ('2017-11-20T12:18:35Z'): " ++ arg
110 Nothing -> Left $ "Cannot parse date, ISO format used ('2017-11-20T12:18:35Z'): " ++ arg
111 Just utcTime -> Right utcTime
111 Just utcTime -> Right utcTime
112
112
113−readP :: P.ReadP a a -> ReadM a
113+parseCabal :: Parsec a => ReadM a
114−readP p = eitherReader $ \s -> case [ r' | (r',"") <- P.readP_to_S p s ] of
114+parseCabal = eitherReader eitherParsec
115− (r:_) -> Right r
116− _ -> Left ("invalid value " ++ show s)
117
115
118-- | Replicate the normalization performed by GHC_CONVERT_CPU in GHC's aclocal.m4
116-- | Replicate the normalization performed by GHC_CONVERT_CPU in GHC's aclocal.m4
119-- since the output of that is what Cabal parses.
117-- since the output of that is what Cabal parses.
@@ -164,7 +162,7 @@ parsePlatformParts = \case
164pinfo :: ParserInfo Options
162pinfo :: ParserInfo Options
165pinfo = info
163pinfo = info
166 ( helper
164 ( helper
167− <*> infoOption ("cabal2nix " ++ display version) (long "version" <> help "Show version number")
165+ <*> infoOption ("cabal2nix " ++ prettyShow version) (long "version" <> help "Show version number")
168 <*> options
166 <*> options
169 )
167 )
170 ( fullDesc
168 ( fullDesc
src/Distribution/Nixpkgs/Haskell/Constraint.hs+1−1
@@ -9,7 +9,7 @@ import Distribution.Nixpkgs.Haskell.OrphanInstances ( )
9type Constraint = Dependency
9type Constraint = Dependency
10
10
11satisfiesConstraint :: PackageIdentifier -> Constraint -> Bool
11satisfiesConstraint :: PackageIdentifier -> Constraint -> Bool
12−satisfiesConstraint (PackageIdentifier pn v) (Dependency cn vr) = (pn /= cn) || (v `withinRange` vr)
12+satisfiesConstraint (PackageIdentifier pn v) (Dependency cn vr _) = (pn /= cn) || (v `withinRange` vr)
13
13
14satisfiesConstraints :: PackageIdentifier -> [Constraint] -> Bool
14satisfiesConstraints :: PackageIdentifier -> [Constraint] -> Bool
15satisfiesConstraints p = all (satisfiesConstraint p)
15satisfiesConstraints p = all (satisfiesConstraint p)
src/Distribution/Nixpkgs/Haskell/Derivation.hs+2−2
@@ -112,8 +112,8 @@ instance Pretty Derivation where
112 pPrint drv@MkDerivation {..} = funargs (map text ("mkDerivation" : toAscList inputs)) $$ vcat
112 pPrint drv@MkDerivation {..} = funargs (map text ("mkDerivation" : toAscList inputs)) $$ vcat
113 [ text "mkDerivation" <+> lbrace
113 [ text "mkDerivation" <+> lbrace
114 , nest 2 $ vcat
114 , nest 2 $ vcat
115− [ attr "pname" $ doubleQuotes $ disp (packageName _pkgid)
115+ [ attr "pname" $ doubleQuotes $ pPrint (packageName _pkgid)
116− , attr "version" $ doubleQuotes $ disp (packageVersion _pkgid)
116+ , attr "version" $ doubleQuotes $ pPrint (packageVersion _pkgid)
117 , pPrint _src
117 , pPrint _src
118 , onlyIf (_subpath /= ".") $ attr "postUnpack" postUnpack
118 , onlyIf (_subpath /= ".") $ attr "postUnpack" postUnpack
119 , onlyIf (_revision > 0) $ attr "revision" $ doubleQuotes $ int _revision
119 , onlyIf (_revision > 0) $ attr "revision" $ doubleQuotes $ int _revision
src/Distribution/Nixpkgs/Haskell/FromCabal.hs+7−7
@@ -58,14 +58,14 @@ finalizeGenericPackageDescription haskellResolver arch compiler flags constraint
58 }
58 }
59
59
60 jailbroken :: HaskellResolver -> HaskellResolver
60 jailbroken :: HaskellResolver -> HaskellResolver
61− jailbroken resolver (Dependency pkg _) = resolver (Dependency pkg anyVersion)
61+ jailbroken resolver (Dependency pkg _ _) = resolver (Dependency pkg anyVersion mempty)
62
62
63 withInternalLibs :: HaskellResolver -> HaskellResolver
63 withInternalLibs :: HaskellResolver -> HaskellResolver
64 withInternalLibs resolver d = depPkgName d `elem` internalNames || resolver d
64 withInternalLibs resolver d = depPkgName d `elem` internalNames || resolver d
65
65
66 internalNames :: [PackageName]
66 internalNames :: [PackageName]
67 internalNames = [ unqualComponentNameToPackageName n | (n,_) <- condSubLibraries genDesc ]
67 internalNames = [ unqualComponentNameToPackageName n | (n,_) <- condSubLibraries genDesc ]
68− ++ [ unqualComponentNameToPackageName n | Just n <- libName <$> subLibraries (packageDescription genDesc) ]
68+ ++ [ unqualComponentNameToPackageName n | LSubLibName n <- libName <$> subLibraries (packageDescription genDesc) ]
69
69
70 in case finalize (jailbroken (withInternalLibs haskellResolver)) of
70 in case finalize (jailbroken (withInternalLibs haskellResolver)) of
71 Left m -> case finalize (const True) of
71 Left m -> case finalize (const True) of
@@ -119,7 +119,7 @@ fromPackageDescription haskellResolver nixpkgsResolver missingDeps flags Package
119 nixLicense = either fromSPDXLicense fromCabalLicense licenseRaw
119 nixLicense = either fromSPDXLicense fromCabalLicense licenseRaw
120
120
121 resolveInHackage :: Identifier -> Binding
121 resolveInHackage :: Identifier -> Binding
122− resolveInHackage i | (i^.ident) `elem` [ unPackageName n | (Dependency n _) <- missingDeps ] = bindNull i
122+ resolveInHackage i | (i^.ident) `elem` [ unPackageName n | (Dependency n _ _) <- missingDeps ] = bindNull i
123 | otherwise = binding # (i, path # ["self",i]) -- TODO: "self" shouldn't be hardcoded.
123 | otherwise = binding # (i, path # ["self",i]) -- TODO: "self" shouldn't be hardcoded.
124
124
125 -- TODO: This is all very confusing. Haskell packages refer to the Nixpkgs
125 -- TODO: This is all very confusing. Haskell packages refer to the Nixpkgs
@@ -144,11 +144,11 @@ fromPackageDescription haskellResolver nixpkgsResolver missingDeps flags Package
144 | otherwise = bindNull i
144 | otherwise = bindNull i
145
145
146 resolveInHackageThenNixpkgs :: Identifier -> Binding
146 resolveInHackageThenNixpkgs :: Identifier -> Binding
147− resolveInHackageThenNixpkgs i | haskellResolver (Dependency (mkPackageName (i^.ident)) anyVersion) = resolveInHackage i
147+ resolveInHackageThenNixpkgs i | haskellResolver (Dependency (mkPackageName (i^.ident)) anyVersion mempty) = resolveInHackage i
148 | otherwise = resolveInNixpkgs i
148 | otherwise = resolveInNixpkgs i
149
149
150 internalLibNames :: [PackageName]
150 internalLibNames :: [PackageName]
151− internalLibNames = fmap unqualComponentNameToPackageName . catMaybes $ libName <$> subLibraries
151+ internalLibNames = [ unqualComponentNameToPackageName n | LSubLibName n <- libName <$> subLibraries ]
152
152
153 doHaddockPhase :: Bool
153 doHaddockPhase :: Bool
154 doHaddockPhase | not (null internalLibNames) = False
154 doHaddockPhase | not (null internalLibNames) = False
@@ -158,7 +158,7 @@ fromPackageDescription haskellResolver nixpkgsResolver missingDeps flags Package
158 convertBuildInfo :: Cabal.BuildInfo -> Nix.BuildInfo
158 convertBuildInfo :: Cabal.BuildInfo -> Nix.BuildInfo
159 convertBuildInfo Cabal.BuildInfo {..} | not buildable = mempty
159 convertBuildInfo Cabal.BuildInfo {..} | not buildable = mempty
160 convertBuildInfo Cabal.BuildInfo {..} = mempty
160 convertBuildInfo Cabal.BuildInfo {..} = mempty
161− & haskell .~ Set.fromList [ resolveInHackage (toNixName x) | (Dependency x _) <- targetBuildDepends, x `notElem` internalLibNames ]
161+ & haskell .~ Set.fromList [ resolveInHackage (toNixName x) | (Dependency x _ _) <- targetBuildDepends, x `notElem` internalLibNames ]
162 & system .~ Set.fromList [ resolveInNixpkgs y | x <- extraLibs, y <- libNixName x ]
162 & system .~ Set.fromList [ resolveInNixpkgs y | x <- extraLibs, y <- libNixName x ]
163 & pkgconfig .~ Set.fromList [ resolveInNixpkgs y | PkgconfigDependency x _ <- pkgconfigDepends, y <- libNixName (unPkgconfigName x) ]
163 & pkgconfig .~ Set.fromList [ resolveInNixpkgs y | PkgconfigDependency x _ <- pkgconfigDepends, y <- libNixName (unPkgconfigName x) ]
164 & tool .~ Set.fromList (map resolveInHackageThenNixpkgs . concatMap buildToolNixName
164 & tool .~ Set.fromList (map resolveInHackageThenNixpkgs . concatMap buildToolNixName
@@ -166,7 +166,7 @@ fromPackageDescription haskellResolver nixpkgsResolver missingDeps flags Package
166
166
167 convertSetupBuildInfo :: Cabal.SetupBuildInfo -> Nix.BuildInfo
167 convertSetupBuildInfo :: Cabal.SetupBuildInfo -> Nix.BuildInfo
168 convertSetupBuildInfo bi = mempty
168 convertSetupBuildInfo bi = mempty
169− & haskell .~ Set.fromList [ resolveInHackage (toNixName x) | (Dependency x _) <- Cabal.setupDepends bi ]
169+ & haskell .~ Set.fromList [ resolveInHackage (toNixName x) | (Dependency x _ _) <- Cabal.setupDepends bi ]
170
170
171bindNull :: Identifier -> Binding
171bindNull :: Identifier -> Binding
172bindNull i = binding # (i, path # ["null"])
172bindNull i = binding # (i, path # ["null"])
src/Distribution/Nixpkgs/Haskell/FromCabal/PostProcess.hs+1−1
@@ -21,7 +21,7 @@ import Language.Nix
21
21
22postProcess :: Derivation -> Derivation
22postProcess :: Derivation -> Derivation
23postProcess deriv =
23postProcess deriv =
24− foldr (.) id [ f | (Dependency n vr, f) <- hooks, packageName deriv == n, packageVersion deriv `withinRange` vr ]
24+ foldr (.) id [ f | (Dependency n vr _, f) <- hooks, packageName deriv == n, packageVersion deriv `withinRange` vr ]
25 . fixGtkBuilds
25 . fixGtkBuilds
26 . fixBuildDependsForTools
26 . fixBuildDependsForTools
27 $ deriv
27 $ deriv
src/Distribution/Nixpkgs/Haskell/OrphanInstances.hs+24−3
@@ -9,9 +9,12 @@ import qualified Data.Text as T
9import Data.Yaml
9import Data.Yaml
10import Distribution.Compiler
10import Distribution.Compiler
11import Distribution.Package
11import Distribution.Package
12+import Distribution.Parsec
12import Distribution.System
13import Distribution.System
13−import Distribution.Text
14+import Distribution.Pretty as Cabal
15+import qualified Data.Version as Base
14import Distribution.Version
16import Distribution.Version
17+import Language.Nix.PrettyPrinting as Nix
15
18
16instance NFData CompilerInfo
19instance NFData CompilerInfo
17instance NFData AbiTag
20instance NFData AbiTag
@@ -61,7 +64,25 @@ instance FromJSON CompilerInfo where
61 parseJSON (String s) = return (unknownCompilerInfo (fromString (T.unpack s)) NoAbiTag)
64 parseJSON (String s) = return (unknownCompilerInfo (fromString (T.unpack s)) NoAbiTag)
62 parseJSON s = fail ("parseJSON: " ++ show s ++ " is not a valid Haskell compiler")
65 parseJSON s = fail ("parseJSON: " ++ show s ++ " is not a valid Haskell compiler")
63
66
67+instance Nix.Pretty Version where
68+ pPrint = pretty
69+
70+instance Nix.Pretty PackageName where
71+ pPrint = pretty
72+
73+instance Nix.Pretty PackageIdentifier where
74+ pPrint = pretty
75+
76+instance Nix.Pretty CompilerId where
77+ pPrint = pretty
78+
79+instance Nix.Pretty Platform where
80+ pPrint = pretty
81+
82+instance Nix.Pretty Base.Version where
83+ pPrint = text . Base.showVersion
84+
64-- parsing tools
85-- parsing tools
65
86
66−text2isString :: Text a => String -> String -> a
87+text2isString :: Parsec a => String -> String -> a
67−text2isString t s = fromMaybe (error ("fromString: " ++ show s ++ " is not a valid " ++ t)) (simpleParse s)
88+text2isString t s = fromMaybe (error ("fromString: " ++ show s ++ " is not a valid " ++ t)) (simpleParsec s)
src/Distribution/Nixpkgs/Haskell/PackageSourceSpec.hs+9−8
@@ -11,16 +11,18 @@ import qualified Data.ByteString.Char8 as BS
11import Data.List ( isSuffixOf, isPrefixOf )
11import Data.List ( isSuffixOf, isPrefixOf )
12import qualified Data.Map as DB
12import qualified Data.Map as DB
13import Data.Maybe
13import Data.Maybe
14+import qualified Data.Text as T
15+import qualified Data.Text.Encoding as T
14import Data.Time
16import Data.Time
15import Distribution.Nixpkgs.Fetch
17import Distribution.Nixpkgs.Fetch
16import Distribution.Nixpkgs.Hashes
18import Distribution.Nixpkgs.Hashes
17import qualified Distribution.Nixpkgs.Haskell.Hackage as DB
19import qualified Distribution.Nixpkgs.Haskell.Hackage as DB
20+import Distribution.Nixpkgs.Haskell.OrphanInstances ( )
18import qualified Distribution.Package as Cabal
21import qualified Distribution.Package as Cabal
19import Distribution.PackageDescription
22import Distribution.PackageDescription
20import qualified Distribution.PackageDescription as Cabal
23import qualified Distribution.PackageDescription as Cabal
21import Distribution.PackageDescription.Parsec as Cabal
24import Distribution.PackageDescription.Parsec as Cabal
22−import Distribution.Parsec.Common (showPError)
25+import Distribution.Parsec
23−import Distribution.Text ( simpleParse, display )
24import Distribution.Version
26import Distribution.Version
25import qualified Hpack.Config as Hpack
27import qualified Hpack.Config as Hpack
26import qualified Hpack.Render as Hpack
28import qualified Hpack.Render as Hpack
@@ -29,8 +31,7 @@ import System.Directory ( doesDirectoryExist, doesFileExist, createDirectoryIfMi
29import System.Exit ( exitFailure )
31import System.Exit ( exitFailure )
30import System.FilePath ( (</>), (<.>) )
32import System.FilePath ( (</>), (<.>) )
31import System.IO
33import System.IO
32−import qualified Data.Text as T
34+import Text.PrettyPrint.HughesPJClass hiding ( first )
33−import qualified Data.Text.Encoding as T
34
35
35data HpackUse
36data HpackUse
36 = ForceHpack
37 = ForceHpack
@@ -107,12 +108,12 @@ fromDB hackageDBIO pkg = do
107 return (ds, setCabalFileHash (DB.cabalFileSha256 vd) (DB.cabalFile vd))
108 return (ds, setCabalFileHash (DB.cabalFileSha256 vd) (DB.cabalFile vd))
108 where
109 where
109 pkgId :: Cabal.PackageIdentifier
110 pkgId :: Cabal.PackageIdentifier
110− pkgId = fromMaybe (error ("invalid Haskell package id " ++ show pkg)) (simpleParse pkg)
111+ pkgId = fromMaybe (error ("invalid Haskell package id " ++ show pkg)) (simpleParsec pkg)
111 name = Cabal.packageName pkgId
112 name = Cabal.packageName pkgId
112
113
113− unknownPackageError = fail $ "No such package " ++ display pkgId ++ " in the cabal database. Did you run cabal update?"
114+ unknownPackageError = fail $ "No such package " ++ prettyShow pkgId ++ " in the cabal database. Did you run cabal update?"
114
115
115− url = "mirror://hackage/" ++ display pkgId ++ ".tar.gz"
116+ url = "mirror://hackage/" ++ prettyShow pkgId ++ ".tar.gz"
116
117
117 version :: Version
118 version :: Version
118 version = Cabal.packageVersion pkgId
119 version = Cabal.packageVersion pkgId
@@ -175,7 +176,7 @@ sourceFromHackage optHash pkgId cabalDir = do
175 exitFailure
176 exitFailure
176
177
177showPackageIdentifier :: Cabal.GenericPackageDescription -> String
178showPackageIdentifier :: Cabal.GenericPackageDescription -> String
178−showPackageIdentifier pkgDesc = name ++ "-" ++ display version where
179+showPackageIdentifier pkgDesc = name ++ "-" ++ prettyShow version where
179 pkgId = Cabal.package . Cabal.packageDescription $ pkgDesc
180 pkgId = Cabal.package . Cabal.packageDescription $ pkgDesc
180 name = Cabal.unPackageName (Cabal.packageName pkgId)
181 name = Cabal.unPackageName (Cabal.packageName pkgId)
181 version = Cabal.packageVersion pkgId
182 version = Cabal.packageVersion pkgId