Skip to content

Commit 062d7cc

Browse files
authored
Merge pull request #105 from domenkozar/issue-94
Fixes #94
2 parents 9070f91 + 7cb2caa commit 062d7cc

File tree

5 files changed

+73
-40
lines changed

5 files changed

+73
-40
lines changed

src/Stack2nix/External/Cabal2nix.hs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
{-# LANGUAGE RecordWildCards #-}
2+
{-# LANGUAGE OverloadedStrings #-}
23

34
module Stack2nix.External.Cabal2nix (
45
cabal2nix
56
) where
67

7-
import Cabal2nix (cabal2nixWithDB)
8+
import Cabal2nix (cabal2nixWithDB, parseArgs, optNixpkgsIdentifier, Options)
9+
import Control.Lens
810
import Data.Maybe (fromMaybe)
911
import Data.Text (Text, unpack)
12+
import qualified Distribution.Nixpkgs.Haskell.Hackage as DB
13+
import Distribution.Nixpkgs.Haskell.Derivation (Derivation)
1014
import Distribution.System (Platform(..), Arch(..), OS(..))
15+
import Language.Nix
1116
import System.IO (hPutStrLn, stderr)
1217
import Stack2nix.Types (Args (..))
13-
import qualified Distribution.Nixpkgs.Haskell.Hackage as DB
14-
import Distribution.Nixpkgs.Haskell.Derivation (Derivation)
18+
1519
import Text.PrettyPrint.HughesPJClass (Doc)
1620

1721
cabal2nix :: Args -> FilePath -> Maybe Text -> Maybe FilePath -> DB.HackageDB -> IO (Either Doc Derivation)
1822
cabal2nix Args{..} uri commit subpath hackageDB = do
1923
let runCmdArgs = args $ fromMaybe "." subpath
2024
hPutStrLn stderr $ unwords ("+ cabal2nix":runCmdArgs)
21-
cabal2nixWithDB hackageDB runCmdArgs
25+
options <- parseArgs runCmdArgs
26+
cabal2nixWithDB hackageDB $ cabalOptions options
2227

2328
where
2429
args :: FilePath -> [String]
@@ -29,6 +34,13 @@ cabal2nix Args{..} uri commit subpath hackageDB = do
2934
, [uri]
3035
]
3136

37+
-- Override default nixpkgs resolver to do pkgs.attr instead of attr
38+
cabalOptions :: Options -> Options
39+
cabalOptions options =
40+
options {
41+
optNixpkgsIdentifier = \i -> Just (binding # (i, path # ["pkgs", i]))
42+
}
43+
3244
-- | Copied (and modified) from src/Distribution/Nixpkgs/Meta.hs
3345
fromCabalPlatform :: Platform -> String
3446
fromCabalPlatform (Platform I386 Linux) = "i686-linux"

src/Stack2nix/External/Stack.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import Data.Text (pack, unpack)
1616
import Distribution.Nixpkgs.Haskell.Derivation (Derivation,
1717
configureFlags)
1818
import qualified Distribution.Nixpkgs.Haskell.Hackage as DB
19-
import Distribution.Nixpkgs.Haskell.PackageSourceSpec (loadHackageDB)
2019
import Options.Applicative
2120
import Path (parseAbsFile)
2221
import Stack.Build.Source (getGhcOptions, loadSourceMapFull)
@@ -48,6 +47,7 @@ import Stack.Types.PackageIdentifier (PackageIdentifi
4847
import Stack.Types.PackageName (PackageName)
4948
import Stack.Types.Runner
5049
import Stack2nix.External.Cabal2nix (cabal2nix)
50+
import Stack2nix.Hackage (loadHackageDB)
5151
import Stack2nix.Render (render)
5252
import Stack2nix.Types (Args (..))
5353
import Stack2nix.Util (ensureExecutable,

src/Stack2nix/Hackage.hs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
-- | This module is needed to replace P.parseDB which would otherwise filter out
2+
-- deprecated packages, which may end up being in an LTS.
3+
module Stack2nix.Hackage
4+
( loadHackageDB
5+
) where
6+
7+
import Control.Exception (SomeException, mapException)
8+
import qualified Data.Map as Map
9+
import Data.Time.Clock (UTCTime)
10+
import Distribution.Hackage.DB.Path (hackageTarball)
11+
import qualified Distribution.Hackage.DB.Unparsed as U
12+
import qualified Distribution.Hackage.DB.Parsed as P
13+
import Distribution.Package (PackageName)
14+
import Distribution.Hackage.DB.Errors (HackageDBPackageName(..))
15+
import qualified Distribution.Nixpkgs.Haskell.Hackage as H
16+
17+
18+
19+
loadHackageDB :: Maybe FilePath
20+
-- ^ The path to the Hackage database.
21+
-> Maybe UTCTime
22+
-- ^ If we have hackage-snapshot time.
23+
-> IO H.HackageDB
24+
loadHackageDB optHackageDB optHackageSnapshot = do
25+
dbPath <- maybe hackageTarball return optHackageDB
26+
readTarball optHackageSnapshot dbPath
27+
28+
29+
readTarball :: Maybe UTCTime -> FilePath -> IO H.HackageDB
30+
readTarball ts p = do
31+
dbu <- U.readTarball ts p
32+
let dbp = parseDB dbu
33+
return (Map.mapWithKey (H.parsePackageData dbu) dbp)
34+
35+
36+
parseDB :: U.HackageDB -> P.HackageDB
37+
parseDB = Map.mapWithKey parsePackageData
38+
39+
parsePackageData :: PackageName -> U.PackageData -> P.PackageData
40+
parsePackageData pn (U.PackageData _ vs') =
41+
mapException (\e -> HackageDBPackageName pn (e :: SomeException)) $
42+
Map.mapWithKey (P.parseVersionData pn) $ vs'

stack.yaml

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,13 @@
1-
resolver: lts-9.20
1+
resolver: lts-12.0
22

33
packages:
44
- '.'
5-
# https://github.com/peti/hackage-db/pull/7
6-
- location:
7-
git: https://github.com/domenkozar/hackage-db
8-
commit: 0b58f1062d0a87b06bbae343d3c5a2f86ba26537
9-
extra-dep: true
10-
# https://github.com/NixOS/cabal2nix/pull/322
11-
- location:
12-
git: https://github.com/NixOS/cabal2nix
13-
commit: e72fbdfe57941627633006fa1fb4003e26619424
14-
extra-dep: true
155

166
extra-deps:
17-
- stack-1.6.3
18-
- Cabal-2.0.1.1
19-
- bindings-uname-0.1
20-
- path-0.6.1
21-
- path-io-1.3.3
22-
- ansi-terminal-0.7.1.1
23-
- ansi-wl-pprint-0.6.8.1
24-
- extra-1.6.2
25-
- hpack-0.21.2
26-
- unliftio-0.2.1.0
27-
28-
flags: {}
7+
- cabal2nix-2.10.0
298

309
nix:
3110
packages: [zlib,gmp,git,pcre,openssl]
3211

33-
extra-package-dbs: []
34-
3512
ghc-options:
3613
stack2nix: -Werror

stack2nix.cabal

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,25 @@ source-repository head
1919

2020
library
2121
hs-source-dirs: src
22-
build-depends: base >=4.9 && <4.10
23-
, Cabal >= 2.0.0.2 && < 2.1
24-
, async >= 2.1.1.1 && < 2.2
25-
, cabal2nix >= 2.7 && < 2.8
22+
build-depends: base >=4.9 && <4.12
23+
, Cabal >= 2.0.0.2 && < 2.3
24+
, async >= 2.1.1.1 && < 2.3
25+
, cabal2nix >= 2.10 && < 2.11
2626
, containers >= 0.5.7.1 && < 0.6
2727
, directory >= 1.3 && < 1.4
2828
, distribution-nixpkgs >= 1.1 && < 1.2
2929
, filepath >= 1.4.1.1 && < 1.5
30-
, optparse-applicative >= 0.13.2 && < 0.14
30+
, hackage-db
31+
, optparse-applicative >= 0.13.2 && < 0.15
3132
, pretty
3233
, path
3334
, language-nix
3435
, lens
35-
, process >= 1.4.3 && < 1.5
36+
, process >= 1.4.3 && < 1.7
3637
, regex-pcre >= 0.94.4 && < 0.95
3738
, SafeSemaphore >= 0.10.1 && < 0.11
3839
, stack >= 1.5.1
39-
, temporary >= 1.2.0.4 && < 1.3
40+
, temporary >= 1.2.0.4 && < 1.4
4041
, text >= 1.2.2.1 && < 1.3
4142
, time
4243
exposed-modules: Stack2nix
@@ -48,16 +49,17 @@ library
4849
, Stack2nix.External.Stack
4950
, Stack2nix.External.VCS.Git
5051
, Stack2nix.External.Util
52+
, Stack2nix.Hackage
5153
, Paths_stack2nix
5254
ghc-options: -Wall
5355
default-language: Haskell2010
5456

5557
executable stack2nix
5658
main-is: Main.hs
57-
build-depends: base >=4.9 && <4.10
58-
, Cabal >= 2.0.0.2 && < 2.1
59+
build-depends: base
60+
, Cabal
5961
, stack2nix
60-
, optparse-applicative >= 0.13.2 && < 0.14
62+
, optparse-applicative
6163
, time
6264
hs-source-dirs: stack2nix
6365
ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N

0 commit comments

Comments
 (0)