@@ -15,6 +15,13 @@ import System.FilePath
15
15
import Data.ByteString (ByteString )
16
16
import Data.Maybe (catMaybes , maybeToList )
17
17
import Data.Foldable (toList )
18
+ import Distribution.Package
19
+ ( packageName , packageVersion )
20
+ import Distribution.Pretty (prettyShow )
21
+ import qualified System.FilePath.Posix as FilePath.Posix
22
+ ( combine , joinPath , splitDirectories )
23
+ import Network.URI
24
+ ( URI (uriAuthority , uriPath ), URIAuth (.. ), parseURI )
18
25
19
26
import Distribution.Types.CondTree
20
27
import Distribution.Types.Library
@@ -224,7 +231,7 @@ srcToNix _ (Path p) = mkRecSet [ "src" $= applyMkDefault (mkRelPath p) ]
224
231
srcToNix pi' (PrivateHackage url)
225
232
= mkNonRecSet $
226
233
[ " src" $= applyMkDefault (mkSym pkgs @. " fetchurl" @@ mkNonRecSet
227
- [ " url" $= mkStr (fromString $ mkPrivateHackageUrl url pi')
234
+ [ " url" $= mkStr (fromString . show $ mkPrivateHackageUrl url pi')
228
235
, " sha256" $= (mkSym " config" @. " sha256" )
229
236
])
230
237
]
@@ -248,11 +255,40 @@ srcToNix _ (Git url rev mbSha256 mbPath)
248
255
$= mkStr (fromString $ " sourceRoot+=/" <> root <> " ; echo source root reset to $sourceRoot" )
249
256
| Just root <- [mbPath] ]
250
257
251
- mkPrivateHackageUrl :: String -> PackageIdentifier -> String
252
- mkPrivateHackageUrl hackageUrl pi' =
253
- hackageUrl <> " /package/" <> pkgNameVersion <> " /" <> pkgNameVersion <> " .tar.gz"
254
- where
255
- pkgNameVersion = unPackageName (pkgName pi') <> " -" <> show (pretty (pkgVersion pi'))
258
+ -- This logic is hard coded in `cabal-install` see:
259
+ -- * Distribution.Client.HttpUtils.isOldHackageURI
260
+ isOldHackageURI :: URI -> Bool
261
+ isOldHackageURI uri
262
+ = case uriAuthority uri of
263
+ Just (URIAuth {uriRegName = " hackage.haskell.org" }) ->
264
+ FilePath.Posix. splitDirectories (uriPath uri)
265
+ == [" /" ," packages" ," archive" ]
266
+ _ -> False
267
+
268
+ -- This logic is hard coded in `cabal-install` see:
269
+ -- * Distribution.Client.FetchUtils.packageURI
270
+ packageURI :: URI -> PackageId -> URI
271
+ packageURI remoteRepoURI pkgid | isOldHackageURI remoteRepoURI =
272
+ remoteRepoURI {
273
+ uriPath = FilePath.Posix. joinPath
274
+ [uriPath remoteRepoURI
275
+ ,prettyShow (packageName pkgid)
276
+ ,prettyShow (packageVersion pkgid)
277
+ ,prettyShow pkgid <.> " tar.gz" ]
278
+ }
279
+ packageURI remoteRepoURI pkgid =
280
+ remoteRepoURI {
281
+ uriPath = FilePath.Posix. joinPath
282
+ [uriPath remoteRepoURI
283
+ ," package"
284
+ ,prettyShow pkgid <.> " tar.gz" ]
285
+ }
286
+
287
+ mkPrivateHackageUrl :: String -> PackageIdentifier -> URI
288
+ mkPrivateHackageUrl hackageUrl = maybe
289
+ (error $ " Unable to parse hackage URI " <> hackageUrl)
290
+ packageURI
291
+ (parseURI hackageUrl)
256
292
257
293
newtype SysDependency = SysDependency { unSysDependency :: String } deriving (Show , Eq , Ord )
258
294
data SetupDependency = SetupDependency PackageName LibraryName deriving (Show , Eq , Ord )
0 commit comments