Skip to content

Commit 401f2c5

Browse files
committed
Better snapshot handling
1 parent 2d24020 commit 401f2c5

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

stack2nix/Main.hs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import Cabal2Nix.Util
3232

3333
import Text.PrettyPrint.ANSI.Leijen (hPutDoc, Doc)
3434
import System.IO
35-
import Data.List (isSuffixOf)
35+
import Data.List (isSuffixOf, isInfixOf)
3636
import Control.Applicative ((<|>))
3737

3838
import Distribution.Nixpkgs.Fetch
@@ -164,7 +164,19 @@ stackexpr args =
164164
do evalue <- decodeFileEither (stackFile args)
165165
case evalue of
166166
Left e -> error (show e)
167-
Right value -> stack2nix args =<< resolveSnapshot value
167+
Right value -> stack2nix args
168+
=<< cleanupStack <$> resolveSnapshot value
169+
where cleanupStack :: Stack -> Stack
170+
cleanupStack (Stack r ps es)
171+
= Stack r (cleanupPkg <$> (ps ++ [Local e | e <- es, looksLikePath e]))
172+
(cleanupExtraDep <$> [e | e <- es, not (looksLikePath e)])
173+
-- drop trailing slashes. Nix doesn't like them much;
174+
-- stack doesn't seem to care.
175+
cleanupPkg (Local p) | "/" `isSuffixOf` p = Local (take (length p - 1) p)
176+
cleanupPkg x = x
177+
cleanupExtraDep = id
178+
looksLikePath :: String -> Bool
179+
looksLikePath = isInfixOf "/"
168180

169181
stack2nix :: Args -> Stack -> IO NExpr
170182
stack2nix args stack@(Stack resolver _ _) =

0 commit comments

Comments
 (0)