USER environment variable does not match, causing a build failure

basically there was a moment when I changed a user variable in my hove config without thinking, immediately regretted it and changed it back, but it didn’t help. I tried asking every AI chatbot and searched all the existing issues, but still can’t figure out how to fix it. I also tried rolling back to the previous generations, but it didn’t help either. my user is niko, w4le5 is a non-existent user that I applied by mistake.

I cannot nor want to reinstall, please help me

here’s the console output and full config:

full configwarning: the following units failed: home-manager-niko.service
× home-manager-niko.service - Home Manager environment for niko
Loaded: loaded (/etc/systemd/system/home-manager-niko.service; enabled; preset: ignored)
Active: failed (Result: exit-code) since Wed 2026-01-21 00:30:18 +05; 360ms ago
Invocation: 7f45744c29244954b53b7813b2e738f1
Process: 2939 ExecStart=/nix/store/rayqv9xw3qkwjp007p6avfwi277z9zy6-hm-setup-env /nix/store/dqk69wjxpim8dm1cn4hvb50fbzml510x-home-manager-generation (code=exited, st
Main PID: 2939 (code=exited, status=1/FAILURE)
IP: 0B in, 0B out
IO: 12K read, 0B written
Mem peak: 9M
CPU: 94ms
Jan 21 00:30:18 pwnstation systemd[1]: Starting Home Manager environment for niko...
Jan 21 00:30:18 pwnstation hm-activate-niko[2939]: Starting Home Manager activation
Jan 21 00:30:18 pwnstation hm-activate-niko[2939]: Environment variable USER is set to "w4le5" but we expect "niko"
Jan 21 00:30:18 pwnstation systemd[1]: home-manager-niko.service: Main process exited, code=exited, status=1/FAILURE
Jan 21 00:30:18 pwnstation systemd[1]: home-manager-niko.service: Failed with result 'exit-code'.
Jan 21 00:30:18 pwnstation systemd[1]: Failed to start Home Manager environment for niko.

and printenv output

Hey! Maybe setting the env var for building helps(?):
USER=niko nixos-rebuild […]

BR

BTW: It irritates me a bit that rebooting into an older/prev. build (which has worked) isn’t working …

Unfortunately it didn’t help, I have tried it already actually.

BTW: I know right? I thought it would help too, but after rolling back to the very first generation of my system i realized that it’s not the case sadly

That won’t work because this has nothing to do with rebuilding, it’s the hm activation service which has an isolated environment.

Won’t work because other stateful data has changed, like (hopefully) /etc/passwd, /etc/shadow, … and NixOS does not track stateful data (as it shouldn’t, that would imply data loss on every boot). That’s why users.mutableUsers is on by default.

Anyway:

What’s the output of the commands below?

systemctl show home-manager-niko --property=User,Environment --no-pager

whoami

And how exactly did you change your username?

1 Like

Environment=HOME_MANAGER_BACKUP_EXT=backup LOCALE_ARCHIVE=/nix/store/8pw03yms4ng064nhgv26krlzia9xmla4-glibc-locales-2.40-66/lib/locale/locale-archive LOGNAME=niko PATH=/nix/store/d75200gb22v7p0703h5jrkgg8bqydk5q-coreutils-9.8/bin:/nix/store/wd99g2j010fdkry0ws1bhxzm52w82ssx-findutils-4.10.0/bin:/nix/store/qfmq7p42ak5yn389qvx7zpxkan5i4xiy-gnugrep-3.12/bin:/nix/store/k06ssckzrzn9jjvvs4n62m6567zmbx6x-gnused-4.9/bin:/nix/store/9m6xh63j8mvragnhra8k7rchwxldcrry-systemd-258.2/bin:/nix/store/d75200gb22v7p0703h5jrkgg8bqydk5q-coreutils-9.8/sbin:/nix/store/wd99g2j010fdkry0ws1bhxzm52w82ssx-findutils-4.10.0/sbin:/nix/store/qfmq7p42ak5yn389qvx7zpxkan5i4xiy-gnugrep-3.12/sbin:/nix/store/k06ssckzrzn9jjvvs4n62m6567zmbx6x-gnused-4.9/sbin:/nix/store/9m6xh63j8mvragnhra8k7rchwxldcrry-systemd-258.2/sbin QT_QPA_PLATFORM=offscreen TZDIR=/nix/store/q42y30akm86ph3pzzdrp5qyrm7pg6sqy-tzdata-2025b/share/zoneinfo USER=niko User=niko

whoami:

niko

originally I changed my username by adding sessionVariables = { USER = “w4le5“; LOGNAME = "w4le5";}; to my home.nix

Oh. Yeah that’s definitely not the way to change usernames.

I know you mentioned “rolling back” but unclear what you tried - did you try rebooting your system (into ‌the current generation again) after removing those vars?

I have tried rebooting into the current generation and when it didn’t work I also tried rebooting into previous generation. and when it didn’t work either I just rolled back as far as possible just to make sure, but the problem persisted

Can you try setting these to the correct value "niko" and then nixos-rebuild boot then reboot?

it was the first thing I did

We’re not mindreaders, we can’t guess what you tried unless you tell us.
Idk at this point, file a bug with hm I guess?

I am sorry if it sounded rude, I was just trying to say that I have tried it already and it didn’t help

@w4le5 I can’t help any further ATM (and @waffle8946 also tried) …

So, maybe just give us some more information about your setup/config and the build process/commands …(?)

KR

Well, I attached the entire config and described how I tried to fix it myself. What else can I provide that would be helpful? If you request something specific, I’ll be happy to provide it

Well, I missed the point to not have to downloads files …

Sry, I’m out :woozy_face:

Good luck!

IMO if you did no other changes to your user, this feels like a home-manager bug, envvar changes should not be so stateful as to persist through reboot.

1 Like