title: How to write a shell.nix file which combines other nix-shell environments?
body: <p>I want to write a <code>shell.nix</code> file that will provide me a development environment which includes developer tools + haskell dependencies. I would like to keep my nix expressions separate - for now that means one file containing information about my editor, and one file containing information about my haskell project.</p>
  
  <p>I have tried to set up a really basic environment, but can't get it to work. I have two files which I can create a <code>nix-shell</code> from already:</p>
  
  <pre><code># my-haskell-shell.nix - generated by cabal2nix --shell
  
  { nixpkgs ? import &lt;nixpkgs&gt; {}, compiler ? "default", doBenchmark ? false }:
  
  let
  
    inherit (nixpkgs) pkgs;
  
    f = { mkDerivation, base, cabal-install, hpack, stdenv }:
        mkDerivation {
          pname = "hello-world";
          version = "0.1.0.0";
          src = ./.;
          isLibrary = false;
          isExecutable = true;
          libraryToolDepends = [ hpack ];
          executableHaskellDepends = [ base ];
          executableToolDepends = [ cabal-install hpack ];
          preConfigure = "hpack";
          license = stdenv.lib.licenses.mit;
        };
  
    haskellPackages = if compiler == "default"
                         then pkgs.haskellPackages
                         else pkgs.haskell.packages.${compiler};
  
    variant = if doBenchmark then pkgs.haskell.lib.doBenchmark else pkgs.lib.id;
  
    drv = variant (haskellPackages.callPackage f {});
  
  in
    if pkgs.lib.inNixShell then drv.env else drv
  </code></pre>
  
  <pre><code># my-neovim-shell.nix
  
  with import &lt;nixpkgs&gt; {};
  
  let
    my-neovim = neovim.override { vimAlias = false; };
  
  in
  stdenv.mkDerivation {
    name = "neovim-dev-env";
    buildInputs = [
      my-neovim
    ];
  }
  </code></pre>
  
  <p>Both of these produce useful shell environments! (That is, <code>nix-shell my-haskell-env.nix</code> and <code>nix-shell my-neovim-env.nix</code> give me cabal and neovim respectively, but not both). </p>
  
  <p>My attempt at producing a <code>shell.nix</code> which will provide an environment with <em>both</em> neovim and cabal available is this:</p>
  
  <pre><code># shell.nix
  with import &lt;nixpkgs&gt; {};
  let
    my-neovim-shell-env = import ./my-neovim-shell.nix;
    my-haskell-shell-env = import ./my-haskell-shell.nix {};
  in
  stdenv.mkDerivation {
    name = "my-new-env";
    buildInputs = [
      my-neovim-shell-env
      my-haskell-shell-env
    ];
  }
  </code></pre>
  
  <p>This does not work however. It seems to try to build the neovim environment:</p>
  
  <pre><code> $ nix-shell
  these derivations will be built:
    /nix/store/k9ygid1wl75vf2nq7jzfh32mv5f8i956-neovim-dev-env.drv
  building '/nix/store/k9ygid1wl75vf2nq7jzfh32mv5f8i956-neovim-dev-env.drv'...
  unpacking sources
  variable $src or $srcs should point to the source
  builder for '/nix/store/k9ygid1wl75vf2nq7jzfh32mv5f8i956-neovim-dev-env.drv' failed with exit code 1
  error: build of '/nix/store/k9ygid1wl75vf2nq7jzfh32mv5f8i956-neovim-dev-env.drv' failed
  </code></pre>
  
  <p>I don't know how to fix this; what am I doing wrong? I suspect maybe I should not be using mkDerivation?</p>