Skip to content

Commit e5e929b

Browse files
authored
Merge pull request #115 from puffnfresh/feature/compiler-cabal2nix
Pass --compiler to calls to cabal2nix
2 parents a452c8a + 25e57a9 commit e5e929b

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

src/Stack2nix/External/Cabal2nix.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ import Distribution.Nixpkgs.Haskell.Derivation (Derivation)
1414
import Distribution.System (Platform(..), Arch(..), OS(..))
1515
import Language.Nix
1616
import System.IO (hPutStrLn, stderr)
17+
import Stack.Types.Version (Version)
1718
import Stack2nix.Types (Args (..))
1819

1920
import Text.PrettyPrint.HughesPJClass (Doc)
2021

21-
cabal2nix :: Args -> FilePath -> Maybe Text -> Maybe FilePath -> DB.HackageDB -> IO (Either Doc Derivation)
22-
cabal2nix Args{..} uri commit subpath hackageDB = do
22+
cabal2nix :: Args -> Version -> FilePath -> Maybe Text -> Maybe FilePath -> DB.HackageDB -> IO (Either Doc Derivation)
23+
cabal2nix Args{..} ghcVersion uri commit subpath hackageDB = do
2324
let runCmdArgs = args $ fromMaybe "." subpath
2425
hPutStrLn stderr $ unwords ("+ cabal2nix":runCmdArgs)
2526
options <- parseArgs runCmdArgs
@@ -31,6 +32,7 @@ cabal2nix Args{..} uri commit subpath hackageDB = do
3132
[ maybe [] (\c -> ["--revision", unpack c]) commit
3233
, ["--subpath", dir]
3334
, ["--system", fromCabalPlatform argPlatform]
35+
, ["--compiler", "ghc-" ++ show ghcVersion]
3436
, [uri]
3537
]
3638

src/Stack2nix/External/Stack.hs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ import Stack.Runners (loadCompilerVer
3030
withBuildConfig)
3131
import Stack.Types.BuildPlan (PackageLocation (..),
3232
Repo (..))
33-
import Stack.Types.Compiler (CVType (..),
34-
CompilerVersion,
35-
getGhcVersion)
33+
import Stack.Types.Compiler (getGhcVersion)
3634
import Stack.Types.Config
3735
import Stack.Types.Config.Build (BuildCommand (..))
3836
import Stack.Types.Nix
@@ -46,6 +44,7 @@ import Stack.Types.PackageIdentifier (PackageIdentifi
4644
packageIdentifierString)
4745
import Stack.Types.PackageName (PackageName)
4846
import Stack.Types.Runner
47+
import Stack.Types.Version (Version)
4948
import Stack2nix.External.Cabal2nix (cabal2nix)
5049
import Stack2nix.Hackage (loadHackageDB)
5150
import Stack2nix.Render (render)
@@ -66,20 +65,20 @@ data PackageRef
6665
| NonHackagePackage PackageIdentifier (PackageLocation FilePath)
6766
deriving (Eq, Show)
6867

69-
genNixFile :: Args -> FilePath -> Maybe String -> Maybe String -> DB.HackageDB -> PackageRef -> IO (Either Doc Derivation)
70-
genNixFile args baseDir uri argRev hackageDB pkgRef = do
68+
genNixFile :: Args -> Version -> FilePath -> Maybe String -> Maybe String -> DB.HackageDB -> PackageRef -> IO (Either Doc Derivation)
69+
genNixFile args ghcVersion baseDir uri argRev hackageDB pkgRef = do
7170
cwd <- getCurrentDirectory
7271
case pkgRef of
7372
NonHackagePackage _ident PLArchive {} -> error "genNixFile: No support for archive package locations"
7473
HackagePackage (PackageIdentifierRevision pkg _) ->
75-
cabal2nix args ("cabal://" <> packageIdentifierString pkg) Nothing Nothing hackageDB
74+
cabal2nix args ghcVersion ("cabal://" <> packageIdentifierString pkg) Nothing Nothing hackageDB
7675
NonHackagePackage _ident (PLRepo repo) ->
77-
cabal2nix args (unpack $ repoUrl repo) (Just $ repoCommit repo) (Just (repoSubdirs repo)) hackageDB
76+
cabal2nix args ghcVersion (unpack $ repoUrl repo) (Just $ repoCommit repo) (Just (repoSubdirs repo)) hackageDB
7877
NonHackagePackage _ident (PLFilePath path) -> do
7978
relPath <- makeRelativeToCurrentDirectory path
8079
projRoot <- canonicalizePath $ cwd </> baseDir
8180
let defDir = baseDir </> makeRelative projRoot path
82-
cabal2nix args (fromMaybe defDir uri) (pack <$> argRev) (const relPath <$> uri) hackageDB
81+
cabal2nix args ghcVersion (fromMaybe defDir uri) (pack <$> argRev) (const relPath <$> uri) hackageDB
8382

8483
-- TODO: remove once we use flags, options
8584
sourceMapToPackages :: Map PackageName PackageSource -> [PackageRef]
@@ -99,9 +98,9 @@ planAndGenerate
9998
-> FilePath
10099
-> Maybe String
101100
-> Args
102-
-> String
101+
-> Version
103102
-> RIO env ()
104-
planAndGenerate boptsCli baseDir remoteUri args@Args {..} ghcnixversion = do
103+
planAndGenerate boptsCli baseDir remoteUri args@Args {..} ghcVersion = do
105104
(_targets, _mbp, _locals, _extraToBuild, sourceMap) <- loadSourceMapFull
106105
NeedTargets
107106
boptsCli
@@ -114,11 +113,11 @@ planAndGenerate boptsCli baseDir remoteUri args@Args {..} ghcnixversion = do
114113
argThreads
115114
(\p ->
116115
fmap (addGhcOptions buildConf p)
117-
<$> genNixFile args baseDir remoteUri argRev hackageDB p
116+
<$> genNixFile args ghcVersion baseDir remoteUri argRev hackageDB p
118117
)
119118
pkgs
120119
let locals = map (\l -> show (packageName (lpPackage l))) _locals
121-
liftIO $ render drvs args locals ghcnixversion
120+
liftIO . render drvs args locals $ nixVersion ghcVersion
122121

123122
-- | Add ghc-options declared in stack.yaml to the nix derivation for a package
124123
-- by adding to the configureFlags attribute of the derivation
@@ -150,18 +149,22 @@ runPlan baseDir remoteUri args@Args{..} = do
150149
let stackFile = baseDir </> argStackYaml
151150

152151
ghcVersion <- getGhcVersionIO globals stackFile
153-
let ghcnixversion = filter (/= '.') $ show (getGhcVersion ghcVersion)
154-
ensureExecutable ("haskell.compiler.ghc" ++ ghcnixversion)
155-
withBuildConfig globals $ planAndGenerate buildOpts baseDir remoteUri args ghcnixversion
152+
-- let ghcnixversion = filter (/= '.') $ show (getGhcVersion ghcVersion)
153+
ensureExecutable ("haskell.compiler.ghc" ++ nixVersion ghcVersion)
154+
withBuildConfig globals $ planAndGenerate buildOpts baseDir remoteUri args ghcVersion
156155

157-
getGhcVersionIO :: GlobalOpts -> FilePath -> IO (CompilerVersion 'CVWanted)
156+
nixVersion :: Version -> String
157+
nixVersion =
158+
filter (/= '.') . show
159+
160+
getGhcVersionIO :: GlobalOpts -> FilePath -> IO Version
158161
getGhcVersionIO go stackFile = do
159162
cp <- canonicalizePath stackFile
160163
fp <- parseAbsFile cp
161164
lc <- withRunner LevelError True False ColorAuto Nothing False $ \runner ->
162165
-- https://www.fpcomplete.com/blog/2017/07/the-rio-monad
163166
runRIO runner $ loadConfig mempty Nothing (SYLOverride fp)
164-
loadCompilerVersion go lc
167+
getGhcVersion <$> loadCompilerVersion go lc
165168

166169
globalOpts :: FilePath -> FilePath -> Args -> GlobalOpts
167170
globalOpts currentDir stackRoot Args{..} =

0 commit comments

Comments
 (0)