@@ -10,6 +10,7 @@ import Distribution.NixOS.Fetch
10import Control.Exception ( bracket )
10import Control.Exception ( bracket )
11import Control.Monad ( when )
11import Control.Monad ( when )
12import Distribution.Text ( disp )
12import Distribution.Text ( disp )
13+import Distribution.NixOS.PrettyPrinting
13import System.Console.GetOpt ( OptDescr(..), ArgDescr(..), ArgOrder(..), usageInfo, getOpt )
14import System.Console.GetOpt ( OptDescr(..), ArgDescr(..), ArgOrder(..), usageInfo, getOpt )
14import System.Environment ( getArgs )
15import System.Environment ( getArgs )
15import System.Exit ( exitFailure, exitSuccess )
16import System.Exit ( exitFailure, exitSuccess )
@@ -27,6 +28,7 @@ data Configuration = Configuration
27 , optRevision :: String
28 , optRevision :: String
28 , optHyperlinkSource :: Bool
29 , optHyperlinkSource :: Bool
29 , optHackageDb :: Maybe FilePath
30 , optHackageDb :: Maybe FilePath
31+ , optNixShellOutput :: Bool
31 deriving (Show)
33 deriving (Show)
@@ -43,6 +45,7 @@ defaultConfiguration = Configuration
43 , optRevision = ""
45 , optRevision = ""
44 , optHyperlinkSource = True
46 , optHyperlinkSource = True
45 , optHackageDb = Nothing
47 , optHackageDb = Nothing
48+ , optNixShellOutput = False
48options :: [OptDescr (Configuration -> Configuration)]
51options :: [OptDescr (Configuration -> Configuration)]
@@ -58,6 +61,7 @@ options =
58 , Option "" ["no-check"] (NoArg (\o -> o { optDoCheck = False })) "don't run regression test suites of this package"
61 , Option "" ["no-check"] (NoArg (\o -> o { optDoCheck = False })) "don't run regression test suites of this package"
59 , Option "" ["rev"] (ReqArg (\x o -> o { optRevision = x }) "REVISION") "revision, only used when fetching from VCS"
62 , Option "" ["rev"] (ReqArg (\x o -> o { optRevision = x }) "REVISION") "revision, only used when fetching from VCS"
60 , Option "" ["no-hyperlink-source"] (NoArg (\o -> o { optHyperlinkSource = False })) "don't add pretty-printed source code to the documentation"
63 , Option "" ["no-hyperlink-source"] (NoArg (\o -> o { optHyperlinkSource = False })) "don't add pretty-printed source code to the documentation"
64+ , Option "" ["shell"] (NoArg (\o -> o { optNixShellOutput = True })) "generate output suitable for nix-shell"
63usage :: String
67usage :: String
@@ -107,4 +111,18 @@ main = bracket (return ()) (\() -> hFlush stdout >> hFlush stderr) $ \() -> do
107 , extraFunctionArgs = "stdenv" : extraFunctionArgs deriv
111 , extraFunctionArgs = "stdenv" : extraFunctionArgs deriv
110− putStr (show (disp (normalize deriv')))
115+ deriv'' = disp (normalize deriv')
119+ [ text "with (import <nixpkgs> {}).pkgs;"
120+ , text "let pkg = " <> hang (text "haskellngPackages.callPackage") 2 (parens (expr)) <+> braces empty <> semi
125+ deriv''' | optNixShellOutput cfg = shell deriv''
126+ | otherwise = deriv''
128+ putStrLn (show deriv''')