Installing home-manager config to target machine from install media BEFORE booting onto target machine

Is there any way to chroot and then install a home-manager config onto the target machine before I boot onto the newly installed disk while still keeping it separate from my system nixos config?

I wanted to try to configure my i3 entirely from home manager, and make my lightdm just run ~/.xsession and have home manager take care of the rest, so that I can take my i3 to any distro with me. It works well when I set it up on an already running machine. I can run i3 entirely from home-manager with all my config.

However, this presents an interesting issue. When I install nixos to a target machine from my installer image, I am unable to log into a session on the target machine until I run home manager because there is no desktop environment installed yet. But I cant run home-manager to install it because I am unable to start a session.

I could solve this issue by adding the home-manager module to my system configs imports. However, then they aren’t separate anymore, or at the very least I would have to have a separate config entrypoint for first time installs compared to subsequent ones where the home-manager was included as a system module, and i would need to have one per machine. I am not a fan of that at all and would like to continue importing them separately and still pre install the home manager to the target machine.

If there is a command to install to the target from the installer for home manager, I could very easily just put it in the existing alias in my installer image. Can I just straight up chroot into /mnt and run home-manager? Will be a few hours till I can test.

The installer image

The lightdm module

Edit: yup… Still stuck XD

1 Like


Will be a little bit until I have a script for it but I think this may do the trick, I can use nixos-enter to activate the nix environment inside the chroot environment, and then run home manager with the --option sandbox false flag


I can install the stuff but I cant activate apparently?

i can build it fine

however if i try to activate it as root it says it expected me to be logged in as the user, and if I try to activate it as user it tells me I dont have permission to change /nix/var/nix/profiles/per-user to 755 permissions… If I try to sudo it tells me pam isnt set up

Its already 755 permissions lol How do I do this.

I got it to activate via setting my user and home variables to that of the user without actually swapping off of root.

However this caused all my programs to get installed to root because it put the .nix-profile there, and the configuration and files to go to the user…

So I can start a session as the user but use no programs, not even a terminal editor… My i3 bar works though lol

and I cant start a session as root but it has all the programs…


Idk how to fix that so I guess im going to reinstall and try a third time

any luck ? I was wondering if I can do something like this too, instead of relying on shell script to get basic functionality into my home dir.

1 Like

Unfortunately no. I got distracted by trying to learn C++ and am just installing i3 normally for now. I use home manager for it, but I have a second session type that is installed by system so that I can get up and running on first install.

I dont like that solution much though, hopefully it can be figured out someday