Pass GHC --package-db options to Cabal query

List of issues:
1. Fix --g flag.
2. Read/Write index file with utf8 encoding to avoid IO errors.
3. Pass GHC --package-db options to Cabal query of installed packages when creating the index