Skip to content

nixos-install fails if /mnt is not empty #244643

@mode89

Description

@mode89

Describe the bug

If there are any files under /mnt (of the target's root file system), nixos-install fails.

Steps To Reproduce

Steps to reproduce the behavior:

  1. Boot into NixOS live CD.
  2. Mount target's root partition as /mnt.
  3. Mount target's boot partition as /mnt/boot.
  4. Create /mnt/mnt directory.
  5. Create a file under /mnt/mnt: touch /mnt/mnt/file.
  6. Generate configuration files: nixos-generate-config --root /mnt.
  7. Run nixos-install.

Expected behavior

nixos-install should finish normally.

Additional context

The last lines of nixos-install's output:

installing the boot loader...
setting up /etc...
updating GRUB 2 menu...
installing the GRUB 2 boot loader on /dev/sda...
Installing for i386-pc platform.
Installation finished. No error reported.
rmdir: failed to remove '/mnt': Directory not empty

In my usage scenario I keep the NixOS configuration files on a separate partition that should be mounted as a directory under the target's /mnt, and /etc/nixos/configuration.nix is a relative symbolic link pointing to that location.

I can confirm that nixos-install on NixOS 22.05 doesn't have this issue.

I think that the culprit could be this line, and probably rmdir should be replaced by rm -r.

Notify maintainers

@rnhmjoj
@ncfavier

Metadata

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
- system: "x86_64-linux"
- host os: `Linux 6.1.31, NixOS, 23.05 (Stoat), 23.05pre-git`
- multi-user?: `yes`
- sandbox: `yes`
- version: `nix-env (Nix) 2.13.3`
- channels(root): `"nixos-23.05pre-git"`
- nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions