title: Cabal cannot find locally sourced (yet correctly installed) packages
body: <p>I recently upgraded to Cabal 3.2 (and GHC 8.10) and I am running into some major issues that make some of my project non-buildable anymore...</p>
  
  <h2>Thorough description of the problem</h2>
  
  <p>Here is a minimal (not) working configuration that fails every time:</p>
  
  <ol>
  <li><p>I start off with a clean Cabal configuration (by deleting <code>~/.cabal</code>); the reason for that will appear later in the post. I run <code>cabal update</code> to recreate the <code>.cabal</code> directory and to ensure Cabal is working.</p></li>
  <li><p>I create a project (let's call it <code>test1</code>) using <code>cabal init</code>. This is a library project with one exposed module (conveniently named <code>Test1</code>) that exports some dummy function <code>foo</code>. I run <code>cabal build</code>, then <code>cabal install --lib</code>; everything is running smooth, so far so good.</p></li>
  <li><p>Just to be sure, I leave the project directory and fire up GHCi. I type in <code>:m Test1</code> to load the module I created earlier, and it works! I can type in <code>foo ...</code> and see my function executed. Also, I list the content of <code>~/.cabal/store/ghc-8.10.xxx</code> and see that the <code>test1-xxx</code> directory is there.</p></li>
  <li><p>I then create a new project, <code>test2</code>, still using <code>cabal init</code>. This time, I configure it to be an executable, and I add <code>test1</code> as a dependency (using the <code>build-depends</code> field). But this time when I run <code>cabal build</code>, I run into some issue:</p></li>
  </ol>
  
  <pre><code>~/projects/haskell/test2&gt; cabal build
  Resolving dependencies...
  cabal: Could not resolve dependencies:
  [__0] trying: test2-0.1.0.0 (user goal)
  [__1] unknown package: test1 (dependency of test2)
  [__1] fail (backjumping, conflict set: test1, test2)
  After searching the rest of the dependency tree exhaustively, these were the
  goals I've had most trouble fulfilling: test2, test1
  </code></pre>
  
  <p>It seems to me like package <code>test1</code> cannot be found, however I can access it from GHCi (and GHC for that matters) and it is present in <code>~/.cabal/store</code>...</p>
  
  <p>But unfortunately there is more.</p>
  
  <ol start="5">
  <li>I create a third project, <code>test3</code>. This is a library, and it depends on nothing else than <code>base</code> (so in particular it <em>does not</em> depend on <code>test1</code>). The lib exposes one module, <code>Test3</code>, with one function exported, <code>bar</code>. I run <code>cabal build</code>, no problem here. But when I want to install <code>test3</code> with <code>cabal install --lib</code> I run into some errors:</li>
  </ol>
  
  <pre><code>~/projects/haskell/test3&gt; cabal install --lib
  Wrote tarball sdist to
  /home/&lt;user&gt;/projects/haskell/test3/dist-newstyle/sdist/test3-0.1.0.0.tar.gz
  Resolving dependencies...
  cabal: Could not resolve dependencies:
  [__0] unknown package: test1 (user goal)
  [__0] fail (backjumping, conflict set: test1)
  After searching the rest of the dependency tree exhaustively, these were the
  goals I've had most trouble fulfilling: test1
  </code></pre>
  
  <p>It seems that it cannot find <code>test1</code>, although it has been installed correctly; may be this is a remnant of the failed build of <code>test2</code> though...</p>
  
  <ol start="6">
  <li><p>Just to be sure, I fire up GHCi and type in <code>:m Test3</code>, but GHCi tells me that it cannot find module <code>Test3</code> (and even suggests this is a typo and I was meaning <code>Test1</code>), showing that <code>test3</code> indeed did not get installed, although it got successfully built...</p></li>
  <li><p>Okay there is one more quirk to this whole situation: I create once again a new project with <code>cabal init</code>, called <code>test4</code>, which is an executable that (again) depends on nothing else than <code>base</code>. I keep the default <code>Main.hs</code> (that just prints "Hello, Haskell!"). I run <code>cabal build</code>: no problem. Then I run <code>cabal install</code> and... No problem either? I run <code>test4</code> in a random location and it fires up the executable, printing "Hello, Haskell!" in the terminal...</p></li>
  <li><p>And there is one last thing: I go to some random location and I run <code>cabal install xxx --lib</code> where <code>xxx</code> is a library package available on Hackage (for example <code>xml</code>) and:</p></li>
  </ol>
  
  <pre><code>~&gt; cabal install xml --lib
  Resolving dependencies...
  cabal: Could not resolve dependencies:
  [__0] unknown package: test1 (user goal)
  [__0] fail (backjumping, conflict set: test1)
  After searching the rest of the dependency tree exhaustively, these were the
  goals I've had most trouble fulfilling: test1
  </code></pre>
  
  <p>This is the reason why I need to nuke <code>.cabal</code> regularly... Right now I seem to be in some kind of stale state where I cannot install any library anymore.</p>
  
  <h2>Technical configuration and notes</h2>
  
  <p>I am running Cabal 3.2.0.0 and GHC 8.10.0.20200123. I installed them from the hvr/ghc PPA, and I made sure there are no other versions of those tools anywhere on my computer.</p>
  
  <p>Just as a note, I am running Ubuntu 18.04.4 LTS (with XFCE so XUbuntu to be exact). Everything else (seem to be like it) is up to date.</p>
  
  <p>Last thing, regarding the <code>*.cabal</code> files I use for building, they are pretty much the ones generated by <code>cabal init</code>, except I switch <code>executable xxx</code> for <code>library</code> in the case of libraries, and I simply add a <code>exposed-modules</code> field for exposing modules for the libraries (so <code>Test1</code> for <code>test1</code> and <code>Test3</code> for <code>test3</code> respectively). I also use <code>build-depends</code> in <code>test2</code> to make the project depend on <code>test1</code>. Apart from that, they are pretty much left untouched.</p>
  
  <h2>Notes and thoughts</h2>
  
  <p>I must confess that I am new to Cabal 3; until last week I was using Cabal 1 (because I never bothered to update it; yes I know this is bad). With Cabal 1 I did not have any problem whatsoever, and I was perfectly able to install a package from local sources and depend on it in other projects...</p>
  
  <p>I feel like I am doing something wrong; maybe am I not using the correct Cabal commands? I saw somewhere something about <code>cabal new-build</code> and <code>cabal new-install</code> but it does not seem to do anything more than <code>cabal build</code> and <code>cabal install</code>, at least in my case. I also wanted to investigate sandboxes but it seems that has disappeared since version 2 of Cabal.</p>
  
  <p>There is also a slight possibility this is a Cabal bug, but I don't find any relevant issue on the bug tracker that may be related to my problem...</p>
  
  <p>What do you think about this? What am I doing wrong? Do you see any alternative or possible fix?</p>
  
  <p>Thanks a lot!</p>