Override postInstall for emacsOverlay

I am using the GitHub - nix-community/emacs-overlay: Bleeding edge emacs overlay [maintainer=@adisbladis] which is already set up through flakes and want to override the postInstall script to add some bash at the end.

let doom-emacs = (pkgs.emacs).overrideAttrs (attrs: {
	postInstall = (attrs.postInstall or "") + ''
	mv ${inputs.doom-emacs} ${config.home.homeDirectory}/.emacs.d
	'';
});

but the service.emacs.package = pkgs.emacsGcc has no effect on the pkgs.emacs above, I have to change it to pkgs.emacsGcc directly instead. Also, for default pkgs.emacs, it starts to build the entire emacs where as normally it should be a binary and should not trigger a build. What is the correct way to override the Overlay?

The postInstall isn’t allowed to write in your $HOME.

What exactly are you trying to achieve?

I was trying to clone the doom emacs repo in .emacs.d along with emacs and run ~/.emacs.d/bin/doom install. Is there an actual way to do something like this or is my best bet just using nix-straight.el?

You can not do that in a derivation.

You need to either do the doom stuff manually or manage it through a nixos or home-manager module.

Though as I am not using doom myself, but vanilla emacs, I can’t tell you much more than that.

A quick web search though brought me to GitHub - vlaci/nix-doom-emacs: doom-emacs packaged for Nix, which seems to provide a wrapper that does doom fully in the store or a HM module to manage it thoruogh home.

Yes, nix-doom-emacs uses nix-straight.el. It completely manages doom-emacs where as I wanted to partially manage it (install doom-emacs and update it myself with ~/.emacs.d/bin/doom upgrade rather than through nix rebuild switch). This is because nix-straight.el gives much higher startup times than doing it manually myself. I just want to run

git clone --depth 1 https://github.com/hlissner/doom-emacs ~/.emacs.d
~/.emacs.d/bin/doom install -y

after installing emacs. I’m not sure if this is possible tho

You have to do that manually then.

In HM you could perhaps use activation scripts, though as they should be idempotent, its probably not a good idea to make them create folders without taking precautions.

I have previously looked into activation scripts. But I want to run this script exactly once (when I install emacs). A clever workaround would be to check if .emacs.d exists and write it if it doesn’t. Is there a way to run something like an activation script only once?

Nope, it will be run each time on activation, but of course you can wrap the script in a conditional.