mirror of
https://github.com/justinwoo/spago2nix.git
synced 2024-11-25 10:03:17 +03:00
pass through extra spago flags on generate
This commit is contained in:
parent
1ed1a955bc
commit
8e961bc055
@ -9,7 +9,9 @@ import Core (FetchResult(..), MyError(..), NixPrefetchGitResult, Package, Repo(.
|
||||
import Data.Array as Array
|
||||
import Data.Bifunctor (lmap)
|
||||
import Data.Either (Either(..))
|
||||
import Data.Maybe (Maybe(..))
|
||||
import Data.List (List)
|
||||
import Data.List as List
|
||||
import Data.Maybe (Maybe(..), maybe)
|
||||
import Data.String as String
|
||||
import Data.Traversable (traverse, traverse_)
|
||||
import Data.Validation.Semigroup (V(..), toEither)
|
||||
@ -40,12 +42,12 @@ brokenRepoSHA = SHA256 "0sjjj9z1dhilhpc8pq4154czrb79z9cm044jvn75kxcjv6v5l2m5"
|
||||
-- "sha256": "0sjjj9z1dhilhpc8pq4154czrb79z9cm044jvn75kxcjv6v5l2m5",
|
||||
-- }
|
||||
|
||||
spagoListPackages :: Aff (Either MyError (Array Package))
|
||||
spagoListPackages = do
|
||||
spagoListPackages :: Maybe SpagoArgs -> Aff (Either MyError (Array Package))
|
||||
spagoListPackages mSpagoArgs = do
|
||||
error "getting packages.."
|
||||
output <- S.spawn
|
||||
{ cmd: "spago"
|
||||
, args: [ "ls", "deps", "--json", "--transitive" ]
|
||||
, args: [ "ls", "deps", "--json", "--transitive" ] <> spagoArgs
|
||||
, stdin: Nothing
|
||||
}
|
||||
CP.defaultSpawnOptions
|
||||
@ -60,6 +62,7 @@ spagoListPackages = do
|
||||
error output.stderr
|
||||
pure $ Left $ SpagoRunError (show e)
|
||||
where
|
||||
spagoArgs = maybe [] unSpagoArgs mSpagoArgs
|
||||
words :: String -> Array String
|
||||
words = String.split (String.Pattern "\n") <<< String.trim
|
||||
|
||||
@ -236,10 +239,10 @@ chunk n xs | n < 1 = [xs]
|
||||
chunk' acc [] = acc
|
||||
chunk' acc rest = chunk' (acc <> [Array.take n rest]) (Array.drop n rest)
|
||||
|
||||
generate :: Int -> Aff Unit
|
||||
generate maxProcs = do
|
||||
generate :: Int -> Maybe SpagoArgs -> Aff Unit
|
||||
generate maxProcs mSpagoArgs = do
|
||||
ensureSetup
|
||||
packages <- exitOnError spagoListPackages
|
||||
packages <- exitOnError $ spagoListPackages mSpagoArgs
|
||||
fetches <- toResult <$> concatMapM (parTraverse ensureFetchPackage) (chunk maxProcs packages)
|
||||
case fetches of
|
||||
Left errors -> do
|
||||
@ -263,3 +266,16 @@ generate maxProcs = do
|
||||
Left e -> do
|
||||
error $ show e
|
||||
exit 1
|
||||
|
||||
-- extra args we parse out to pass to spago if needed
|
||||
newtype SpagoArgs = SpagoArgs (List String)
|
||||
|
||||
unSpagoArgs :: SpagoArgs -> Array String
|
||||
unSpagoArgs (SpagoArgs xs) = List.toUnfoldable xs
|
||||
|
||||
parseSpagoArgs :: List String -> Maybe SpagoArgs
|
||||
parseSpagoArgs xs = go xs
|
||||
where
|
||||
go (List.Cons "--" rest) = Just $ SpagoArgs rest
|
||||
go (List.Cons _ rest) = go rest
|
||||
go List.Nil = Nothing
|
||||
|
@ -41,12 +41,14 @@ generate extraArgs = do
|
||||
log $ "Expected an integer, but got: " <> List.intercalate " " extraArgs
|
||||
log $ "Specify the maximum number of packages to fetch simultaneously."
|
||||
exit 1
|
||||
Just n -> Generate.generate n
|
||||
Just n -> do
|
||||
let spagoArgs = Generate.parseSpagoArgs extraArgs
|
||||
Generate.generate n spagoArgs
|
||||
where
|
||||
parse :: List String -> Maybe Int
|
||||
parse List.Nil = Just 0
|
||||
parse (List.Cons arg List.Nil) = Int.fromString arg
|
||||
parse _ = Nothing
|
||||
parse (List.Cons "--" _) = Just 0
|
||||
parse (List.Cons arg _) = Int.fromString arg
|
||||
|
||||
install :: List String -> Aff Unit
|
||||
install extraArgs = do
|
||||
@ -125,9 +127,10 @@ help = """spago2nix - generate Nix derivations from packages required in a spago
|
||||
Usage: spago2nix (generate | install | build)
|
||||
|
||||
Available commands:
|
||||
generate [n]
|
||||
generate [n] [--] [pass-through spago args]
|
||||
Generate a Nix expression of packages from Spago. If n is
|
||||
given, it will limit the number of packages fetched at once.
|
||||
Pass extra flags to Spago by specifying more after `--`.
|
||||
install [passthrough args for nix-shell]
|
||||
Install dependencies from spago-packages.nix in Spago style
|
||||
build [passthrough args for nix-shell]
|
||||
|
Loading…
Reference in New Issue
Block a user