summaryrefslogtreecommitdiffstats
path: root/krebs/5pkgs/simple/cabal-read.nix
blob: f8fc71e05c938c9a1f0a5d6de966291ff6ec8b3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{ writeHaskellPackage }:

# Because `sed -n 's/.*\<ghc-options:\s\+\(.*\)/\1/p'` is too simple.
writeHaskellPackage "cabal-read" {
  executables.ghc-options = {
    extra-depends = ["Cabal"];
    text = /* haskell */ ''
      module Main (main) where
      import Data.List
      import Data.Maybe
      import Distribution.Compiler
      import Distribution.PackageDescription.Parsec
      import Distribution.Types.BuildInfo
      import Distribution.Types.CondTree
      import Distribution.Types.Executable
      import Distribution.Types.GenericPackageDescription
      import Distribution.Types.UnqualComponentName
      import Distribution.Verbosity
      import System.Environment
      main :: IO ()
      main = do
          [path, name] <- getArgs

          desc <- readGenericPackageDescription normal path

          case lookup (mkUnqualComponentName name) (condExecutables desc) of
            Just exe ->
              putStrLn . intercalate " " . fromMaybe [] . lookup GHC
                       . options . buildInfo . condTreeData $ exe

            Nothing ->
              error ("executable " <> name <> " not found in " <> path)
    '';
  };
}