@@ -11,34 +11,47 @@ import Distribution.Nixpkgs.Haskell.Stack
11import Distribution.System as System
11import Distribution.System as System
12import qualified Distribution.Text as Text
12import qualified Distribution.Text as Text
13import Options.Applicative as Opts
13import Options.Applicative as Opts
15import Stack.Types
14import Stack.Types
15+import System.Environment
16+import System.FilePath
18data Options = Options
19data Options = Options
19− { _optOutFile :: !FilePath
20+ { _optAllCabalHashesRepo :: !FilePath
21+ , _optLtsHaskellRepo :: !FilePath
22+ , _optOutStackagePackages :: !FilePath
23+ , _optOutStackageConfig :: !FilePath
24+ , _optOutDerivation :: !FilePath
20 , _optHackageDb :: !(Maybe HackageDb)
25 , _optHackageDb :: !(Maybe HackageDb)
21 , _optNixpkgsRepository :: !FilePath
26 , _optNixpkgsRepository :: !FilePath
22− , _optAllCabalHashesPath :: !FilePath
23− , _optLtsHaskellPath :: !FilePath
24− , _optStackageOutPackages :: !FilePath
25− , _optStackageOutConfig :: !FilePath
26 , _optCompilerId :: !CompilerId
27 , _optCompilerId :: !CompilerId
27 , _optPlatform :: !Platform
28 , _optPlatform :: !Platform
28− , _optStackYaml :: !FilePath
29+ , _optStackYamlArg :: !FilePath
29 } deriving (Show)
30 } deriving (Show)
31makeLenses ''Options
32makeLenses ''Options
34+envStackYaml :: IO (Maybe FilePath)
35+envStackYaml = lookupEnv "STACK_YAML"
37+optStackYaml :: Getter Options FilePath
38+optStackYaml = optStackYamlArg . to stackYamlFile
40+ stackYamlFile p = case splitFileName p of
41+ (dir, "") -> dir </> "stack.yaml"
42+ (dir, ".") -> dir </> "stack.yaml"
43+ (_ , "..") -> p </> "stack.yaml"
33options :: Parser Options
46options :: Parser Options
34options = Options
47options = Options
35− <$> outFile
48+ <$> allCabalHashesRepo
50+ <*> outStackagePackages
51+ <*> outStackageConfig
36 <*> optional hackageDb
53 <*> optional hackageDb
37 <*> nixpkgsRepository
54 <*> nixpkgsRepository
38− <*> allCabalHashesPath
40− <*> stackageOutPackages
41− <*> stackageOutConfig
42 <*> compilerId
55 <*> compilerId
43 <*> platform
56 <*> platform
44 <*> stackYamlArg
57 <*> stackYamlArg
@@ -50,14 +63,6 @@ pinfo = info
50 ( fullDesc
63 ( fullDesc
51 <> header "stack2nix converts Stack files into build instructions for Nix." )
64 <> header "stack2nix converts Stack files into build instructions for Nix." )
53−outFile :: Parser FilePath
55− ( long "nix-out-file"
56− <> metavar "NIX_OUT_FILE"
57− <> help "path to output derivation"
58− <> value "default.nix"
59− <> showDefaultWith id )
61nixpkgsRepository :: Parser FilePath
66nixpkgsRepository :: Parser FilePath
62nixpkgsRepository = option str
67nixpkgsRepository = option str
63 ( long "nixpkgs"
68 ( long "nixpkgs"
@@ -66,51 +71,48 @@ nixpkgsRepository = option str
66 <> value "<nixpkgs>"
71 <> value "<nixpkgs>"
67 <> showDefaultWith id )
72 <> showDefaultWith id )
69−stackageBuildPlan :: Parser FilePath
74+allCabalHashesRepo :: Parser FilePath
70−stackageBuildPlan = option str
75+allCabalHashesRepo = option str
71− ( long "stackage-build-plan"
72− <> metavar "STACKAGE_BUILD_PLAN"
73− <> help "stackage build plan (YAML)" )
75−allCabalHashesPath :: Parser FilePath
76−allCabalHashesPath = option str
77 ( long "all-cabal-hashes"
76 ( long "all-cabal-hashes"
78− <> metavar "ALL_CABAL_HASHES"
77+ <> metavar "REPO_DIR"
79 <> help "path to commercialhaskell/all-cabal-hashes repository" )
78 <> help "path to commercialhaskell/all-cabal-hashes repository" )
81−ltsHaskellPath :: Parser FilePath
80+ltsHaskellRepo :: Parser FilePath
82−ltsHaskellPath = option str
81+ltsHaskellRepo = option str
83 ( long "lts-haskell"
82 ( long "lts-haskell"
84− <> metavar "LTS_HASKELL_DIR"
83+ <> metavar "REPO_DIR"
85 <> help "path to fpco/lts-haskell repository" )
84 <> help "path to fpco/lts-haskell repository" )
87−stackResolver :: Parser StackResolver
88−stackResolver = StackResolver <$>
91− <> metavar "RESOLVER"
92− <> help "override stack resolver" )
94−stackageOutPackages :: Parser FilePath
86+outStackagePackages :: Parser FilePath
95−stackageOutPackages = option str
87+outStackagePackages = option str
96− ( long "nix-stackage-packages"
88+ ( long "out-packages"
97− <> metavar "STACKAGE_PACKAGES"
89+ <> metavar "NIX_FILE"
98− <> help "name of the output file for the package set"
90+ <> help "output file of the stackage packages set"
99 <> value "packages.nix"
91 <> value "packages.nix"
100 <> showDefaultWith id)
92 <> showDefaultWith id)
102−stackageOutConfig :: Parser FilePath
94+outStackageConfig :: Parser FilePath
103−stackageOutConfig = option str
95+outStackageConfig = option str
104− ( long "nix-stackage-config"
96+ ( long "out-config"
105− <> metavar "STACKAGE_CONFIG"
97+ <> metavar "NIX_FILE"
106− <> help "name of the output file for the package set configuration"
98+ <> help "output file of the stackage packages compiler config"
107 <> value "configuration-packages.nix"
99 <> value "configuration-packages.nix"
108 <> showDefaultWith id)
100 <> showDefaultWith id)
102+outDerivation :: Parser FilePath
103+outDerivation = option str
104+ ( long "out-derivation"
105+ <> metavar "NIX_FILE"
106+ <> help "path to output derivation"
107+ <> value "default.nix"
108+ <> showDefaultWith id )
110stackYamlArg :: Parser FilePath
110stackYamlArg :: Parser FilePath
111stackYamlArg = Opts.argument str
111stackYamlArg = Opts.argument str
112 ( metavar "STACK_YAML"
112 ( metavar "STACK_YAML"
113− <> value "stack.yaml" )
113+ <> help "path to stack.yaml file or directory" )
115+-- inherited from cabal2nix
115hackageDb :: Parser HackageDb
117hackageDb :: Parser HackageDb
116hackageDb = HackageDb <$>
118hackageDb = HackageDb <$>
@@ -140,6 +142,8 @@ platform = option (readP Text.parse)
140 <> value buildPlatform
142 <> value buildPlatform
141 <> showDefaultWith Text.display )
143 <> showDefaultWith Text.display )
143text :: ReadM Text
147text :: ReadM Text
144text = T.pack <$> str
148text = T.pack <$> str