Override a transitive emacs dependency

I’d like to override a transitive dependency so eglot uses a flymake fork that allows me to override the directory cluttering default behavior.

At the very end of the emacs section of the manual it covers an example I think is like my case using (emacsPackagesGen emacs).overrideScope', here is that example inline:

overrides = self: super: rec {
  haskell-mode = self.melpaPackages.haskell-mode;
  ...
};
((emacsPackagesGen emacs).overrideScope' overrides).emacsWithPackages (p: with p; [
  # here both these package will use haskell-mode of our own choice
  ghc-mod
  dante
])

My attempt in the context of the repo is on Github, but here’s my nix file I’m testing by running nix-shell --pure emacs.nix --keep HOME --run "emacs --batch --eval='(load \"$HOME/init.el\")'":

{
pkgs ? import <nixpkgs>
{
      overlays = [
      (self: super: {
        flymake = builtins.fetchGit {
          url = "git@github.com:flymake/emacs-flymake.git";
          rev = "8701c806d5e8f4e2c6f7dea461273482ad89c029";
          ref = "master";
        };
      })
    ];
  }
}:
let
  myEmacs = pkgs.emacs;
  overrides = self: super: rec {
    flymake = builtins.fetchGit {
          url = "git@github.com:flymake/emacs-flymake.git";
          rev = "8701c806d5e8f4e2c6f7dea461273482ad89c029";
          ref = "master";
        };
  };
  emacsWithPackages = ((pkgs.emacsPackagesGen myEmacs).overrideScope' overrides).emacsWithPackages (p: with p; [
    p.haskellMode
    # eglot breaks for haskell if flymake writes temporary directories in place
    # This fork of flymake lets you set the `flymake-run-in-place` variable to nil
    # to disable this:
    # https://github.com/flymake/emacs-flymake#use-the-system-temporary-directory-for-temp-files
    # The manual told me that overrideScope' should be enough, so I guess I'm probably missing something
    p.eglot
  ]);
in
(pkgs.stdenv.mkDerivation {
  name = "debug-flymake-annoying-clutter";
  buildInputs = [
    emacsWithPackages
  ];
})

Thanks!

With some help in IRC we ended up getting something a little smaller and focused just on overriding flycheck but even it doesn’t seem to work:

{ pkgs ? import <nixpkgs> {} }:
let
  myEmacs = pkgs.emacs;
  overrides = self: super: {
    flymake = super.flymake.overrideAttrs (oa: {
      src = builtins.fetchGit {
        url = "git@github.com:flymake/emacs-flymake.git";
        rev = "8701c806d5e8f4e2c6f7dea461273482ad89c029";
        ref = "master";
      };
    });
  };
  myEmacsWithPackages = ((pkgs.emacsPackagesGen myEmacs).overrideScope' overrides).emacsWithPackages (p: with p; [
    p.haskellMode
    p.flymake
  ]);
in
(pkgs.stdenv.mkDerivation {
  name = "debug-flymake-annoying-clutter";
  buildInputs = [
    myEmacsWithPackages
  ];
})

Some more context on this:

codygman___: Yes, but it's not a nix dependency of haskell-mode. Oh, I think I see. The installPhase of flymake uses the elpa package directlry
codygman___: So maybe your pure src approach was actually right
But how does Emacs know how to find it the...
codygman___: Well, at least that's the problem. The actual flymake needs to override the installPhase or something to point emacs at the new source. I don't know how to tell emacs to do that though

The answer ended up being:

{ pkgs ? import <nixpkgs> {} }:
let
  myEmacs = pkgs.emacs;
  overrides = self: super: {
    flymake = super.flymake.override {
      elpaBuild = args: super.elpaBuild (args // {
        src = (builtins.fetchGit {
          url = "git@github.com:flymake/emacs-flymake.git";
          rev = "8701c806d5e8f4e2c6f7dea461273482ad89c029";
          ref = "master";
        }) + "/flymake.el";
      });
    };
  };
in
(pkgs.stdenv.mkDerivation {
  name = "debug-flymake-annoying-clutter";
  buildInputs = [
    (((pkgs.emacsPackagesGen myEmacs).overrideScope' overrides).emacsWithPackages (p: with p; [
      p.haskellMode
      p.flymake
    ]))
  ];
})

I now am left with an emacs bug, but in the emacs that nix profile produces you can M-x customize-group and see the run in place option is available!