nixos-rebuild error in nixos-enter
- User
nixos-rebuild error in nixos-enter
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
nixos-rebuild error in nixos-enter
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Hey!
Running nixos-rebuild from inside a nixos-enter chroot can work, but a few common gotchas trip people up.
Below is a checklist of the usual suspects, why they happen, and how to fix or work around them. If none of these match what you’re seeing, let me know the exact error text and we’ll dig deeper. 🚀
nixos-rebuildInside the installer ISO you have two basic options:
| Where you run the command | Typical invocation | When it’s easiest |
|---|---|---|
| Outside the chroot (still on the ISO) | nixos-rebuild --root /mnt switch | You want the simplest path; ISO-providednixos-rebuild already has channels, nix-daemon running, etc. |
Inside the chroot entered with nixos-enter /mnt | nixos-rebuild switch (no --root) | You prefer to be “in” the future system. Requires a couple of extra prep steps (mounts, channels, daemon). |
If you don’t have a strong reason to be inside the chroot, option 1 is usually less hassle.
Symptom:
error: getting status of '/run/current-system/sw': No such file or directory
Why: In a fresh chroot, /run is empty; nixos-rebuild wants the current-system symlink to discover the running generation.
Fixes
a) From outside the chroot, just run with --root /mnt (nothing needs /run inside the chroot).
b) If you must stay in the chroot, make sure the /run tmpfs is mounted:
# still *outside* the chroot
mount --bind /run /mnt/run
Inside the ISO environment, the NIXOS channel is already set up.
Inside the chroot, you’re suddenly using the target system’s /root/.nix-defexpr. If you never ran nix-channel --add before, nixos-rebuild can’t find <nixpkgs> or <nixos-config>.
Quick rescue:
nix-channel --add https://nixos.org/channels/nixos-23.11 nixos
nix-channel --update
Or, skip channels and supply a flake explicitly:
nixos-rebuild switch --flake /etc/nixos#your-host-name
Usually harmless. The installer ISO does run the daemon, but your chroot does not. You can either:
• Ignore it
• Start the daemon inside the chroot (nix-daemon &)
• Or pass --use-remote-sudo to make nixos-rebuild talk to the host daemon.
Most people just ignore the warning.
If you ran nixos-enter without --root /mnt, sometimes /dev did not get bind-mounted correctly, so GRUB install tries to talk to the wrong block device.
Make sure you mounted the three “binds”:
mount --bind /dev /mnt/dev
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys
nixos-enter /mnt does that for you automatically; if you used plain chroot you’ll have to.
# Assuming your system root is /mnt
nixos-generate-config --root /mnt # only the first time
nano /mnt/etc/nixos/configuration.nix # edit whatever
nixos-rebuild --root /mnt switch # install system + bootloader
nixos-enter /mnt
# you are now inside the future system
nix-channel --add https://nixos.org/channels/nixos-23.11 nixos
nix-channel --update
nixos-rebuild switch
Copy-paste the exact error (with --show-trace if it’s an evaluation failure). Also helpful:
nixos-rebuild --flake ...)ls -l /mnt/run/current-system (outside chroot).nix-channel --list inside the chroot.With that info we can nail down the underlying problem quickly.
system has not been booted with systemd as init system
That message means exactly what it says:
inside the chroot opened by nixos-enter you do not have a running
systemd instance, so any tool that tries to talk to systemd
(systemctl, loginctl, …) will error out with
System has not been booted with systemd as init system (PID 1). Can't operate.
nixos-enter /mnt is just a bind-mount chroot.
The real PID 1 (systemd) is still running on the live installer that
you booted, not in the target root at /mnt.
Therefore the chroot has no “system bus” to talk to.
✅ Edit files (/etc/nixos/*.nix, fstab, users, …)
✅ Run nix-* commands (build, eval, fetch, …)
✅ Run nixos-rebuild in build/boot mode
❌ Start/stop services with systemctl
❌ Use journalctl, loginctl, … (they need a running systemd)
You ran nixos-rebuild switch inside the chroot and it failed
with the systemd error.
• Outside the chroot do:
nixos-rebuild --root /mnt switch
This talks to the installer’s systemd (which is running) while
installing the target system into /mnt.
• Or, if you prefer to stay inside the chroot:
nixos-rebuild boot # writes the system + boot-loader
exit # leave the chroot
reboot # boot into the new system
boot builds the system but skips the “activate” step that would
need systemd.
You just want to install NixOS the first time
Easiest is still the classic command from outside the chroot:
nixos-install --root /mnt
That wraps the whole build / boot-loader / user setup for you.
You really need a systemd inside the target root (e.g. for debugging a service interactively). Use instead of :
systemd-nspawnnixos-entersystemd-nspawn -D /mnt
Now PID 1 inside the container is systemd, so
systemctl, journalctl, etc. work.
| Goal | Recommended command |
|---|---|
| First install | nixos-install --root /mnt |
| Rebuild while on installer ISO | nixos-rebuild --root /mnt switch |
| Rebuild inside chroot w/o systemd | nixos-rebuild boot (or build) |
| Chroot with systemd | systemd-nspawn -D /mnt |
Seeing “system has not been booted with systemd” inside a chroot is normal and harmless; just pick the rebuild mode that doesn’t try to talk to systemd, or run the command from outside the chroot instead.
If you still hit problems, paste the exact command + full error output
(with --show-trace if it’s a Nix evaluation failure) and we’ll chase
it down. 🚀