@@ -10,6 +10,7 @@ import Distribution.NixOS.Fetch
1010import Control.Exception ( bracket )
1111import Control.Monad ( when )
1212import Distribution.Text ( disp )
13+import Distribution.NixOS.PrettyPrinting
1314import System.Console.GetOpt ( OptDescr(..), ArgDescr(..), ArgOrder(..), usageInfo, getOpt )
1415import System.Environment ( getArgs )
1516import System.Exit ( exitFailure, exitSuccess )
@@ -27,6 +28,7 @@ data Configuration = Configuration
2728 , optRevision :: String
2829 , optHyperlinkSource :: Bool
2930 , optHackageDb :: Maybe FilePath
31+ , optNixShellOutput :: Bool
3032 }
3133 deriving (Show)
3234
@@ -43,6 +45,7 @@ defaultConfiguration = Configuration
4345 , optRevision = ""
4446 , optHyperlinkSource = True
4547 , optHackageDb = Nothing
48+ , optNixShellOutput = False
4649 }
4750
4851options :: [OptDescr (Configuration -> Configuration)]
@@ -58,6 +61,7 @@ options =
5861 , Option "" ["no-check"] (NoArg (\o -> o { optDoCheck = False })) "don't run regression test suites of this package"
5962 , Option "" ["rev"] (ReqArg (\x o -> o { optRevision = x }) "REVISION") "revision, only used when fetching from VCS"
6063 , 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"
6165 ]
6266
6367usage :: String
@@ -107,4 +111,18 @@ main = bracket (return ()) (\() -> hFlush stdout >> hFlush stderr) $ \() -> do
107111 , extraFunctionArgs = "stdenv" : extraFunctionArgs deriv
108112 }
109113
110− putStr (show (disp (normalize deriv')))
114+ deriv'' :: Doc
115+ deriv'' = disp (normalize deriv')
116+
117+ shell :: Doc -> Doc
118+ shell expr = vcat
119+ [ text "with (import <nixpkgs> {}).pkgs;"
120+ , text "let pkg = " <> hang (text "haskellngPackages.callPackage") 2 (parens (expr)) <+> braces empty <> semi
121+ , text "in"
122+ , text " pkg.env"
123+ ]
124+
125+ deriv''' | optNixShellOutput cfg = shell deriv''
126+ | otherwise = deriv''
127+
128+ putStrLn (show deriv''')