Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update nix-tools dependencies to build with GHC 9.10.1 #2263

Merged
merged 3 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions nix-tools/cabal.project
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
index-state: 2024-03-28T00:00:00Z
index-state: 2024-10-15T20:31:31Z

packages: nix-tools

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

allow-newer:
algebraic-graphs:deepseq,
hackage-db:base,
hackage-db:Cabal,
hpack:Cabal,
hnix:base,
hnix:template-haskell,
hnix:aeson,
hnix:base,
hnix:bytestring,
hnix:free,
hnix:relude,
hnix-store-core:base,
hnix-store-core:memory,
hnix-store-core:bytestring,
hnix-store-core:cryptonite,
hnix-store-core:bytestring

source-repository-package
type: git
location: https://github.com/haskell/cabal.git
tag: c0647bc914928ab6362278c73f17b084ca3ed9ab
subdir: cabal-install
--sha256: sha256-BQs6ciCKWNzsEdUewEvUu4lcyrI5DH7abKzM4035lSc=
hnix-store-core:memory,
hnix:template-haskell,
hpack:Cabal,
lens-family-th:base,
lens-family-th:template-haskell,

source-repository-package
type: git
Expand All @@ -38,5 +36,5 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/andreabedini/Cabal-syntax-json.git
tag: bf97be0038489239a11c61653b55afc77356ac1e
--sha256: sha256-i9TEqQqRqFM07q1Lr6wcMlURhBkhkVxHhP1jQjSE+Yg=
tag: b7192832f730d9181a013ef7c77f2ad0b30cca43
--sha256: sha256-Yw2HQOCmjOvfKHi3xWbSniAZfyrshOvsgmUbqFmDDpU=
38 changes: 19 additions & 19 deletions nix-tools/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions nix-tools/flake.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
inputs = {
nixpkgs.follows = "haskellNix/nixpkgs";
# nixpkgs-unstable.url = "github:NixOS/nixpkgs";

haskellNix.url = "github:input-output-hk/haskell.nix";
};

Expand Down
39 changes: 23 additions & 16 deletions nix-tools/nix-tools/hackage2nix/Main.hs
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE LambdaCase #-}

module Main where
module Main (main) where

import Cabal2Nix
import Cabal2Nix.Util ( quoted )
#if !MIN_VERSION_base(4, 17, 0)
import Control.Applicative ( liftA2 )
#endif
import Control.Monad.Trans.State.Strict
import Crypto.Hash.SHA256 ( hash )
import qualified Data.ByteString.Base16 as Base16
import qualified Data.ByteString.Char8 as BS
import Data.Char ( isUpper )
import Data.Foldable ( toList
, for_
)
Expand Down Expand Up @@ -50,7 +54,6 @@ import System.Environment ( getArgs )
import System.FilePath ( (</>)
, (<.>)
)
import Data.Char (isUpper)

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

db <- U.readTarball Nothing inp

let (nixFiles, cabalFiles) =
runState (fmap (toList . (Seq.sortOn fst)) $ foldMapWithKeyA package2nix db) mempty
createDirectoryIfMissing False out
writeFile (out </> "default.nix") $
"with builtins; mapAttrs (_: mapAttrs (_: data: rec {\n\
\ inherit (data) sha256;\n\
\ revisions = data.revisions // {\n\
\ default = revisions.\"${data.revisions.default}\";\n\
\ };\n\
\})) {\n"
-- Import all the per package nix files
<> mconcat (map (\(pname, _) ->
" " <> quoted pname <> " = import ./nix/" <> escapeUpperCase pname <> ".nix;\n") nixFiles)
<> "}\n"
writeFile (out </> "default.nix") $ unlines [
"with builtins; mapAttrs (_: mapAttrs (_: data: rec {",
" inherit (data) sha256;",
" revisions = data.revisions // {",
" default = revisions.\"${data.revisions.default}\";",
" };",
"})) {",
-- Import all the per package nix files
unlines [
" " <> quoted pname <> " = import ./nix/" <> escapeUpperCase pname <> ".nix;"
| (pname, _) <- nixFiles
],
"}"
]

createDirectoryIfMissing False (out </> "nix")
for_ nixFiles $ \(pname, nix) ->
Expand Down Expand Up @@ -124,9 +131,9 @@ version2nix pname vnum (U.VersionData { U.cabalFileRevisions, U.metaFile }) =
do
revisionBindings <- sequenceA
$ zipWith (revBindingJson pname vnum) cabalFileRevisions [0 ..]
let hash = decodeUtf8 $ fromString $ P.parseMetaData pname vnum metaFile Map.! "sha256"
let sha256 = decodeUtf8 $ fromString $ P.parseMetaData pname vnum metaFile Map.! "sha256"
return $ Seq.singleton (quoted (fromPretty vnum), mkNonRecSet
[ "sha256" $= mkStr hash
[ "sha256" $= mkStr sha256
, "revisions" $= mkNonRecSet
( map (uncurry ($=)) revisionBindings
++ ["default" $= mkStr (fst (last revisionBindings))]
Expand Down
48 changes: 26 additions & 22 deletions nix-tools/nix-tools/make-install-plan/MakeInstallPlan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import qualified Cabal2Nix hiding (gpd2nix)
import qualified Data.ByteString.Lazy as BSL
import Data.Foldable (for_)
import qualified Data.Text.Encoding as T
import Distribution.Client.DistDirLayout (DistDirLayout (distDirectory, distProjectCacheFile, distProjectFile))
import Distribution.Client.DistDirLayout (DistDirLayout (..))
import Distribution.Client.GlobalFlags
import Distribution.Client.HashValue (HashValue, showHashValue)
import qualified Distribution.Client.InstallPlan as InstallPlan
import Distribution.Client.NixStyleOptions (NixStyleFlags (..), defaultNixStyleFlags, nixStyleOptions)
import Distribution.Client.ProjectConfig
import Distribution.Client.ProjectOrchestration
import Distribution.Client.ProjectPlanOutput (writePlanExternalRepresentation)
import Distribution.Client.ProjectPlanning (ElaboratedConfiguredPackage (..), rebuildInstallPlan, availableTargets)
import Distribution.Client.ProjectPlanning (ElaboratedConfiguredPackage (..), availableTargets, rebuildInstallPlan)
import Distribution.Client.Setup
import Distribution.Client.Types.PackageLocation (PackageLocation (..))
import Distribution.Client.Types.Repo (LocalRepo (..), RemoteRepo (..), Repo (..))
Expand All @@ -25,14 +24,15 @@ import Distribution.Pretty (prettyShow)
import Distribution.Simple.Command
import Distribution.Simple.Flag
import qualified Distribution.Simple.Utils as Cabal
import Distribution.Types.SourceRepo (KnownRepoType (Git), RepoType (..))
import Distribution.Types.SourceRepo (KnownRepoType (..), RepoType (..))
import Distribution.Verbosity (Verbosity)
import qualified Distribution.Verbosity as Verbosity
import Freeze (projectFreezeConfig)
import Nix.Expr
import Nix.Pretty (prettyNix)
import Prettyprinter (Doc)
import Prettyprinter.Render.Text (hPutDoc)
import ProjectPlanOutput (writePlanExternalRepresentation)
import System.Environment (getArgs)
import System.FilePath
import System.IO (IOMode (WriteMode), hClose, openFile)
Expand All @@ -46,35 +46,39 @@ main = do
CommandErrors errs -> putStrLn $ "commandErrors: " ++ show errs
CommandReadyToGo (mkflags, _commandParse) ->
let globalFlags = defaultGlobalFlags
flags@NixStyleFlags {configFlags} = mkflags (commandDefaultFlags cmdUI)
flags@NixStyleFlags{configFlags} = mkflags (commandDefaultFlags cmdUI)
verbosity = fromFlagOrDefault Verbosity.normal (configVerbosity configFlags)
cliConfig = commandLineFlagsToProjectConfig globalFlags flags mempty
in installPlanAction verbosity cliConfig

cmdUI :: CommandUI (NixStyleFlags ())
cmdUI =
CommandUI
{ commandName = "",
commandSynopsis = "Makes an install-plan",
commandUsage = ("Usage: " ++),
commandDescription = Nothing,
commandNotes = Nothing,
commandDefaultFlags = defaultNixStyleFlags (),
commandOptions = nixStyleOptions (const [])
{ commandName = ""
, commandSynopsis = "Makes an install-plan"
, commandUsage = ("Usage: " ++)
, commandDescription = Nothing
, commandNotes = Nothing
, commandDefaultFlags = defaultNixStyleFlags ()
, commandOptions = nixStyleOptions (const [])
}

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

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

-- Write plan.json
Cabal.notice verbosity $ "Writing plan.json to " ++ distProjectCacheFile distDirLayout "plan.json"
writePlanExternalRepresentation distDirLayout elaboratedPlan elaboratedSharedConfig (availableTargets elaboratedPlan)
writePlanExternalRepresentation
distDirLayout
elaboratedPlan
elaboratedSharedConfig
(availableTargets elaboratedPlan)

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

for_ ecps $
\ElaboratedConfiguredPackage
{ elabPkgSourceId,
elabPkgSourceLocation,
elabPkgSourceHash,
elabLocalToProject,
elabPkgDescriptionOverride
} -> do
{ elabPkgSourceId
, elabPkgSourceLocation
, elabPkgSourceHash
, elabLocalToProject
, elabPkgDescriptionOverride
} -> do
let nixFile = cabalFilesDir </> prettyShow (pkgName elabPkgSourceId) <.> "nix"
for_ elabPkgDescriptionOverride $ \pkgTxt -> do
-- In the plan we have elabPkgDescription :: PackageDescription which is the cabal file after
Expand Down Expand Up @@ -123,8 +127,8 @@ packageLocation2Src pkgSrcLoc pkgSrcHash = case pkgSrcLoc of
(SourceRepositoryPackage (KnownRepoType Git) location (Just tag) branch subdir []) ->
Cabal2Nix.Git location tag branch subdir
_otherCases -> error $ "Repository " <> show sourceRepoMaybe <> " not supported"
where
mSrcHash = showHashValue <$> pkgSrcHash
where
mSrcHash = showHashValue <$> pkgSrcHash

writeDoc :: FilePath -> Doc ann -> IO ()
writeDoc file doc = do
Expand Down
Loading
Loading