Skip to content

One IFD for all project-related information? #1616

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

Closed
michaelpj opened this issue Aug 25, 2022 · 6 comments
Closed

One IFD for all project-related information? #1616

michaelpj opened this issue Aug 25, 2022 · 6 comments
Labels
enhancement New feature or request

Comments

@michaelpj
Copy link
Collaborator

From discussion with @andreabedini.

At the moment we do a bunch of parsing of the cabal.project in Nix. This avoids us from having to do more IFD. But we have to do at least one IFD already to get the plan.json. So we could have an analyze-project derivation that gives us the plan.json but also the index-state, repository stanzas etc. That would let us write the logic in Haskell, which would be nicer and easier to test (and could maybe even use the cabal parser).

cc @hamishmack

@hamishmack
Copy link
Collaborator

See also #1370 (comment)

@andreabedini
Copy link
Member

andreabedini commented Aug 25, 2022

Playing with cabal-install I managed to put togheter something like this. It should do most of what you want @michaelpj

{- cabal:
build-depends: base ^>= 4.14
             , bytestring
             , directory
             , filepath
             , Cabal         >=3.8 && <3.9
             , cabal-install >=3.8 && <3.9
             , pretty-simple
-}

module Main where

import Distribution.Client.DistDirLayout
import Distribution.Client.HttpUtils
import Distribution.Client.InstallPlan
import Distribution.Client.ProjectPlanOutput (writePlanExternalRepresentation)
import Distribution.Client.ProjectPlanning
import Distribution.Verbosity
import System.Environment
import Text.Pretty.Simple (pPrint)

main :: IO ()
main = do
  [path] <- getArgs

  let verbosity = verbose
  let distDirLayout = defaultDistDirLayout (ProjectRootImplicit path) Nothing

  httpTransport <- configureTransport verbosity mempty Nothing

  (projectConfig, localPackages) <-
    rebuildProjectConfig
      verbosity
      httpTransport
      distDirLayout
      mempty

  putStrLn "-- projectConfig --"
  pPrint projectConfig

  putStrLn "-- localPackages --"
  pPrint localPackages

  let cabalDirLayout = defaultCabalDirLayout "/tmp/cabal-dir"

  -- Two variants of the install plan are returned: with and without
  -- packages from the store. That is, the "improved" plan where source
  -- packages are replaced by pre-existing installed packages from the
  -- store (when their ids match), and also the original elaborated plan
  -- which uses primarily source packages.
  (improvedPlan, elaboratedPlan, esc, tis, at) <- rebuildInstallPlan verbosity distDirLayout cabalDirLayout projectConfig localPackages

  putStrLn $ unlines ["-- imporovedPlan -- ", showInstallPlan improvedPlan]
  putStrLn $ unlines ["-- elaboratedPlan --", showInstallPlan elaboratedPlan]
  putStrLn "-- elaborated shared config --"
  pPrint esc
  putStrLn "-- total index state --"
  pPrint tis
  putStrLn "-- active repos --"
  pPrint at

  -- writes plan.json in distProjectCacheFile distDirLayout
  writePlanExternalRepresentation distDirLayout elaboratedPlan esc

@yvan-sraka
Copy link
Contributor

Is this issue something we want to implement in nix-tools?

@michaelpj
Copy link
Collaborator Author

Yes, it would need to be synchronized across the two: nix-tools would need to provide the executable and haskell.nix consume it. More reason to merge the repos already :)

@yvan-sraka yvan-sraka added the enhancement New feature or request label Sep 20, 2022
@andreabedini
Copy link
Member

Something similar is in progress at #1775

@andreabedini
Copy link
Member

This idea was partially implemented in #1775 and this is the direction things are going.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants