git.iko.soy/typeable/cabal2nix
on master help sign in
Use Pretty instance for showing DerivationSource
1e3e66fKevin Quick
src/Distribution/Nixpkgs/Fetch.hs+19
@@ -18,7 +18,9 @@ import Control.Monad.IO.Class
18import Control.Monad.Trans.Maybe
18import Control.Monad.Trans.Maybe
19import Data.Aeson
19import Data.Aeson
20import qualified Data.ByteString.Lazy.Char8 as BS
20import qualified Data.ByteString.Lazy.Char8 as BS
21+import qualified Data.List as L
21import GHC.Generics ( Generic )
22import GHC.Generics ( Generic )
23+import Language.Nix.PrettyPrinting as PP
22import System.Directory
24import System.Directory
23import System.Environment
25import System.Environment
24import System.Exit
26import System.Exit
@@ -68,6 +70,23 @@ instance FromJSON DerivationSource where
68 <*> o .: "sha256"
70 <*> o .: "sha256"
69 parseJSON _ = error "invalid DerivationSource"
71 parseJSON _ = error "invalid DerivationSource"
70
72
73+instance PP.Pretty DerivationSource where
74+ pPrint DerivationSource {..} =
75+ let isHackagePackage = "mirror://hackage/" `L.isPrefixOf` derivUrl
76+ fetched = derivKind /= ""
77+ in if isHackagePackage then attr "sha256" $ string derivHash
78+ else if not fetched then attr "src" $ text derivUrl
79+ else vcat
80+ [ text "src" <+> equals <+> text ("fetch" ++ derivKind) <+> lbrace
81+ , nest 2 $ vcat
82+ [ attr "url" $ string derivUrl
83+ , attr "sha256" $ string derivHash
84+ , if derivRevision /= "" then attr "rev" (string derivRevision) else PP.empty
85+ ]
86+ , rbrace PP.<> semi
87+ ]
88+
89+
71urlDerivationSource :: String -> String -> DerivationSource
90urlDerivationSource :: String -> String -> DerivationSource
72urlDerivationSource url hash = DerivationSource "url" url "" hash
91urlDerivationSource url hash = DerivationSource "url" url "" hash
73
92
src/Distribution/Nixpkgs/Haskell/Derivation.hs+1−13
@@ -112,7 +112,7 @@ instance Pretty Derivation where
112 , nest 2 $ vcat
112 , nest 2 $ vcat
113 [ attr "pname" $ doubleQuotes $ disp (packageName _pkgid)
113 [ attr "pname" $ doubleQuotes $ disp (packageName _pkgid)
114 , attr "version" $ doubleQuotes $ disp (packageVersion _pkgid)
114 , attr "version" $ doubleQuotes $ disp (packageVersion _pkgid)
115− , sourceAttr _src
115+ , pPrint _src
116 , onlyIf (_subpath /= ".") $ attr "postUnpack" postUnpack
116 , onlyIf (_subpath /= ".") $ attr "postUnpack" postUnpack
117 , onlyIf (_revision > 0) $ attr "revision" $ doubleQuotes $ int _revision
117 , onlyIf (_revision > 0) $ attr "revision" $ doubleQuotes $ int _revision
118 , onlyIf (not (null _editedCabalFile) && _revision > 0) $ attr "editedCabalFile" $ string _editedCabalFile
118 , onlyIf (not (null _editedCabalFile) && _revision > 0) $ attr "editedCabalFile" $ string _editedCabalFile
@@ -148,17 +148,5 @@ instance Pretty Derivation where
148 renderedFlags = [ text "-f" <> (if enable then empty else char '-') <> text (unFlagName f) | (f, enable) <- unFlagAssignment _cabalFlags ]
148 renderedFlags = [ text "-f" <> (if enable then empty else char '-') <> text (unFlagName f) | (f, enable) <- unFlagAssignment _cabalFlags ]
149 ++ map text (toAscList _configureFlags)
149 ++ map text (toAscList _configureFlags)
150 isHackagePackage = "mirror://hackage/" `isPrefixOf` derivUrl _src
150 isHackagePackage = "mirror://hackage/" `isPrefixOf` derivUrl _src
151− sourceAttr DerivationSource {..}
152− | isHackagePackage = attr "sha256" $ string derivHash
153− | derivKind /= "" = vcat
154− [ text "src" <+> equals <+> text ("fetch" ++ derivKind) <+> lbrace
155− , nest 2 $ vcat
156− [ attr "url" $ string derivUrl
157− , attr "sha256" $ string derivHash
158− , if derivRevision /= "" then attr "rev" (string derivRevision) else empty
159− ]
160− , rbrace <> semi
161− ]
162− | otherwise = attr "src" $ text derivUrl
163
151
164 postUnpack = string $ "sourceRoot+=/" ++ _subpath ++ "; echo source root reset to $sourceRoot"
152 postUnpack = string $ "sourceRoot+=/" ++ _subpath ++ "; echo source root reset to $sourceRoot"