title: ghc-pkg: Couldn't open database for modification: hLock: invalid argument
body: <p>I'm trying to compile the <code>behead.hs</code> script from the pandoc tutorial on Ubuntu 20.04 (WSL1).
  I can successfully compile it with<br />
  <code>stack exec -- ghc behead.hs</code> or<br />
  <code>stack --resolver lts-16.25 exec -- ghc behead.hs</code><br />
  but that uses <code>pandoc-types-1.20</code> and I need <code>pandoc-types-1.22</code> so I try<br />
  <code>stack --resolver nightly-2020-12-07 exec -- ghc behead.hs</code><br />
  (the earliest nightly to feature <code>pandoc-types-1.22</code> is <code>2020-09-20</code>, that fails with the same error as below)</p>
  <p>This yields:</p>
  <pre><code>Preparing to install GHC (tinfo6) to an isolated location.
  This will not interfere with any system-level installation.
  Already downloaded.
  ghc-pkg: Couldn't open database /home/me/.stack/programs/x86_64-linux/ghc-tinfo6-8.10.2/lib/ghc-8.10.2/package.conf.d for modification: {handle: /home/me/.stack/programs/x86_64-linux/ghc-tinfo6-8.10.2/lib/ghc-8.10.2/package.conf.d/package.cache.lock}: hLock: invalid argument (Invalid argument)
  make[1]: *** [ghc.mk:973: install_packages] Error 1
  make: *** [Makefile:51: install] Error 2
  Received ExitFailure 2 when running
  Raw command: /usr/bin/make install
  Run from: /home/me/.stack/programs/x86_64-linux/ghc-tinfo6-8.10.2.temp/ghc-8.10.2/
  
  
  Error: Error encountered while installing GHC with
           make install
           run in /home/me/.stack/programs/x86_64-linux/ghc-tinfo6-8.10.2.temp/ghc-8.10.2/
  
         The following directories may now contain files, but won't be used by stack:
           - /home/me/.stack/programs/x86_64-linux/ghc-tinfo6-8.10.2.temp/
           - /home/me/.stack/programs/x86_64-linux/ghc-tinfo6-8.10.2/
  
         For more information consider rerunning with --verbose flag
  
  Installing GHC ...
  </code></pre>
  <p>With <code>--verbose</code> I get too much to paste here, but I am happy to provide grep results. Possibly relevant extract:</p>
  <pre><code>#the WSL doesn't seem to get recognized as ubuntu
  [debug] checking build system type... x86_64-pc-linux-gnu
  2020-12-08 11:40:58.363496: [debug] checking host system type... x86_64-pc-linux-gnu
  2020-12-08 11:40:58.363926: [debug] checking target system type... x86_64-pc-linux-gnu
  2020-12-08 11:40:58.364331: [debug] Build platform inferred as: x86_64-unknown-linux
  2020-12-08 11:40:58.412992: [debug] Host platform inferred as: x86_64-unknown-linux
  2020-12-08 11:40:58.463758: [debug] Target platform inferred as: x86_64-unknown-linux
  2020-12-08 11:40:58.715901: [debug] GHC build  : x86_64-unknown-linux
  2020-12-08 11:40:58.716483: [debug] GHC host   : x86_64-unknown-linux
  2020-12-08 11:40:58.717018: [debug] GHC target : x86_64-unknown-linux
  2020-12-08 11:40:58.717558: [debug] LLVM target: x86_64-unknown-linux
  #the last lines before the error:
  [debug] Installing library in /home/me/.stack/programs/x86_64-linux/ghc-tinfo6-8.10.2/lib/ghc-8.10.2/ghc-8.10.2
  [debug] &quot;/home/me/.stack/programs/x86_64-linux/ghc-tinfo6-8.10.2/lib/ghc-8.10.2/bin/ghc-pkg&quot; --force --global-package-db &quot;/home/me/.stack/programs/x86_64-linux/ghc-tinfo6-8.10.2/lib/ghc-8.10.2/package.conf.d&quot; update rts/dist/package.conf.install
  </code></pre>
  <p>I have currently no way of reproducing this on an actual linux machine to see whether the fact that I'm using WSL is relevant to the problem. I can try that in ~6h.</p>
  <p>File for reproduction:</p>
  <pre><code>#!/usr/bin/env runhaskell
  -- behead.hs
  import Text.Pandoc.JSON
  
  main :: IO ()
  main = toJSONFilter behead
  
  behead :: Block -&gt; Block
  behead (Header n _ xs) | n &gt;= 2 = Para [Emph xs]
  </code></pre>
  <p>I would like to understand why this happens but morover how I can compile the script with <code>pandoc-types-1.22</code>.</p>