When nixos-rebuilding as user on latest unstable, I get
building Nix...
building the system configuration...
Error in tempdir() using /run/user/1000/nix-build.XXXXXX: Parent directory (/run/user/1000) does not exist at /nix/store/cg6yr2rfsv0mkzk8l57znrvv73gsi6ix-nix-1.11.14/lib/perl5/site_perl/5.24.2/x86_64-linux-thread-multi/Nix/Utils.pm line 45.
Using sudo nixos-rebuild build works.
/run/user/1000 should be actually created by systemd-logind.
Do you have a valid login session?
$ loginctl
SESSION UID USER SEAT TTY
8 1000 joerg seat0
1 sessions listed.
$ loginctl
SESSION UID USER SEAT TTY
2 1000 m seat0
1 sessions listed.
I encountered this issue several times as well. In my case the system is a NixOS VM I only contact over mosh.
There was no login session on the VM:
~~~
$ loginctl
SESSION UID USER SEAT TTY
0 sessions listed.
~~~
I then tried to trigger a session by connecting via ssh. In the original, still open, mosh session:
~~~
$ loginctl
SESSION UID USER SEAT TTY
13 1100 coconnor
1 sessions listed.
~~~
And sure enough: nixos-rebuild works.
Interesting. Why would there be no session?
This is a problem with mosh and systemd-logind. Once mosh has established the mosh connection, it forks itself and exits the ssh session. When the ssh session is exited your logind session goes away, which also removes /run/user/<uid>/.
I searched around on the issue you mentioned. Rather interesting how common this is!
The command loginctl enable-linger $USER will retain the session after ssh disconnect. This means, for my case, the procedure is:
to establish a persistent session.
From what I see, the issue I encountered is not a NixOS issue. As @Mic92 mentions the issue is with mosh.
I forgot about enable-linger. This fixes the issue with mosh. I have no idea what happens in @matthiasbeyer case. I have the following mounts:
console.
$ mount | grep run
tmpfs on /run type tmpfs (rw,nosuid,nodev,size=4047128k,mode=755)
ramfs on /run/keys type ramfs (rw,nosuid,nodev,relatime,mode=750)
tmpfs on /run/wrappers type tmpfs (rw,nodev,relatime)
tmpfs on /run/user/1000 type tmpfs (rw,nosuid,nodev,relatime,size=1618848k,mode=700,uid=1000,gid=100)
Apparently another way to solve this is setting
alias mosh-server='systemd-run --user --scope mosh-server'
in the server shell. The session is still gone (looking with loginctl) but Nix is working as usual.
Thank you for your contributions.
This has been automatically marked as stale because it has had no activity for 180 days.
If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.
Here are suggestions that might help resolve this more quickly:
@rnhmjoj work-around should solve this issue.