1{-# LANGUAGE RecordWildCards, DeriveGeneric, StandaloneDeriving #-}
2{-# OPTIONS_GHC -fno-warn-orphans #-} -- for FlagName below
4module Distribution.Nixpkgs.Haskell
8 , module Distribution.Nixpkgs.Meta
13import Control.DeepSeq.Generics
15import Data.Set ( Set )
16import qualified Data.Set as Set
20import Distribution.Nixpkgs.Meta
21import Distribution.Nixpkgs.Fetch
22import Distribution.Nixpkgs.Util.PrettyPrinting
23import Distribution.Package
24import Distribution.PackageDescription ( FlagAssignment, FlagName(..) )
25import GHC.Generics ( Generic )
27toAscList :: Set String -> [String]
28toAscList = sortBy (compare `on` map toLower) . Set.toList
30-- | A represtation of Nix expressions for building Haskell packages.
31-- The data type correspond closely to the definition of
32-- 'PackageDescription' from Cabal.
34-- Note that the "Text" instance definition provides pretty-printing,
35-- but no parsing as of now!
36data Derivation = MkDerivation
40 , src :: DerivationSource
42 , isExecutable :: Bool
43 , extraFunctionArgs :: Set String
44 , buildDepends :: Set String
45 , testDepends :: Set String
46 , buildTools :: Set String
47 , extraLibs :: Set String
48 , pkgConfDeps :: Set String
49 , configureFlags :: Set String
50 , cabalFlags :: FlagAssignment
54 , testTarget :: String
55 , hyperlinkSource :: Bool
56 , enableSplitObjs :: Bool
57 , phaseOverrides :: String
58 , editedCabalFile :: String
61 deriving (Show, Eq, Ord, Generic)
63instance Pretty Derivation where
64 pPrint = renderDerivation
66instance Package Derivation where
67 packageId deriv = PackageIdentifier (PackageName (pname deriv)) (version deriv)
69instance NFData Derivation where rnf = genericRnf
71instance NFData FlagName where rnf = genericRnf
73renderDerivation :: Derivation -> Doc
74renderDerivation (MkDerivation {..}) =
75 funargs (map text ("mkDerivation" : toAscList inputs)) $$ vcat
76 [ text "mkDerivation" <+> lbrace
78 [ attr "pname" $ string pname
79 , attr "version" $ doubleQuotes (disp version)
80 , onlyIf (revision > 0) $ attr "revision" $ doubleQuotes (int revision)
82 , onlyIf (not (null editedCabalFile)) $ attr "editedCabalFile" $ string editedCabalFile
83 , boolattr "isLibrary" (not isLibrary || isExecutable) isLibrary
84 , boolattr "isExecutable" (not isLibrary || isExecutable) isExecutable
85 , listattr "buildDepends" empty (toAscList buildDepends)
86 , listattr "testDepends" empty (toAscList testDepends)
87 , listattr "buildTools" empty (toAscList buildTools)
88 , listattr "extraLibraries" empty (toAscList extraLibs)
89 , listattr "pkgconfigDepends" empty (toAscList pkgConfDeps)
90 , listattr "configureFlags" empty (map (show . show) renderedFlags)
91 , boolattr "enableSplitObjs" (not enableSplitObjs) enableSplitObjs
92 , boolattr "doHaddock" (not runHaddock) runHaddock
93 , boolattr "jailbreak" jailbreak jailbreak
94 , boolattr "doCheck" (not doCheck) doCheck
95 , onlyIf (not (null testTarget)) $ attr "testTarget" $ string testTarget
96 , boolattr "hyperlinkSource" (not hyperlinkSource) hyperlinkSource
97 , onlyIf (not (null phaseOverrides)) $ vcat ((map text . lines) phaseOverrides)
103 inputs = Set.unions [ buildDepends, testDepends, buildTools, extraLibs, pkgConfDeps, extraFunctionArgs
104 , Set.fromList ["fetch" ++ derivKind src | derivKind src /= "" && not isHackagePackage]
106 renderedFlags = [ text "-f" <> (if enable then empty else char '-') <> text f | (FlagName f, enable) <- cabalFlags ]
107 ++ map text (toAscList configureFlags)
108 isHackagePackage = "mirror://hackage/" `isPrefixOf` derivUrl src
109 sourceAttr (DerivationSource{..})
110 | isHackagePackage = attr "sha256" $ string derivHash
111 | derivKind /= "" = vcat
112 [ text "src" <+> equals <+> text ("fetch" ++ derivKind) <+> lbrace
114 [ attr "url" $ string derivUrl
115 , attr "sha256" $ string derivHash
116 , if derivRevision /= "" then attr "rev" (string derivRevision) else empty
120 | otherwise = attr "src" $ text derivUrl
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list