Skip to content

Commit 23c4060

Browse files
authored
Update nix-tools dependencies to build with GHC 9.10.1 (#2263)
* Update nix-tools dependencies to build with GHC 9.10.1 - Re-organise some of nix-tools modules - Vendor-in custom ProjectPlanOutput - Bump pinned haskell.nix * Bump Cabal-syntax commit * Restore nix-tools support for GHC 9.2
1 parent 4547a5c commit 23c4060

File tree

13 files changed

+543
-191
lines changed

13 files changed

+543
-191
lines changed

nix-tools/cabal.project

+13-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
index-state: 2024-03-28T00:00:00Z
1+
index-state: 2024-10-15T20:31:31Z
22

33
packages: nix-tools
44

@@ -10,24 +10,22 @@ extra-packages: cabal-install, hpack, Cabal-syntax-json
1010
test-show-details: direct
1111

1212
allow-newer:
13+
algebraic-graphs:deepseq,
1314
hackage-db:base,
1415
hackage-db:Cabal,
15-
hpack:Cabal,
16-
hnix:base,
17-
hnix:template-haskell,
1816
hnix:aeson,
17+
hnix:base,
18+
hnix:bytestring,
19+
hnix:free,
1920
hnix:relude,
2021
hnix-store-core:base,
21-
hnix-store-core:memory,
22+
hnix-store-core:bytestring,
2223
hnix-store-core:cryptonite,
23-
hnix-store-core:bytestring
24-
25-
source-repository-package
26-
type: git
27-
location: https://github.com/haskell/cabal.git
28-
tag: c0647bc914928ab6362278c73f17b084ca3ed9ab
29-
subdir: cabal-install
30-
--sha256: sha256-BQs6ciCKWNzsEdUewEvUu4lcyrI5DH7abKzM4035lSc=
24+
hnix-store-core:memory,
25+
hnix:template-haskell,
26+
hpack:Cabal,
27+
lens-family-th:base,
28+
lens-family-th:template-haskell,
3129

3230
source-repository-package
3331
type: git
@@ -38,5 +36,5 @@ source-repository-package
3836
source-repository-package
3937
type: git
4038
location: https://github.com/andreabedini/Cabal-syntax-json.git
41-
tag: bf97be0038489239a11c61653b55afc77356ac1e
42-
--sha256: sha256-i9TEqQqRqFM07q1Lr6wcMlURhBkhkVxHhP1jQjSE+Yg=
39+
tag: b7192832f730d9181a013ef7c77f2ad0b30cca43
40+
--sha256: sha256-Yw2HQOCmjOvfKHi3xWbSniAZfyrshOvsgmUbqFmDDpU=

nix-tools/flake.lock

+19-19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nix-tools/flake.nix

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{
22
inputs = {
33
nixpkgs.follows = "haskellNix/nixpkgs";
4-
# nixpkgs-unstable.url = "github:NixOS/nixpkgs";
5-
64
haskellNix.url = "github:input-output-hk/haskell.nix";
75
};
86

nix-tools/nix-tools/hackage2nix/Main.hs

+23-16
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1+
{-# LANGUAGE CPP #-}
12
{-# LANGUAGE OverloadedStrings #-}
23
{-# LANGUAGE NamedFieldPuns #-}
34
{-# LANGUAGE LambdaCase #-}
45

5-
module Main where
6+
module Main (main) where
67

78
import Cabal2Nix
89
import Cabal2Nix.Util ( quoted )
10+
#if !MIN_VERSION_base(4, 17, 0)
911
import Control.Applicative ( liftA2 )
12+
#endif
1013
import Control.Monad.Trans.State.Strict
1114
import Crypto.Hash.SHA256 ( hash )
1215
import qualified Data.ByteString.Base16 as Base16
1316
import qualified Data.ByteString.Char8 as BS
17+
import Data.Char ( isUpper )
1418
import Data.Foldable ( toList
1519
, for_
1620
)
@@ -50,7 +54,6 @@ import System.Environment ( getArgs )
5054
import System.FilePath ( (</>)
5155
, (<.>)
5256
)
53-
import Data.Char (isUpper)
5457

5558
-- Avoid issues with case insensitive file systems by escaping upper case
5659
-- characters with a leading _ character.
@@ -64,27 +67,31 @@ main :: IO ()
6467
main = do
6568
out:rest <- getArgs
6669
(inp, src) <- case rest of
67-
[tarball, url, hash] -> return (tarball, Just $ Repo url (Just hash))
70+
[tarball, url, sha256] -> return (tarball, Just $ Repo url (Just sha256))
6871
[tarball, url] -> return (tarball, Just $ Repo url Nothing)
6972
[tarball] -> return (tarball, Nothing)
7073
[] -> hackageTarball >>= \tarball -> return (tarball, Nothing)
74+
_ -> error "Usage: hackage2nix [tarball [url [hash]]]"
7175

7276
db <- U.readTarball Nothing inp
7377

7478
let (nixFiles, cabalFiles) =
7579
runState (fmap (toList . (Seq.sortOn fst)) $ foldMapWithKeyA package2nix db) mempty
7680
createDirectoryIfMissing False out
77-
writeFile (out </> "default.nix") $
78-
"with builtins; mapAttrs (_: mapAttrs (_: data: rec {\n\
79-
\ inherit (data) sha256;\n\
80-
\ revisions = data.revisions // {\n\
81-
\ default = revisions.\"${data.revisions.default}\";\n\
82-
\ };\n\
83-
\})) {\n"
84-
-- Import all the per package nix files
85-
<> mconcat (map (\(pname, _) ->
86-
" " <> quoted pname <> " = import ./nix/" <> escapeUpperCase pname <> ".nix;\n") nixFiles)
87-
<> "}\n"
81+
writeFile (out </> "default.nix") $ unlines [
82+
"with builtins; mapAttrs (_: mapAttrs (_: data: rec {",
83+
" inherit (data) sha256;",
84+
" revisions = data.revisions // {",
85+
" default = revisions.\"${data.revisions.default}\";",
86+
" };",
87+
"})) {",
88+
-- Import all the per package nix files
89+
unlines [
90+
" " <> quoted pname <> " = import ./nix/" <> escapeUpperCase pname <> ".nix;"
91+
| (pname, _) <- nixFiles
92+
],
93+
"}"
94+
]
8895

8996
createDirectoryIfMissing False (out </> "nix")
9097
for_ nixFiles $ \(pname, nix) ->
@@ -124,9 +131,9 @@ version2nix pname vnum (U.VersionData { U.cabalFileRevisions, U.metaFile }) =
124131
do
125132
revisionBindings <- sequenceA
126133
$ zipWith (revBindingJson pname vnum) cabalFileRevisions [0 ..]
127-
let hash = decodeUtf8 $ fromString $ P.parseMetaData pname vnum metaFile Map.! "sha256"
134+
let sha256 = decodeUtf8 $ fromString $ P.parseMetaData pname vnum metaFile Map.! "sha256"
128135
return $ Seq.singleton (quoted (fromPretty vnum), mkNonRecSet
129-
[ "sha256" $= mkStr hash
136+
[ "sha256" $= mkStr sha256
130137
, "revisions" $= mkNonRecSet
131138
( map (uncurry ($=)) revisionBindings
132139
++ ["default" $= mkStr (fst (last revisionBindings))]

nix-tools/nix-tools/make-install-plan/MakeInstallPlan.hs

+26-22
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ import qualified Cabal2Nix hiding (gpd2nix)
66
import qualified Data.ByteString.Lazy as BSL
77
import Data.Foldable (for_)
88
import qualified Data.Text.Encoding as T
9-
import Distribution.Client.DistDirLayout (DistDirLayout (distDirectory, distProjectCacheFile, distProjectFile))
9+
import Distribution.Client.DistDirLayout (DistDirLayout (..))
1010
import Distribution.Client.GlobalFlags
1111
import Distribution.Client.HashValue (HashValue, showHashValue)
1212
import qualified Distribution.Client.InstallPlan as InstallPlan
1313
import Distribution.Client.NixStyleOptions (NixStyleFlags (..), defaultNixStyleFlags, nixStyleOptions)
1414
import Distribution.Client.ProjectConfig
1515
import Distribution.Client.ProjectOrchestration
16-
import Distribution.Client.ProjectPlanOutput (writePlanExternalRepresentation)
17-
import Distribution.Client.ProjectPlanning (ElaboratedConfiguredPackage (..), rebuildInstallPlan, availableTargets)
16+
import Distribution.Client.ProjectPlanning (ElaboratedConfiguredPackage (..), availableTargets, rebuildInstallPlan)
1817
import Distribution.Client.Setup
1918
import Distribution.Client.Types.PackageLocation (PackageLocation (..))
2019
import Distribution.Client.Types.Repo (LocalRepo (..), RemoteRepo (..), Repo (..))
@@ -25,14 +24,15 @@ import Distribution.Pretty (prettyShow)
2524
import Distribution.Simple.Command
2625
import Distribution.Simple.Flag
2726
import qualified Distribution.Simple.Utils as Cabal
28-
import Distribution.Types.SourceRepo (KnownRepoType (Git), RepoType (..))
27+
import Distribution.Types.SourceRepo (KnownRepoType (..), RepoType (..))
2928
import Distribution.Verbosity (Verbosity)
3029
import qualified Distribution.Verbosity as Verbosity
3130
import Freeze (projectFreezeConfig)
3231
import Nix.Expr
3332
import Nix.Pretty (prettyNix)
3433
import Prettyprinter (Doc)
3534
import Prettyprinter.Render.Text (hPutDoc)
35+
import ProjectPlanOutput (writePlanExternalRepresentation)
3636
import System.Environment (getArgs)
3737
import System.FilePath
3838
import System.IO (IOMode (WriteMode), hClose, openFile)
@@ -46,35 +46,39 @@ main = do
4646
CommandErrors errs -> putStrLn $ "commandErrors: " ++ show errs
4747
CommandReadyToGo (mkflags, _commandParse) ->
4848
let globalFlags = defaultGlobalFlags
49-
flags@NixStyleFlags {configFlags} = mkflags (commandDefaultFlags cmdUI)
49+
flags@NixStyleFlags{configFlags} = mkflags (commandDefaultFlags cmdUI)
5050
verbosity = fromFlagOrDefault Verbosity.normal (configVerbosity configFlags)
5151
cliConfig = commandLineFlagsToProjectConfig globalFlags flags mempty
5252
in installPlanAction verbosity cliConfig
5353

5454
cmdUI :: CommandUI (NixStyleFlags ())
5555
cmdUI =
5656
CommandUI
57-
{ commandName = "",
58-
commandSynopsis = "Makes an install-plan",
59-
commandUsage = ("Usage: " ++),
60-
commandDescription = Nothing,
61-
commandNotes = Nothing,
62-
commandDefaultFlags = defaultNixStyleFlags (),
63-
commandOptions = nixStyleOptions (const [])
57+
{ commandName = ""
58+
, commandSynopsis = "Makes an install-plan"
59+
, commandUsage = ("Usage: " ++)
60+
, commandDescription = Nothing
61+
, commandNotes = Nothing
62+
, commandDefaultFlags = defaultNixStyleFlags ()
63+
, commandOptions = nixStyleOptions (const [])
6464
}
6565

6666
-- The following is adapted from cabal-install's Distribution.Client.CmdFreeze
6767
installPlanAction :: Verbosity -> ProjectConfig -> IO ()
6868
installPlanAction verbosity cliConfig = do
69-
ProjectBaseContext {distDirLayout, cabalDirLayout, projectConfig, localPackages} <-
69+
ProjectBaseContext{distDirLayout, cabalDirLayout, projectConfig, localPackages} <-
7070
establishProjectBaseContext verbosity cliConfig OtherCommand
7171

7272
(_improvedPlan, elaboratedPlan, elaboratedSharedConfig, totalIndexState, activeRepos) <-
7373
rebuildInstallPlan verbosity distDirLayout cabalDirLayout projectConfig localPackages Nothing
7474

7575
-- Write plan.json
7676
Cabal.notice verbosity $ "Writing plan.json to " ++ distProjectCacheFile distDirLayout "plan.json"
77-
writePlanExternalRepresentation distDirLayout elaboratedPlan elaboratedSharedConfig (availableTargets elaboratedPlan)
77+
writePlanExternalRepresentation
78+
distDirLayout
79+
elaboratedPlan
80+
elaboratedSharedConfig
81+
(availableTargets elaboratedPlan)
7882

7983
-- Write cabal.freeze
8084
let freezeConfig = projectFreezeConfig elaboratedPlan totalIndexState activeRepos
@@ -90,12 +94,12 @@ installPlanAction verbosity cliConfig = do
9094

9195
for_ ecps $
9296
\ElaboratedConfiguredPackage
93-
{ elabPkgSourceId,
94-
elabPkgSourceLocation,
95-
elabPkgSourceHash,
96-
elabLocalToProject,
97-
elabPkgDescriptionOverride
98-
} -> do
97+
{ elabPkgSourceId
98+
, elabPkgSourceLocation
99+
, elabPkgSourceHash
100+
, elabLocalToProject
101+
, elabPkgDescriptionOverride
102+
} -> do
99103
let nixFile = cabalFilesDir </> prettyShow (pkgName elabPkgSourceId) <.> "nix"
100104
for_ elabPkgDescriptionOverride $ \pkgTxt -> do
101105
-- In the plan we have elabPkgDescription :: PackageDescription which is the cabal file after
@@ -123,8 +127,8 @@ packageLocation2Src pkgSrcLoc pkgSrcHash = case pkgSrcLoc of
123127
(SourceRepositoryPackage (KnownRepoType Git) location (Just tag) branch subdir []) ->
124128
Cabal2Nix.Git location tag branch subdir
125129
_otherCases -> error $ "Repository " <> show sourceRepoMaybe <> " not supported"
126-
where
127-
mSrcHash = showHashValue <$> pkgSrcHash
130+
where
131+
mSrcHash = showHashValue <$> pkgSrcHash
128132

129133
writeDoc :: FilePath -> Doc ann -> IO ()
130134
writeDoc file doc = do

0 commit comments

Comments
 (0)