stack2nix 0.2.1 → 0.2.2
raw patch · 6 files changed
+55/−38 lines, 6 filesdep ~Cabaldep ~basedep ~containers
Dependency ranges changed: Cabal, base, containers, distribution-nixpkgs, stack
Files
- ChangeLog.md +9/−0
- README.md +3/−9
- src/Stack2nix/External/Cabal2nix.hs +6/−3
- src/Stack2nix/External/Stack.hs +25/−17
- src/Stack2nix/Types.hs +5/−2
- stack2nix.cabal +7/−7
ChangeLog.md view
@@ -1,5 +1,14 @@ # Changelog +## v0.2.2 (2019-01-17)++Bug fixes:++- LTS-13 compatibility+- Proper fix for bin-package-db #118+- Add package flags #148+- Upgrade stack to 1.9 #133+ ## v0.2.1 (2018-09-04) Bug fixes:
README.md view
@@ -1,6 +1,7 @@ # stack2nix [](https://travis-ci.org/input-output-hk/stack2nix)+[](https://hackage.haskell.org/package/stack2nix) ## About @@ -14,7 +15,7 @@ ## Installation -There are three options. The first - using Nix is recommended. If there are difficulties please file an issue.+There are two options. The first - using Nix is recommended. If there are difficulties please file an issue. ## Nix (recommended) @@ -22,18 +23,11 @@ 2. Clone this repo. 3. Run `nix-build` to build. -### Stack+### Stack + Nix 1. Install [Nix](https://nixos.org/nix/). 2. Clone this repo. 3. Run `stack install --nix` to install.--### Virtual Machine--1. Install [VirtualBox](https://www.virtualbox.org/wiki/VirtualBox) and [Vagrant](https://www.vagrantup.com/).-2. Clone this repo.-3. Run `./scripts/vagrant.sh` and take a coffee break.-4. If there are no errors, log into the VM: `vagrant ssh`. ## Usage
src/Stack2nix/External/Cabal2nix.hs view
@@ -7,20 +7,22 @@ import Cabal2nix (cabal2nixWithDB, parseArgs, optNixpkgsIdentifier, Options) import Control.Lens+import Data.Bool (bool) import Data.Maybe (fromMaybe) 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.System (Platform(..), Arch(..), OS(..)) import Language.Nix import System.IO (hPutStrLn, stderr) import Stack.Types.Version (Version)-import Stack2nix.Types (Args (..))+import Stack2nix.Types (Args (..), Flags) import Text.PrettyPrint.HughesPJClass (Doc) -cabal2nix :: Args -> Version -> FilePath -> Maybe Text -> Maybe FilePath -> DB.HackageDB -> IO (Either Doc Derivation)-cabal2nix Args{..} ghcVersion uri commit subpath hackageDB = do+cabal2nix :: Args -> Version -> FilePath -> Maybe Text -> Maybe FilePath -> Flags -> DB.HackageDB -> IO (Either Doc Derivation)+cabal2nix Args{..} ghcVersion uri commit subpath flags hackageDB = do let runCmdArgs = args $ fromMaybe "." subpath hPutStrLn stderr $ unwords ("+ cabal2nix":runCmdArgs) options <- parseArgs runCmdArgs@@ -33,6 +35,7 @@ , ["--subpath", dir] , ["--system", fromCabalPlatform argPlatform] , ["--compiler", "ghc-" ++ show ghcVersion]+ , ["-f" ++ bool "-" "" enable ++ unFlagName f | (f, enable) <- flags] , [uri] ]
src/Stack2nix/External/Stack.hs view
@@ -33,22 +33,24 @@ import Stack.Types.Compiler (getGhcVersion) import Stack.Types.Config import Stack.Types.Config.Build (BuildCommand (..))+import Stack.Types.FlagName (toCabalFlagName) import Stack.Types.Nix import Stack.Types.Package (PackageSource (..), lpLocation, lpPackage,+ packageFlags, packageName, packageVersion) import Stack.Types.PackageIdentifier (PackageIdentifier (..), PackageIdentifierRevision (..), packageIdentifierString)-import Stack.Types.PackageName (PackageName)+import Stack.Types.PackageName (PackageName, parsePackageName) import Stack.Types.Runner import Stack.Types.Version (Version) import Stack2nix.External.Cabal2nix (cabal2nix) import Stack2nix.Hackage (loadHackageDB) import Stack2nix.Render (render)-import Stack2nix.Types (Args (..))+import Stack2nix.Types (Args (..), Flags) import Stack2nix.Util (ensureExecutable, logDebug, mapPool)@@ -61,35 +63,37 @@ import Text.PrettyPrint.HughesPJClass (Doc) data PackageRef- = HackagePackage PackageIdentifierRevision- | NonHackagePackage PackageIdentifier (PackageLocation FilePath)+ = HackagePackage Flags PackageIdentifierRevision+ | NonHackagePackage Flags PackageIdentifier (PackageLocation FilePath) deriving (Eq, Show) genNixFile :: Args -> Version -> FilePath -> Maybe String -> Maybe String -> DB.HackageDB -> PackageRef -> IO (Either Doc Derivation) genNixFile args ghcVersion baseDir uri argRev hackageDB pkgRef = do cwd <- getCurrentDirectory case pkgRef of- NonHackagePackage _ident PLArchive {} -> error "genNixFile: No support for archive package locations"- HackagePackage (PackageIdentifierRevision pkg _) ->- cabal2nix args ghcVersion ("cabal://" <> packageIdentifierString pkg) Nothing Nothing hackageDB- NonHackagePackage _ident (PLRepo repo) ->- cabal2nix args ghcVersion (unpack $ repoUrl repo) (Just $ repoCommit repo) (Just (repoSubdirs repo)) hackageDB- NonHackagePackage _ident (PLFilePath path) -> do+ NonHackagePackage _flags _ident PLArchive {} -> error "genNixFile: No support for archive package locations"+ HackagePackage flags (PackageIdentifierRevision pkg _) ->+ cabal2nix args ghcVersion ("cabal://" <> packageIdentifierString pkg) Nothing Nothing flags hackageDB+ NonHackagePackage flags _ident (PLRepo repo) ->+ cabal2nix args ghcVersion (unpack $ repoUrl repo) (Just $ repoCommit repo) (Just (repoSubdirs repo)) flags hackageDB+ NonHackagePackage flags _ident (PLFilePath path) -> do relPath <- makeRelativeToCurrentDirectory path projRoot <- canonicalizePath $ cwd </> baseDir let defDir = baseDir </> makeRelative projRoot path- cabal2nix args ghcVersion (fromMaybe defDir uri) (pack <$> argRev) (const relPath <$> uri) hackageDB+ cabal2nix args ghcVersion (fromMaybe defDir uri) (pack <$> argRev) (const relPath <$> uri) flags hackageDB -- TODO: remove once we use flags, options sourceMapToPackages :: Map PackageName PackageSource -> [PackageRef] sourceMapToPackages = map sourceToPackage . M.elems where sourceToPackage :: PackageSource -> PackageRef- sourceToPackage (PSIndex _ _flags _options pir) = HackagePackage pir+ sourceToPackage (PSIndex _ flags _options pir) = HackagePackage (toCabalFlags flags) pir sourceToPackage (PSFiles lp _) = let pkg = lpPackage lp ident = PackageIdentifier (packageName pkg) (packageVersion pkg)- in NonHackagePackage ident (lpLocation lp)+ in NonHackagePackage (toCabalFlags $ packageFlags pkg) ident (lpLocation lp)+ toCabalFlags fs = [ (toCabalFlagName f0, enabled)+ | (f0, enabled) <- M.toList fs ] planAndGenerate@@ -104,7 +108,10 @@ (_targets, _mbp, _locals, _extraToBuild, sourceMap) <- loadSourceMapFull NeedTargets boptsCli- let pkgs = sourceMapToPackages sourceMap++ -- Stackage lists bin-package-db but it's in GHC 7.10's boot libraries+ binPackageDb <- parsePackageName "bin-package-db"+ let pkgs = sourceMapToPackages (M.delete binPackageDb sourceMap) liftIO $ logDebug args $ "plan:\n" ++ show pkgs hackageDB <- liftIO $ loadHackageDB Nothing argHackageSnapshot@@ -135,8 +142,8 @@ False pkgName :: PackageName pkgName = case pkgRef of- HackagePackage (PackageIdentifierRevision (PackageIdentifier n _) _) -> n- NonHackagePackage (PackageIdentifier n _) _ -> n+ HackagePackage _ (PackageIdentifierRevision (PackageIdentifier n _) _) -> n+ NonHackagePackage _ (PackageIdentifier n _) _ -> n runPlan :: FilePath -> Maybe String@@ -186,7 +193,8 @@ , ["--haddock" | argHaddock] , ["--no-install-ghc"] ]- go = globalOptsFromMonoid False . fromJust . getParseResult $ execParserPure defaultPrefs pinfo args+ go = globalOptsFromMonoid False ColorNever . fromJust . getParseResult $+ execParserPure defaultPrefs pinfo args buildOpts :: BuildOptsCLI buildOpts = fromJust . getParseResult $ execParserPure defaultPrefs (info (buildOptsParser Build) briefDesc) ["--dry-run"]
src/Stack2nix/Types.hs view
@@ -1,7 +1,8 @@ module Stack2nix.Types where -import Data.Time (UTCTime)-import Distribution.System (Platform)+import Data.Time (UTCTime)+import Distribution.PackageDescription (FlagName)+import Distribution.System (Platform) data Args = Args { argRev :: Maybe String@@ -18,3 +19,5 @@ , argVerbose :: Bool } deriving (Show)++type Flags = [(FlagName, Bool)]
stack2nix.cabal view
@@ -1,11 +1,11 @@ name: stack2nix-version: 0.2.1+version: 0.2.2 synopsis: Convert stack.yaml files into Nix build instructions. description: Convert stack.yaml files into Nix build instructions. license: MIT license-file: LICENSE-author: Jacob Mitchell-maintainer: jacob.mitchell@iohk.io+author: IOHK DevOps+maintainer: stack2nix@iohk.io category: Distribution, Nix build-type: Simple extra-source-files:@@ -19,11 +19,11 @@ library hs-source-dirs: src- build-depends: base >=4.9 && <4.12- , Cabal >= 2.0.0.2 && < 2.3+ build-depends: base >=4.9 && <4.13+ , Cabal >= 2.0.0.2 && < 2.5 , async >= 2.1.1.1 && < 2.3 , cabal2nix >= 2.10- , containers >= 0.5.7.1 && < 0.6+ , containers >= 0.5.7.1 && < 0.7 , directory >= 1.3 && < 1.4 , distribution-nixpkgs >= 1.1 && < 1.2 , filepath >= 1.4.1.1 && < 1.5@@ -36,7 +36,7 @@ , process >= 1.4.3 && < 1.7 , regex-pcre >= 0.94.4 && < 0.95 , SafeSemaphore >= 0.10.1 && < 0.11- , stack >= 1.5.1+ , stack >= 1.9 , temporary >= 1.2.0.4 && < 1.4 , text >= 1.2.2.1 && < 1.3 , time