diff --git a/stack2nix/Stack2nix.hs b/stack2nix/Stack2nix.hs index 60f9542..5674c36 100644 --- a/stack2nix/Stack2nix.hs +++ b/stack2nix/Stack2nix.hs @@ -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) = diff --git a/stack2nix/Stack2nix/External/Resolve.hs b/stack2nix/Stack2nix/External/Resolve.hs index 3d7f6ab..f9df8ac 100644 --- a/stack2nix/Stack2nix/External/Resolve.hs +++ b/stack2nix/Stack2nix/External/Resolve.hs @@ -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 @@ -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