Difference between "source-repository-package" and "local no-index repositories" in Cabal

Viewed 846

I know I can add a local package to a cabal project by listing it in the packages: section of the cabal.project file. The simplest example, which makes a project out of a single local package, is packages: ..

In cabal.project I can also add these two things:

  • source-repository-package sections:

      source-repository-package
          type: git
          location: git@github.com:haskell-streaming/streaming.git
          tag: eb3073e6ada51b2bae82c15a9ef3a21ffa5f5529
    
  • definitions of local no-index repositories

      repository my-local-repository
          url: file+noindex:///home/zzz/no-index-repo-dir
    

It seems that both of them let me add packages to a project. What's the difference between the two?

(Note: this question is unrelated to the similarly-named source-repository: field, which simply says which is the repository associated to the source code of a package.)

1 Answers

Only source-repository-package is actually adding a "local package" to your project. It behaves pretty much as listing a package's source folder in packages:, except that the source code is downloaded as needed. In particular, it will be re-downloaded when running cabal build after a cabal clean.

Because it's a local package in your project, other cabal projects are unaware of it. Adding it to other local projects requires recompiling it again.


Meanwhile, local no-index package repositories are repositories in the sense of Hackage or Stackage, only in the local filesystem. They can be specified in both the cabal.project file of an individual project or in the global cabal configuration (~/.cabal/config).

Packages found in these repositories are not considered "local packages" of a project. Their libraries are compiled once and shared between all the projects which are aware of the package repository (which will be all projects, if the repository is listed in ~/.cabal/config). And cabal build after cabal clean will not trigger a recompilation.

Related