summaryrefslogtreecommitdiffstats
path: root/krebs/5pkgs/simple
diff options
context:
space:
mode:
authorlassulus <lassulus@lassul.us>2018-12-04 08:08:43 +0100
committerlassulus <lassulus@lassul.us>2018-12-04 08:08:43 +0100
commitd30118879d052adb9ea59cdc1d0695b5e69664e9 (patch)
tree9c3afb51a24bc26239b8b076037d79960762b17b /krebs/5pkgs/simple
parent205e74c138d809fa1bbb8cbbc983e3344217f3be (diff)
parente8e0a68029516b3577aef5aabf818589009f334d (diff)
Merge remote-tracking branch 'ni/master'
Diffstat (limited to 'krebs/5pkgs/simple')
-rw-r--r--krebs/5pkgs/simple/cabal-read.nix35
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)
+ '';
+ };
+}