diff options
author | tv <tv@krebsco.de> | 2018-12-03 09:51:38 +0100 |
---|---|---|
committer | tv <tv@krebsco.de> | 2018-12-03 09:51:38 +0100 |
commit | 63798eb150e5d572ad887b2e6e6ce287fb187a48 (patch) | |
tree | 343ca69a402294a9c57cb722fbb9504e907e2b52 /krebs | |
parent | 24b07c32840949dbd02a8282d0b5d9cbe1c01bf5 (diff) |
cabal-read: init
Diffstat (limited to 'krebs')
-rw-r--r-- | krebs/5pkgs/simple/cabal-read.nix | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/krebs/5pkgs/simple/cabal-read.nix b/krebs/5pkgs/simple/cabal-read.nix new file mode 100644 index 000000000..f8fc71e05 --- /dev/null +++ b/krebs/5pkgs/simple/cabal-read.nix @@ -0,0 +1,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) + ''; + }; +} |