title: How to get use `callCabal2nix` to supply package list to 'ghcWithPackages'?
body: <p>I have a list of ~46 dependencies.</p>
  <p>I produce a shell using among other things a call to:</p>
  <pre class="lang-hs prettyprint-override"><code>server = pkgs.haskellPackages.callCabal2nix &quot;server&quot; ./server.cabal { };
  </code></pre>
  <p>within an override of <code>pkgs.haskellPackages</code> that goes into <code>pkgs.myHaskellPackages</code>.</p>
  <p>The shell works fine. However, I have another nix for building a docker and this requires a build input that comes from:</p>
  <pre class="lang-hs prettyprint-override"><code>ghc = pkgs.myHaskellPackages.ghcWithPackages (p: [ longlistofdependencies ]);
  </code></pre>
  <p>How do I specify the long list of dependencies without having to write them out manually, defeating the purpose of using <code>callCabal2nix</code> in the first place.</p>
  <pre class="lang-hs prettyprint-override"><code>let                                                                                                                                                                                                                                           
    bootstrap = import &lt;nixpkgs&gt; { };                                                                                                                                                                                                           
                                                                                                                                                                                                                                                
    nixpkgs = builtins.fromJSON (builtins.readFile ./nixpkgs-unstable.json);                                                                                                                                                                    
                                                                                                                                                                                                                                                
    src = bootstrap.fetchFromGitHub {                                                                                                                                                                                                           
      owner = &quot;NixOS&quot;;                                                                                                                                                                                                                          
      repo  = &quot;nixpkgs&quot;;                                                                                                                                                                                                                        
      inherit (nixpkgs) rev sha256;                                                                                                                                                                                                             
    };                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                
    config = {                                                                                                                                                                                                                                  
      allowBroken = true;                                                                                                                                                                                                                       
                                                                                                                                                                                                                                                
      packageOverrides = pkgs: rec {                                                                                                                                                                                                            
        servantSrc = pkgs.fetchFromGitHub {                                                                                                                                                                                                     
          owner = &quot;haskell-servant&quot;;                                                                                                                                                                                                            
          repo = &quot;servant&quot;;                                                                                                                                                                                                                     
          rev = &quot;73c87bc2bc0685649f2337b06ab4fdc66c4ce1dd&quot;;                                                                                                                                                                                     
          sha256 = &quot;0sw4mrncmfna30cyxrvinc1krqhfxn5dcc1ggzqfy39s0yl9q98r&quot;;                                                                                                                                                                      
          #sha256 = &quot;0000000000000000000000000000000000000000000000000000&quot;;                                                                                                                                                                     
        } + &quot;/servant&quot;;                                                                                                                                                                                                                         
                                                                                                                                                                                                                                                
        myHaskellPackages = pkgs.haskellPackages.override {                                                                                                                                                                                     
          overrides = haskellPackagesNew: haskellPackagesOld: rec {                                                                                                                                                                             
            server =                                                                                                                                                                                                                            
              haskellPackagesNew.callCabal2nix &quot;server&quot; ./server.cabal { };                                                                                                                                                                     
                                                                                                                                                                                                                                                
            servant =                                                                                                                                                                                                                           
              haskellPackagesNew.callCabal2nix &quot;servant&quot; servantSrc {};                                                                                                                                                                         
  
            # several other overridden packages                                                                                                                                                                                                                                    
          };
        };
      };
    };
  
    pkgs = import src { inherit config; };
  
    devShell = pkgs.myHaskellPackages.shellFor {
      packages = p: [
        p.server 
      ];
      buildInputs = with pkgs.haskellPackages; [
        hlint
        brittany
        haskell-language-server
      ];
    };
  
    # Every time a dependency changes in the cabal file, this has to be edited as well.
    ghc = pkgs.myHaskellPackages.ghcWithPackages (p: [
      p.aeson p.aeson-qq p.base p.blaze-html p.bytestring p.cache p.containers
      p.contravariant-extras p.criterion p.either p.hashable p.hasql
      p.hasql-migration p.hasql-pool p.hasql-th p.hasql-transaction p.hspec
      p.http-client p.http-conduit p.http-types p.immortal-queue p.lens p.linear
      p.monad-logger p.mtl p.pqueue p.pretty-simple p.QuickCheck p.raw-strings-qq
      p.servant-blaze p.servant-docs p.servant-server
      p.string-interpolate p.text p.text-format p.time p.tuple p.unordered-containers
      p.utf8-string p.vector p.vector-split p.wai p.wai-cors p.warp p.xlsx p.yaml
    ]);
  
  in {
    inherit devShell;
    inherit ghc;
    inherit pkgs;
  }
  </code></pre>
  <p>The <code>ghc</code> output is used in <code>docker.nix</code> as a build input:</p>
  <pre class="lang-hs prettyprint-override"><code>let 
      inherit (import ./pinned-nixpkgs.nix) ghc pkgs;
  
      pricing-server =
          pkgs.stdenv.mkDerivation {
              name = &quot;my-server&quot;;
              pname = &quot;my-server&quot;;
              version = &quot;1.1.0&quot;;
              src = ./.;
  
              buildPhase = ''
                ghc -O2 --make -outputdir ./tmp2 Main.hs
              '';
  
              installPhase = ''
                mkdir -p $out/bin
                cp Main $out/bin
                cp -r ./sql $out/bin
              '';
  
              buildInputs = [ ghc ];
          };
  in
  dockerTools.buildImage {
      # irrelevant to the question.
  }
  
  </code></pre>