Files
haskell.nix/nix-tools/lib/StackRepos.hs
Andrea Bedini 5b7f7f245c Add 'nix-tools/' from commit '555d57e1ea81b79945f2608aa261df20f6b602a5'
git-subtree-dir: nix-tools
git-subtree-mainline: 1110a74a9d
git-subtree-split: 555d57e1ea
2022-09-15 08:11:42 +02:00

47 lines
1.2 KiB
Haskell

{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}
module StackRepos
( doStackRepos
, stack2nix
) where
import Data.Aeson (ToJSON(..))
import Data.Aeson.Encode.Pretty (encodePretty)
import qualified Data.ByteString.Lazy as LBS (writeFile)
import Data.Yaml (decodeFileEither)
import GHC.Generics (Generic)
import Stack2nix.Stack (Stack(..), Dependency(..), Location(..))
import Stack2nix.External.Resolve
import StackRepos.CLI (Args(..))
data SourceRepos = SourceRepos
{ url :: String
, rev :: String
, sha256 :: Maybe String
, subdirs :: [FilePath]
} deriving (Show, Eq, Ord, Generic)
instance ToJSON SourceRepos
doStackRepos :: Args -> IO ()
doStackRepos args = do
evalue <- decodeFileEither (argStackYaml args)
case evalue of
Left e -> error (show e)
Right value -> stack2nix args
=<< resolveSnapshot (argStackYaml args) value
stack2nix :: Args -> Stack -> IO ()
stack2nix args (Stack _ _ pkgs _ _) =
LBS.writeFile "repos.json" $ encodePretty (
pkgs >>= (\case
(DVCS (Git url rev) sha256 subdirs) ->
[SourceRepos { url, rev, sha256, subdirs }]
_ -> []))