Opened 5 years ago

Closed 5 years ago

#5977 closed feature request (fixed)

Allow ignoring global package db

Reported by: duncan Owned by: pcapriotti
Priority: high Milestone: 7.6.1
Component: Compiler Version: 7.4.1
Keywords: Cc: JeremyShaw
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


For sandboxing, users want to be able to use only local package dbs. To handle rts, base etc, they copy those specific packages from the global package db into a local package db.

Currently however there is no sensible way to tell ghc to look only at the listed package dbs, and not the global db. There is a flag -no-user-package-conf to avoid looking at the per-user one, but no equivalent to ignore or to specify the global one.

(Note: as a quirky non-sensible way, you can use GHC_PACKAGE_PATH="" to clear the package db stack, but this should be possible using command line flags.)

The user interface we're now using in cabal is like this:

  • --global sets the initial db stack to [GlobalPackageDB]
  • --user sets the initial db stack to [GlobalPackageDB, UserPackageDB]
  • --package-db=clear clears the db stack to []
  • --package-db=global pushes GlobalPackageDB on the top of the stack
  • --package-db=user pushes UserPackageDB on the top of the stack
  • --package-db=${otherfile} pushes SpecificPackageDB ${otherfile} on the top of the stack

It seems to me we could do something similar with ghc. Currently in ghc we have a -hide-all-packages flag that resets the package set to empty. We could do with an equivalent for the package database stack. I suggest something like:

  • -clear-package-conf
  • -global-package-conf
  • -user-package-conf (and the existing -no-user-package-conf)
  • -package-conf file

The default would remain that the global and user dbs are used, but this can be reset using -clear-package-conf.

Personally I prefer the nomenclarture "package db" rather than "package conf" here, but it's not that important.

Attachments (5)

0001-Add-flags-to-manipulate-package-db-stack-5977.patch (7.5 KB) - added by pcapriotti 5 years ago.
0002-Rename-package-conf-flags-to-package-db.patch (16.0 KB) - added by pcapriotti 5 years ago.
0003-Update-documentation-of-the-package-db-flags.patch (10.7 KB) - added by pcapriotti 5 years ago.
5977-tests.patch (21.8 KB) - added by pcapriotti 5 years ago.
0004-Simplify-the-behavior-of-package-db-flags.patch (9.4 KB) - added by pcapriotti 5 years ago.

Download all attachments as: .zip

Change History (18)

comment:1 Changed 5 years ago by JeremyShaw

  • Cc JeremyShaw added

comment:2 Changed 5 years ago by simonmar

  • difficulty set to Unknown
  • Milestone set to 7.6.1
  • Priority changed from normal to high

Yep, let's do something for 7.6.1.

comment:3 Changed 5 years ago by simonpj

  • Owner set to pcapriotti

Changed 5 years ago by pcapriotti

comment:4 Changed 5 years ago by pcapriotti

  • Status changed from new to patch

The attached patch series adds the extra flags described in this ticket (with the addition of no-global-package-conf, for symmetry), and renames them to *-package-db.

You can find the corresponding patch for Cabal in my github fork:

comment:5 Changed 5 years ago by simonpj

  • Owner changed from pcapriotti to simonmar

comment:6 follow-up: Changed 5 years ago by simonmar

I had a look at the patches. The situation in DynFlags is now a bit strange - we have both the Opt_ReadGlobalPackageConf options and the [PkgConfRef]. I think we should have just the [PkgConfRef] representing the stack, and all the flags should manipulate it directly.


  • We start with [global,user]
  • -no-user-package-db removes user from the list (similarly for global)
  • -user-package-db adds user to the end (similarly for global)
  • -package-conf file adds file to the end
  • -clear-package-db sets the list to empty

comment:7 Changed 5 years ago by simonmar

  • Owner changed from simonmar to pcapriotti

comment:8 in reply to: ↑ 6 Changed 5 years ago by pcapriotti

I'm not sure how that would interact with GHC_PACKAGE_PATH. For example, if I run:

GHC_PACKAGE_PATH="foo:" ghc --no-user-package-db

I'd expect it to use [global, foo] as db stack, but we can't remove user from the stack originating from GHC_PACKAGE_PATH unless we keep the information somewhere (currently it's in Opt_ReadUserPackageConf).

So at the moment there is an "initial stack", which is [global, user] by default, and is affected by -no-user-package-db, -no-global-package-db, -clear-package-db, and GHC_PACKAGE_PATH. The other flags append to the stack *after* the initial stack has been determined.

comment:9 Changed 5 years ago by simonmar

I find it weird that -no-user-package-db affects the "initial stack", but -user-package-db appends the user db to the final stack. So e.g. -user-package-db -no-user-package-db does not do what you expect.

So I see two alternatives. One is to modify my proposal to take into account GHC_PACKAGE_PATH: just initialise the stack from GHC_PACKAGE_PATH before processing the arguments, defaulting to [global,user] if GHC_PACKAGE_PATH is not set.

The other alternative is to keep the concept of the "initial stack", but make -user-package-db and -global-package-db just the inverses of -no-user-package-db and -no-global-package-db respectively. I'd be ok with that too.

comment:10 Changed 5 years ago by pcapriotti

The attached patch implements option 1. The list of flags is now maintained as a [PkgConfRef] -> [PkgConfRef], which is later applied to the base stack obtained by GHC_PACKAGE_PATH.

comment:11 Changed 5 years ago by simonmar

Yes, that looks ok.

comment:12 Changed 5 years ago by p.capriotti@…

commit 6a831be4aa73e86568256813ffa862d7cfd5732d

Author: Paolo Capriotti <>
Date:   Thu May 3 11:29:51 2012 +0100

    Add flags to manipulate package db stack (#5977)
    Introduce new flags to allow any package database stack to be set up.
    The `-no-user-package-conf` and `-no-global-package-conf` flags remove
    the corresponding package db from the initial stack, while
    `-user-package-conf` and `-global-package-conf` push it back on top of
    the stack.

 compiler/main/DynFlags.hs  |   24 +++++++++++--
 compiler/main/Packages.lhs |   81 +++++++++++++++++++++-----------------------
 2 files changed, 60 insertions(+), 45 deletions(-)

comment:13 Changed 5 years ago by pcapriotti

  • Resolution set to fixed
  • Status changed from patch to closed
Note: See TracTickets for help on using tickets.