git.iko.soy/typeable/cabal2nix
on master help sign in
generate-cabal-file.hs: use Cartel to generate our Cabal file programatically
commit8dfcb5b78b69ab8ca2d10c96866eeffdd33d54b9 authorPeter Simons <simons@cryp.to> dateSat 24 Jan 2015, 18:03 (12 years ago) parent8e09014
6 files changed+135−201
.ghci+5 .gitignore+5−3 GNUmakefile+18 cabal2nix.cabal−198 generate-cabal-file.hs+105 release.nix+2
.ghcinew file+5
@@ -0,0 +1,5 @@
1+-- generate-cabal-file.hs needs the cartel library, but the Cabal file
2+-- doesn't mention that library anywhere, so we need to add it manually
3+-- to make haskell-mode's interactive-mode feature happy.
4+
5+:set -package cartel
.gitignore+5−3
@@ -1,10 +1,12 @@
11# ignore build Cabal build files
22
3+/Setup
4+/Setup.hi
5+/Setup.o
6+/cabal2nix.cabal
37/dist/*
4−Setup.o
5−Setup.hi
6−Setup
78
89# vim tmp files
10+
911*.swo
1012*.swp
GNUmakefilenew file+18
@@ -0,0 +1,18 @@
1+# GNUmakefile
2+
3+.PHONY: all configure build check check
4+
5+all:: check
6+
7+configure:: cabal2nix.cabal
8+ @cabal configure --ghc-option=-j --enable-tests
9+
10+build:: configure
11+ @cabal build -j
12+
13+check:: build
14+ @cabal test -j
15+
16+cabal2nix.cabal: generate-cabal-file.hs
17+ runhaskell "$<" >"$@"
18+ cabal check
cabal2nix.cabaldeleted−198
@@ -1,198 +0,0 @@
1−name: cabal2nix
2−version: 2.0
3−copyright: Peter Simons, Andres Loeh
4−license: BSD3
5−license-file: LICENSE
6−author: Peter Simons <simons@cryp.to>, Andres Loeh <mail@andres-loeh.de>
7−maintainer: Nix Developers <nix-dev@lists.science.uu.nl>
8−homepage: http://github.com/NixOS/cabal2nix
9−category: Distribution
10−synopsis: Convert Cabal files into Nix build instructions
11−cabal-version: >= 1.8
12−build-type: Simple
13−data-files: README.md
14−description:
15− The @cabal2nix@ utility converts Cabal files into Nix build instructions. The
16− commandline syntax is:
17− .
18− > Usage: cabal2nix [options] URI
19− > -h --help show this help text
20− > -v --version print version
21− > --hackage-db=FILEPATH path to the local hackage db in tar format
22− > --sha256=HASH sha256 hash of source tarball
23− > -m MAINTAINER --maintainer=MAINTAINER maintainer of this package (may be specified multiple times)
24− > -p PLATFORM --platform=PLATFORM supported build platforms (may be specified multiple times)
25− > -f FLAG --flag=FLAG Cabal flag (may be specified multiple times)
26− > --jailbreak don't honor version restrictions on build inputs
27− > --no-haddock don't run Haddock when building this package
28− > --no-check don't run regression test suites of this package
29− > --rev=REVISION revision, only used when fetching from VCS
30− > --no-hyperlink-source don't add pretty-printed source code to the documentation
31− > --shell generate output suitable for nix-shell
32− >
33− > Recognized URI schemes:
34− >
35− > cabal://pkgname-pkgversion download the specified package from Hackage
36− > cabal://pkgname download latest version of the specified package from Hackage
37− > http://host/path fetch the Cabal file via HTTP
38− > file:///local/path load the Cabal file from the local disk
39− > /local/path.cabal abbreviated version of file URI
40− > <git/svn/bzr/hg URL> download the source from the specified repository
41− .
42− The only required argument is the path to the cabal file. For example:
43− .
44− > cabal2nix http://hackage.haskell.org/packages/archive/cabal2nix/2.0/cabal2nix.cabal
45− > cabal2nix cabal://cabal2nix-2.0
46− .
47− If the @--sha256@ option has not been specified, cabal2nix calls
48− @nix-prefetch-url@ to determine the hash automatically. This causes
49− network traffic, obviously.
50− .
51− If the argument refers to a source repository instead of a cabal file,
52− cabal2nix will use that source repository to fetch from instead of hackage.
53− Currently, cabal2nix supports directories, archives (fetched via http or https) and
54− git, mercurial, svn or bazaar repositories.
55−
56−source-repository head
57− type: git
58− location: git://github.com/NixOS/cabal2nix.git
59−
60−executable cabal2nix
61− main-is: cabal2nix.hs
62− hs-source-dirs: src
63− build-depends: aeson
64− , base < 100
65− , bytestring
66− , Cabal >= 1.18
67− , containers
68− , deepseq
69− , deepseq-generics
70− , directory
71− , filepath
72− , hackage-db >= 1.11
73− , monad-par
74− , monad-par-extras
75− , mtl
76− , pretty
77− , prettyclass
78− , process
79− , QuickCheck
80− , regex-posix
81− , SHA
82− , split
83− , transformers
84− , utf8-string
85− extensions: PatternGuards, RecordWildCards, DeriveGeneric, StandaloneDeriving
86− ghc-options: -Wall
87− other-modules: Cabal2Nix.CorePackages
88− Cabal2Nix.Flags
89− Cabal2Nix.Generate
90− Cabal2Nix.Hackage
91− Cabal2Nix.License
92− Cabal2Nix.Name
93− Cabal2Nix.Normalize
94− Cabal2Nix.Package
95− Cabal2Nix.PostProcess
96− Cabal2Nix.Version
97− Distribution.NixOS.Derivation.Cabal
98− Distribution.NixOS.Derivation.License
99− Distribution.NixOS.Derivation.Meta
100− Distribution.NixOS.Fetch
101− Distribution.NixOS.PackageMap
102− Distribution.NixOS.Util.PrettyPrinting
103−
104−executable hackage2nix
105− main-is: hackage2nix.hs
106− hs-source-dirs: src
107− build-depends: aeson
108− , base < 100
109− , bytestring
110− , Cabal >= 1.18
111− , containers
112− , deepseq
113− , deepseq-generics
114− , directory
115− , regex-posix
116− , filepath
117− , hackage-db >= 1.11
118− , monad-par
119− , monad-par-extras
120− , mtl
121− , pretty
122− , prettyclass
123− , process
124− , QuickCheck
125− , SHA
126− , split
127− , transformers
128− , utf8-string
129− ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N
130− extensions: PatternGuards, RecordWildCards, CPP, DeriveGeneric, StandaloneDeriving
131− other-modules: Cabal2Nix.CorePackages
132− Cabal2Nix.Flags
133− Cabal2Nix.Generate
134− Cabal2Nix.Hackage
135− Cabal2Nix.License
136− Cabal2Nix.Name
137− Cabal2Nix.Normalize
138− Cabal2Nix.Package
139− Cabal2Nix.PostProcess
140− Cabal2Nix.Version
141− Distribution.NixOS.Derivation.Cabal
142− Distribution.NixOS.Derivation.License
143− Distribution.NixOS.Derivation.Meta
144− Distribution.NixOS.Fetch
145− Distribution.NixOS.PackageMap
146− Distribution.NixOS.Util.PrettyPrinting
147−
148−test-suite doctest-cabal2nix
149− type: exitcode-stdio-1.0
150− main-is: doc-test.hs
151− hs-source-dirs: test
152− extensions: PatternGuards, RecordWildCards, CPP, DeriveGeneric, StandaloneDeriving
153− build-depends: base, doctest
154−
155−test-suite self-test
156− type: exitcode-stdio-1.0
157− main-is: spec.hs
158− hs-source-dirs: src, test
159− extensions: PatternGuards, RecordWildCards, CPP, DeriveGeneric, StandaloneDeriving
160− build-depends: aeson
161− , base
162− , bytestring
163− , Cabal >= 1.18
164− , containers
165− , deepseq
166− , deepseq-generics
167− , directory
168− , regex-posix
169− , filepath
170− , hackage-db >= 1.11
171− , hspec
172− , monad-par
173− , monad-par-extras
174− , mtl
175− , pretty
176− , prettyclass
177− , process
178− , QuickCheck
179− , SHA
180− , split
181− , transformers
182− , utf8-string
183− other-modules: Cabal2Nix.CorePackages
184− Cabal2Nix.Flags
185− Cabal2Nix.Generate
186− Cabal2Nix.Hackage
187− Cabal2Nix.License
188− Cabal2Nix.Name
189− Cabal2Nix.Normalize
190− Cabal2Nix.Package
191− Cabal2Nix.PostProcess
192− Cabal2Nix.Version
193− Distribution.NixOS.Derivation.Cabal
194− Distribution.NixOS.Derivation.License
195− Distribution.NixOS.Derivation.Meta
196− Distribution.NixOS.Fetch
197− Distribution.NixOS.PackageMap
198− Distribution.NixOS.Util.PrettyPrinting
generate-cabal-file.hsnew file+105
@@ -0,0 +1,105 @@
1+module Main ( main ) where
2+
3+import Cartel
4+import Control.Monad.Trans ( liftIO )
5+import System.Process ( readProcess )
6+import Data.List ( intercalate )
7+
8+getVersion :: IO Version
9+getVersion = do
10+ v <- readProcess "git" ["log", "-1", "--format=%ci"] ""
11+ let y4:y3:y2:y1:'-':m2:m1:'-':d2:d1:[] = head (words v)
12+ return (read ('[':y4:y3:y2:y1:',':m2:m1:',':d2:d1:"]"))
13+
14+getAuthors :: IO [NonEmptyString]
15+getAuthors = do
16+ buf <- readProcess "sh" ["-c", "git log --pretty=short | git shortlog --numbered --summary"] ""
17+ return [ unwords (tail (words l)) | l <- lines buf, not (null l) ]
18+
19+properties :: Betsy IO Properties
20+properties = do
21+ v <- liftIO getVersion
22+ as <- liftIO $ getAuthors
23+ return $ blank
24+ { name = "cabal2nix"
25+ , version = v
26+ , buildType = Just simple
27+ , category = "Distribution"
28+ , maintainer = "Peter Simons <simons@cryp.to>"
29+ , synopsis = "Convert Cabal files into Nix build instructions."
30+ , description = [ "Convert Cabal files into Nix build instructions." ]
31+ , license = Just bsd3
32+ , licenseFile = "LICENSE"
33+ , copyright = "Copyright (c) 2011-2015 by Peter Simons et al"
34+ , author = intercalate ", " as
35+ , stability = "Experimental"
36+ , cabalVersion = Just (1,8)
37+ , homepage = "http://github.com/NixOS/cabal2nix/"
38+ , bugReports = "http://github.com/NixOS/cabal2nix/issues"
39+ , extraSourceFiles = ["README.md"]
40+ }
41+
42+commonBuildOptions :: HasBuildInfo a => [a]
43+commonBuildOptions = hsSourceDirs ["src"] : commonOptions
44+
45+commonOptions :: HasBuildInfo a => [a]
46+commonOptions = commonGhcOptions : commonBuildDepends : []
47+
48+commonGhcOptions :: HasBuildInfo a => a
49+commonGhcOptions = ghcOptions ["-Wall"]
50+
51+commonBuildDepends :: HasBuildInfo a => a
52+commonBuildDepends = buildDepends
53+ [ package "base" (lt [5])
54+ , unconstrained "aeson"
55+ , unconstrained "bytestring"
56+ , unconstrained "Cabal"
57+ , unconstrained "containers"
58+ , unconstrained "deepseq-generics"
59+ , unconstrained "directory"
60+ , unconstrained "filepath"
61+ , unconstrained "hackage-db"
62+ , unconstrained "monad-par"
63+ , unconstrained "monad-par-extras"
64+ , unconstrained "mtl"
65+ , unconstrained "pretty"
66+ , unconstrained "prettyclass"
67+ , unconstrained "process"
68+ , unconstrained "regex-posix"
69+ , unconstrained "SHA"
70+ , unconstrained "split"
71+ , unconstrained "transformers"
72+ , unconstrained "utf8-string"
73+ ]
74+
75+commonTestOptions :: HasBuildInfo a => [a]
76+commonTestOptions = buildDepends
77+ [ unconstrained "deepseq"
78+ , unconstrained "doctest"
79+ , unconstrained "hspec"
80+ , unconstrained "QuickCheck"
81+ ] : commonBuildOptions
82+
83+library :: Betsy IO [LibraryField]
84+library = do
85+ ms <- modules "src"
86+ return $ exposedModules ms : commonBuildOptions
87+
88+mkExecutable :: NonEmptyString -> [ExecutableField] -> Section
89+mkExecutable exe opt = executable exe $ mainIs (exe++".hs") : opt ++ commonBuildOptions
90+
91+mkTest :: NonEmptyString -> [TestSuiteField] -> Section
92+mkTest test opt = testSuite test $ exitcodeFields (test++".hs") ++ opt ++ hsSourceDirs ["test"] : commonTestOptions
93+
94+main :: IO ()
95+main = defaultMain $ do
96+ props <- properties
97+ lib <- library
98+ return ( props, lib
99+ , [ githubHead "NixOS" "cabal2nix"
100+ , mkExecutable "cabal2nix" []
101+ , mkExecutable "hackage2nix" [ ghcOptions ["-threaded -rtsopts -with-rtsopts=-N"] ]
102+ , mkTest "spec" []
103+ , mkTest "doc-test" []
104+ ]
105+ )
release.nix+2
@@ -24,6 +24,8 @@ in
2424 src = cabal2nixSrc;
2525 isLibrary = false;
2626 isExecutable = true;
27+ preConfigure = "runhaskell $setupCompileFlags generate-cabal-file.hs >cabal2nix.cabal";
28+ buildTools = with haskellPackages; [ cartel pkgs.git ];
2729 buildDepends = with haskellPackages; [
2830 aeson base bytestring Cabal containers deepseq deepseq-generics
2931 directory filepath hackage-db monad-par monad-par-extras mtl pretty