Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/fetch-resolver.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@ let
rawStackYaml = builtins.readFile (srcDir + "/${stackYaml}");

# Determine the resolver as it may point to another file we need
# to look at.
# to look at. `snapshot` is the modern synonym for `resolver`
# (stack >= 2.15.1), so accept either key.
resolver =
let
# Each returns a single-element capture list (the value) or null.
matchLine = l:
let r = builtins.match "^resolver: *(.*)" l;
in if r != null then r else builtins.match "^snapshot: *(.*)" l;
rs = pkgs.lib.lists.concatLists (
pkgs.lib.lists.filter (l: l != null)
(builtins.map (l: builtins.match "^resolver: *(.*)" l)
(builtins.map matchLine
(pkgs.lib.splitString "\n" rawStackYaml)));
in
pkgs.lib.lists.head (rs ++ [ null ]);
Expand Down
5 changes: 3 additions & 2 deletions nix-tools/nix-tools/lib/Stack2nix/Stack.hs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ instance FromJSON Location where

instance FromJSON Stack where
parseJSON = withObject "Stack" $ \s -> Stack
<$> s .: "resolver"
-- `snapshot` is the modern synonym for `resolver` (stack >= 2.15.1).
<$> (s .: "resolver" <|> s .: "snapshot")
<*> s .:? "compiler" .!= Nothing
<*> ((<>) <$> s .:? "packages" .!= [LocalPath "."]
<*> s .:? "extra-deps" .!= [])
Expand All @@ -199,7 +200,7 @@ instance FromJSON Stack where

instance FromJSON StackSnapshot where
parseJSON = withObject "Snapshot" $ \s -> Snapshot
<$> s .: "resolver"
<$> (s .: "resolver" <|> s .: "snapshot")
<*> s .:? "compiler" .!= Nothing
<*> s .: "name"
<*> s .:? "packages" .!= []
Expand Down
Loading