Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The result of (nixos-install && nixos-enter) lacks the /tmp directory #39140

Closed
pvgoran opened this issue Apr 19, 2018 · 10 comments · Fixed by #80769
Closed

The result of (nixos-install && nixos-enter) lacks the /tmp directory #39140

pvgoran opened this issue Apr 19, 2018 · 10 comments · Fixed by #80769

Comments

@pvgoran
Copy link
Contributor

pvgoran commented Apr 19, 2018

Issue description

I have a process that creates a "clean" NixOS filesystem tree for later usage. First, I create the minimal NixOS configuration files at $ROOT/etc/nixos, then I run:

nixos-install --no-bootloader --no-root-passwd --root "$ROOT"
nixos-enter --root "$ROOT" -- true

(Before 18.03, it worked without nixos-enter. I'm not very happy that now I need an additional step, and I'll probably create a separate issue about this. But I can understand that nixos-install creates a minimal installation and nixos-enter activates it.)

I expect to be able to chroot into the resulting filesystem tree and have a fully-working NixOS system. However, these steps don't create the /tmp directory, which prevents nixos-rebuild from working:

[root@nixos-seed:/]# nixos-rebuild dry-build
mktemp: failed to create directory via template ‘/tmp/nixos-rebuild.XXXXXX’: No such file or directory

Steps to reproduce

Build the NixOS tree:

mkdir seed
mkdir -p seed/etc/nixos
cat >seed/etc/nixos/configuration.nix <<END
{ config, pkgs, ... }:
{
  boot.loader.grub.enable = true;
  boot.loader.grub.version = 2;
  boot.loader.grub.device = "/dev/dummy";

  fileSystems."/" =
    { device = "/dev/dummy";
      fsType = "ext4";
    };
}
END
nixos-install --no-bootloader --no-root-passwd --root $(realpath seed)
nixos-enter --root $(realpath seed) -- true

Then try to work in it:

nixos-enter --root $(realpath seed) -- nixos-rebuild dry-build

Technical details

  • system: "x86_64-linux"
  • host os: Linux 4.14.34, NixOS, 18.03.132021.c0c5571ec1a (Impala)
  • multi-user?: yes
  • sandbox: no
  • version: nix-env (Nix) 2.0
  • channels(paul): ""
  • channels(root): "nixos-18.03.132021.c0c5571ec1a"
  • nixpkgs: /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs
@CMCDragonkai
Copy link
Member

That is pretty cool, how do you switch to the seed later? Is the seed mounted from a remote machine?

@pvgoran
Copy link
Contributor Author

pvgoran commented Nov 16, 2018

@CMCDragonkai The seed is packed into a squashfs image which is transferred to the target system. Then a script is run which mounts the image, chroots into it, rsyncs the seed onto the target system's root, and finally chroots the second time into the root to run nixos-rebuild boot.

chkno added a commit to chkno/nixpkgs that referenced this issue Feb 22, 2020
chkno added a commit to chkno/nixpkgs that referenced this issue Feb 22, 2020
/tmp is normally created by the systemd-tmpfiles-setup systemd service
at startup.

Fixes NixOS#39140
@chkno
Copy link
Member

chkno commented Feb 22, 2020

For concreteness: A fix for this problem would cause this test to pass, or at least fail for a different reason. Currently this test fails with this output:

$ nix-build nixos/tests/installer.nix -A simple
...
Can build things in the installed environment
machine: must succeed: nixos-enter -- nix-build ...
machine # setting up /etc...
machine # error: getting status of '/tmp': No such file or directory
machine: output:
error: command `nixos-enter -- nix-build ... failed (exit code 1)

Adding mkdir --mode 1777 /mnt/tmp allows the test to continue.


It looks like /tmp is normally created by the systemd-tmpfiles-setup systemd service which runs at boot. Starting up systemd seems out-of-scope for nixos-enter. Perhaps it should just run systemd-tmpfiles --create --remove --exclude-prefix=/dev like switch-to-configuration.pl does.

@stale
Copy link

stale bot commented Aug 20, 2020

Hello, I'm a bot and I thank you in the name of the community for opening this issue.

To help our human contributors focus on the most-relevant reports, I check up on old issues to see if they're still relevant. This issue has had no activity for 180 days, and so I marked it as stale, but you can rest assured it will never be closed by a non-human.

The community would appreciate your effort in checking if the issue is still valid. If it isn't, please close it.

If the issue persists, and you'd like to remove the stale label, you simply need to leave a comment. Your comment can be as simple as "still important to me". If you'd like it to get more attention, you can ask for help by searching for maintainers and people that previously touched related code and @ mention them in a comment. You can use Git blame or GitHub's web interface on the relevant files to find them.

Lastly, you can always ask for help at our Discourse Forum or at #nixos' IRC channel.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Aug 20, 2020
@pvgoran
Copy link
Contributor Author

pvgoran commented Aug 20, 2020

This issue is still relevant.

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Aug 20, 2020
@louwers
Copy link

louwers commented Sep 17, 2022

Still a problem when just using nixos-install!

@Mikilio
Copy link
Contributor

Mikilio commented Nov 3, 2022

This issue should be reopened as it is the root cause of other problems like #73404. The line added with the fix (#80769) of this issue seems to fail on many uses of nixos-install.sh which calls nixos-enter.sh when attempting to install the bootloader. The error given is not being able to find the command systemd-tmpfiles when using chroot at this stage. Does anyone know why systemd-tmpfiles was supposed to be in PATH here in the first place? I can not understand how this fix used to work before.

@nh2
Copy link
Contributor

nh2 commented Nov 3, 2022

Reopening based on reports above.

@nh2 nh2 reopened this Nov 3, 2022
@Mikilio
Copy link
Contributor

Mikilio commented Nov 3, 2022

Regarding my previous comment, I have confirmed that systemd-tmpfiles is indeed not in the PATH and one should not assume that it would be there. That is because the dependency of nixos-enter on systemd hasn't been declared in tools.nix where it should be. The fix should be easy, so I will submit a pull request.

@ncfavier
Copy link
Member

ncfavier commented Jan 1, 2023

Fixed by #199425

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants