This example config can maybe help you out. It consists of two parts:
- Telling home-manager where to put the i3 initialization code: https://github.com/srid/nix-config/blob/b86bfc9627713b1b4de57bfa3c2f76a2fdb095b1/nix/home/i3.nix#L6
- Tell the display manager where this initialization code can be found: https://github.com/srid/nix-config/blob/ff9684b5fddbf5cf3628311d9c970e136fb4c91a/nixos/i3.nix
This was initially suggested by rycee: Opening i3 from home-manager automatically - #8 by rycee . Hopefully this addition makes it work for you.
EDIT: Why it works when you add it to the root config: because then you are hooking into the system-wide system for hooking up display and window managers. However if you install i3 through home-manager, the system-wide nix config does not know about “user” i3’s existence, and therefore you have to add some manual glue code to make it work. At least that’s my understanding as a nixos noob.