Activating home-manager with impermanence

I’m building a btrfs+impermanence setup, and I’m having trouble integrating home-manager into the process.

I have this impermanence setup in my configuration.nix and it works pretty well:

environment.persistence = {
  "/persist" = {
    directories = [

And this in my home-manager setup:

home.persistence = {
  "/persist/home/${config.home.username}" = {
    directories = [
    allowOther = true;

But after a reboot my home manager environment is not activated. I need to do the following every time:

nix shell home-manager
mkdir -p ~/.local/state/nix/profiles # required or home-manager will throw an error. why?
home-manager switch --flake /etc/nixos

I mean, I guess it kinda makes sense, since the entire root directory including the home is cleared every time.

I looked through a few dotfiles with impermanence, but I just can’t figure out the “correct” way to handle this. It’s as if that this problem isn’t supposed to exist at all. Any tips?

I figured it out, you have to use home-manager as a NixOS module for this to work: