Trying to package Doom-emacs

I am trying to package doom-emacs and I came up with this small derivation (?) to match with the instructions from the repository :

{pkgs ? import <nixpkgs> {}, ...}:

	doomSrc = pkgs.fetchFromGitHub {
		owner = "hlissner";
		repo = "doom-emacs";
		rev = "v2.0.9";
		sha256 = "190ygybn0dn0z98dfv4d5yh4np6ph7wlaz04agw9r49rzwf8g23y";
	(pkgs.emacs).overrideAttrs (attrs: {
		postInstall = (attrs.postInstall or "") + ''
		mv ${doomSrc} $HOME/.emacs.d
		rm -rf $HOME/.emacs.d/{LICENSE,README,.gitignore,.travis.yml,.github}
		$HOME/.emacs.d/bin/doom quickstart

But of course, as $HOME is set to /homeless-shelter (as stated in the manual), a call to nix-build doom-emacs.nix sends back :

mv: cannot move '/nix/store/j36c7sg381fw03x58ylhyikgxi3c0b5q-source' to '/homeless-shelter/.emacs.d': No such file or directory

So how would you package this to achieve the same result ?

Sometimes a build system depends on $HOME to exist to store temporary files, in that case it’s quite common for the build to override that variable to another temporary location. Just grep through nixpkgs and you’ll find a ton of examples.

That being said, it looks like you are trying to install doomSrc into the $HOME. Build results are only kept if they are installed somewhere into the $out path. Have a look at the other plugins, I guess emacs has a way to maintain it’s extensions in another folder.

So for further references, here are my findings which are definitely interesting to anyone following the same path as me :

I did my search and anyone interested in impurities should have a look at this specific (really well-named) file on Nixpkgs.

In my endeavor to package the actual application though I did a significant turn : I am now trying to patch a specific file to avoid impurities (to follow the philosophy of the distribution). But now I get an intriguing error on patching the file :

can't find file to patch at input line 3
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
|--- a/share/emacs/site-lisp/site-start.el      1970-01-01 01:00:01.000000000 +0100
|+++ b/share/emacs/site-lisp/site-start.el      1970-01-01 01:00:01.000000000 +0100
File to patch:
Skip this patch? [y]
Skipping patch.
1 out of 1 hunk ignored

So if anyone has any suggestions to solve the previous issue or even (idiomatic Nix-related) improvement to the derivation feel free to suggest them here, I’ll gladly take some functional magic.