git.iko.soy/typeable/cabal2nix
on master help sign in
Added support for parsing and generating the 'editedCabalFile' attribute.
commit859f11cfbbee711ecb00fe1f8964082f7f5be44b authorPeter Simons <simons@cryp.to> dateMon 15 Dec 2014, 21:42 (12 years ago) parentd19a30f
3 files changed+14−4
src/Cabal2Nix/Generate.hs+3 src/Distribution/NixOS/Derivation/Cabal.hs+10−3 src/hackage4nix.hs+1−1
src/Cabal2Nix/Generate.hs+3
@@ -16,6 +16,7 @@ cabal2nix :: Cabal.GenericPackageDescription -> Derivation
1616cabal2nix cabal = normalize $ postProcess MkDerivation
1717 { pname = let Cabal.PackageName x = Cabal.pkgName pkg in x
1818 , version = Cabal.pkgVersion pkg
19+ , revision = maybe 0 read (lookup "x-revision" xfields)
1920 , src = error "cabal2nix left the src field undefined"
2021 , isLibrary = isJust (Cabal.library tpkg)
2122 , isExecutable = not (null (Cabal.executables tpkg))
@@ -34,6 +35,7 @@ cabal2nix cabal = normalize $ postProcess MkDerivation
3435 , hyperlinkSource = True
3536 , enableSplitObjs = True
3637 , phaseOverrides = ""
38+ , editedCabalFile= ""
3739 , metaSection = Meta
3840 { homepage = Cabal.homepage descr
3941 , description = Cabal.synopsis descr
@@ -45,6 +47,7 @@ cabal2nix cabal = normalize $ postProcess MkDerivation
4547 }
4648 where
4749 descr = Cabal.packageDescription cabal
50+ xfields = Cabal.customFieldsPD descr
4851 pkg = Cabal.package descr
4952 deps = Cabal.buildDepends tpkg
5053 tests = map Cabal.testBuildInfo (Cabal.testSuites tpkg)
src/Distribution/NixOS/Derivation/Cabal.hs+10−3
@@ -45,6 +45,7 @@ import Distribution.Text
4545data Derivation = MkDerivation
4646 { pname :: String
4747 , version :: Version
48+ , revision :: Int
4849 , src :: DerivationSource
4950 , isLibrary :: Bool
5051 , isExecutable :: Bool
@@ -63,6 +64,7 @@ data Derivation = MkDerivation
6364 , hyperlinkSource :: Bool
6465 , enableSplitObjs :: Bool
6566 , phaseOverrides :: String
67+ , editedCabalFile :: String
6668 , metaSection :: Meta
6769 }
6870 deriving (Show, Eq, Ord)
@@ -75,10 +77,11 @@ instance Package Derivation where
7577 packageId deriv = PackageIdentifier (PackageName (pname deriv)) (version deriv)
7678
7779instance NFData Derivation where
78− rnf (MkDerivation a b c d e f g h i j k l m n o p q r t u v) =
80+ rnf (MkDerivation a b c d e f g h i j k l m n o p q r t u v w x) =
7981 a `deepseq` b `deepseq` c `deepseq` d `deepseq` e `deepseq` f `deepseq` g `deepseq`
80− h `deepseq` i `deepseq` j `deepseq` k `deepseq` l `deepseq` m `deepseqFlagAssignment` n `deepseq`
81− o `deepseq` p `deepseq` q `deepseq` r `deepseq` t `deepseq` u `deepseq` v `deepseq` ()
82+ h `deepseq` i `deepseq` j `deepseq` k `deepseq` l `deepseq` m `deepseq` n `deepseqFlagAssignment`
83+ o `deepseq` p `deepseq` q `deepseq` r `deepseq` t `deepseq` u `deepseq` v `deepseq`
84+ w `deepseq` x `deepseq` ()
8285
8386-- FlagName has no NFData instance in old version of Cabal.
8487deepseqFlagAssignment :: FlagAssignment -> a -> a
@@ -93,6 +96,7 @@ renderDerivation deriv =
9396 [ attr "pname" $ string (pname deriv)
9497 , attr "version" $ doubleQuotes (disp (version deriv))
9598 , sourceAttr (src deriv)
99+ , onlyIf (not (null (editedCabalFile deriv))) $ attr "editedCabalFile" $ string (editedCabalFile deriv)
96100 , boolattr "isLibrary" (not (isLibrary deriv) || isExecutable deriv) (isLibrary deriv)
97101 , boolattr "isExecutable" (not (isLibrary deriv) || isExecutable deriv) (isExecutable deriv)
98102 , listattr "buildDepends" empty (buildDepends deriv)
@@ -153,9 +157,11 @@ parseDerivation buf
153157 , docheck <- buf `regsubmatch` "doCheck *= *(true|false) *;"
154158 , hyperlSrc <- buf `regsubmatch` "hyperlinkSource *= *(true|false) *;"
155159 , splitObj <- buf `regsubmatch` "enableSplitObjs *= *(true|false) *;"
160+ , edtdCabal <- buf `regsubmatch` "editedCabalFile *= *\"([^\"]+)\""
156161 = Just MkDerivation
157162 { pname = name
158163 , version = vers
164+ , revision = 0
159165 , src = case (sr,url) of
160166 ([] , _ ) -> DerivationSource "url" ("mirror://hackage/" ++ name ++ "-" ++ vers' ++ ".tar.gz") "" $ head sha
161167 (sr':_, [] ) -> DerivationSource "" sr' "" ""
@@ -179,6 +185,7 @@ parseDerivation buf
179185 , hyperlinkSource = hyperlSrc == ["true"] || null hyperlSrc
180186 , enableSplitObjs = splitObj /= ["false"]
181187 , phaseOverrides = ""
188+ , editedCabalFile = if null edtdCabal then [] else head edtdCabal
182189 , metaSection = Meta
183190 { homepage = ""
184191 , description = ""
src/hackage4nix.hs+1−1
@@ -72,7 +72,7 @@ discoverNixFiles yield dirOrFile = do
7272 (False,_) -> io (readDirectory dirOrFile) >>= mapM_ (discoverNixFiles yield . (dirOrFile </>))
7373
7474regenerateDerivation :: Derivation -> String -> Bool
75−regenerateDerivation _ buf = not (buf =~ "(pre|post)Configure|(pre|post)Install|patchPhase|patches|broken|editedCabalFile")
75+regenerateDerivation _ buf = not (buf =~ "(pre|post)Configure|(pre|post)Install|patchPhase|patches|broken")
7676
7777parseNixFile :: FilePath -> String -> Hackage4Nix (Maybe Pkg)
7878parseNixFile path buf