Skip to content

Commit

Permalink
Resolve local file snapshots relative to stack.yaml (input-output-hk#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
kirelagin authored and angerman committed Nov 30, 2019
1 parent 1b3d624 commit cee8245
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion stack2nix/Stack2nix.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ stackexpr args =
case evalue of
Left e -> error (show e)
Right value -> stack2nix args
=<< resolveSnapshot value
=<< resolveSnapshot (argStackYaml args) value

stack2nix :: Args -> Stack -> IO NExpr
stack2nix args stack@(Stack resolver compiler pkgs pkgFlags ghcOpts) =
Expand Down
9 changes: 6 additions & 3 deletions stack2nix/Stack2nix/External/Resolve.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Data.Aeson
import Data.Yaml hiding (Parser)
import Control.Applicative ((<|>))
import Data.List (isPrefixOf, isSuffixOf)
import System.FilePath ((</>), dropFileName)

import qualified Data.ByteString.Lazy.Char8 as L8

Expand Down Expand Up @@ -34,15 +35,17 @@ decodeURLEither url
-- | If a stack.yaml file contains a @resolver@ that points to
-- a file, resolve that file and merge the snapshot into the
-- @Stack@ record.
resolveSnapshot :: Stack -> IO Stack
resolveSnapshot stack@(Stack resolver compiler pkgs flags ghcOptions)
resolveSnapshot :: FilePath -> Stack -> IO Stack
resolveSnapshot stackYaml stack@(Stack resolver compiler pkgs flags ghcOptions)
= if ".yaml" `isSuffixOf` resolver
then do evalue <- if ("http://" `isPrefixOf` resolver) || ("https://" `isPrefixOf` resolver)
then decodeURLEither resolver
else decodeFileEither resolver
else decodeFileEither (srcDir </> resolver)
case evalue of
Left e -> error (show e)
Right (Snapshot resolver' compiler' _name pkgs' flags' ghcOptions') ->
pure $ Stack resolver' (compiler' <|> compiler) (pkgs <> pkgs') (flags <> flags')
(ghcOptions <> ghcOptions')
else pure stack
where
srcDir = dropFileName stackYaml

0 comments on commit cee8245

Please sign in to comment.