git.iko.soy/typeable/cabal2nix
on master help sign in
Use Pretty instance for showing DerivationSource
commit1e3e66f2fcd926cb9f85fa71e9fce68229faf766 authorKevin Quick <kquick@galois.com> dateWed 15 Aug 2018, 21:55 (8 years ago) parenta91fac7
2 files changed+20−13
src/Distribution/Nixpkgs/Fetch.hs+19 src/Distribution/Nixpkgs/Haskell/Derivation.hs+1−13
src/Distribution/Nixpkgs/Fetch.hs+19
@@ -18,7 +18,9 @@ import Control.Monad.IO.Class
1818import Control.Monad.Trans.Maybe
1919import Data.Aeson
2020import qualified Data.ByteString.Lazy.Char8 as BS
21+import qualified Data.List as L
2122import GHC.Generics ( Generic )
23+import Language.Nix.PrettyPrinting as PP
2224import System.Directory
2325import System.Environment
2426import System.Exit
@@ -68,6 +70,23 @@ instance FromJSON DerivationSource where
6870 <*> o .: "sha256"
6971 parseJSON _ = error "invalid DerivationSource"
7072
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+
7190urlDerivationSource :: String -> String -> DerivationSource
7291urlDerivationSource url hash = DerivationSource "url" url "" hash
7392
src/Distribution/Nixpkgs/Haskell/Derivation.hs+1−13
@@ -112,7 +112,7 @@ instance Pretty Derivation where
112112 , nest 2 $ vcat
113113 [ attr "pname" $ doubleQuotes $ disp (packageName _pkgid)
114114 , attr "version" $ doubleQuotes $ disp (packageVersion _pkgid)
115− , sourceAttr _src
115+ , pPrint _src
116116 , onlyIf (_subpath /= ".") $ attr "postUnpack" postUnpack
117117 , onlyIf (_revision > 0) $ attr "revision" $ doubleQuotes $ int _revision
118118 , onlyIf (not (null _editedCabalFile) && _revision > 0) $ attr "editedCabalFile" $ string _editedCabalFile
@@ -148,17 +148,5 @@ instance Pretty Derivation where
148148 renderedFlags = [ text "-f" <> (if enable then empty else char '-') <> text (unFlagName f) | (f, enable) <- unFlagAssignment _cabalFlags ]
149149 ++ map text (toAscList _configureFlags)
150150 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
163151
164152 postUnpack = string $ "sourceRoot+=/" ++ _subpath ++ "; echo source root reset to $sourceRoot"