Home Explore Blog Models CI



nixpkgs

4th chunk of `nixos/doc/manual/installation/installing-from-other-distro.section.md`
1e91cf2af637b24d2c0d3a1c4b6c4f1615521913f78d91850000000100000f0e
    `/nix` or `/boot` gets "lustrated" on the next boot.

    lustrate /ˈlʌstreɪt/ verb.

    purify by expiatory sacrifice, ceremonial washing, or some other
    ritual action.
    :::

    Let's create the files:

    ```ShellSession
    $ sudo touch /etc/NIXOS
    $ sudo touch /etc/NIXOS_LUSTRATE
    ```

    Let's also make sure the NixOS configuration files are kept once we
    reboot on NixOS:

    ```ShellSession
    $ echo etc/nixos | sudo tee -a /etc/NIXOS_LUSTRATE
    ```

1.  Finally, install NixOS's boot system, backing up the current boot system's files in the process.

    The details of this step can vary depending on the bootloader configuration in NixOS and the bootloader in use by the current system.

    The commands below should work for:

    - [BIOS](https://en.wikipedia.org/wiki/BIOS) systems.

    - [UEFI](https://en.wikipedia.org/wiki/UEFI) systems where both the current system and NixOS mount the [EFI System Partition](https://en.wikipedia.org/wiki/EFI_system_partition) on `/boot`.
      Both [systemd-boot](https://systemd.io/BOOT/) and [grub](https://www.gnu.org/software/grub/index.html) expect this by default in NixOS, but other distributions vary.

    ::: {.warning}
    Once you complete this step, your current distribution will no longer be bootable!
    If you didn't get all the NixOS configuration right, especially those settings pertaining to boot loading and root partition, NixOS may not be bootable either.
    Have a USB rescue device ready in case this happens.
    :::

    ::: {.warning}
    On [UEFI](https://en.wikipedia.org/wiki/UEFI) systems, anything on the [EFI System Partition](https://en.wikipedia.org/wiki/EFI_system_partition) will be removed by these commands, such as other coexisting OS's bootloaders.
    :::

    ```ShellSession
    $ sudo mkdir /boot.bak && sudo mv /boot/* /boot.bak &&
    sudo NIXOS_INSTALL_BOOTLOADER=1 /nix/var/nix/profiles/system/bin/switch-to-configuration boot
    ```

    Cross your fingers, reboot, hopefully you should get a NixOS prompt!

    In other cases, most commonly where the [EFI System Partition](https://en.wikipedia.org/wiki/EFI_system_partition) of the current system is instead mounted on `/boot/efi`, the goal is to:

    - Make sure `/boot` (and the [EFI System Partition](https://en.wikipedia.org/wiki/EFI_system_partition), if mounted elsewhere) are mounted how the NixOS configuration would mount them.

    - Clear them of files related to the current system, backing them up outside of `/boot`.
      NixOS will move the backups into `/old-root` along with everything else when it first boots.

    - Instruct the NixOS closure built earlier to install its bootloader with:
      ```ShellSession
      sudo NIXOS_INSTALL_BOOTLOADER=1 /nix/var/nix/profiles/system/bin/switch-to-configuration boot
      ```

1.  If for some reason you want to revert to the old distribution,
    you'll need to boot on a USB rescue disk and do something along
    these lines:

    ```ShellSession
    # mkdir root
    # mount /dev/sdaX root
    # mkdir root/nixos-root
    # mv -v root/* root/nixos-root/
    # mv -v root/nixos-root/old-root/* root/
    # mv -v root/boot.bak root/boot  # We had renamed this by hand earlier
    # umount root
    # reboot
    ```

    This may work as is or you might also need to reinstall the boot
    loader.

    And of course, if you're happy with NixOS and no longer need the
    old distribution:

    ```ShellSession
    sudo rm -rf /old-root
    ```

1.  It's also worth noting that this whole process can be automated.
    This is especially useful for Cloud VMs, where provider do not
    provide NixOS. For instance,
    [nixos-infect](https://github.com/elitak/nixos-infect) uses the
    lustrate process to convert Digital Ocean droplets to NixOS from
    other distributions automatically.

Title: NixOS Bootloader Installation, System Reversion, and Automation
Summary
This chunk details the final steps of an in-place NixOS installation via `NIXOS_LUSTRATE`. It covers creating `/etc/NIXOS` and `/etc/NIXOS_LUSTRATE` (adding `etc/nixos` to preserve configs), and installing NixOS's boot system. Specific commands are provided for BIOS and UEFI systems (with EFI mounted on `/boot`), alongside warnings about rendering the old OS unbootable and potentially clearing other UEFI bootloaders; a rescue device is advised. Guidance is also given for UEFI systems with different EFI partition mounts. Finally, it outlines manual reversion to the old distribution using a rescue disk, cleaning up `/old-root` after successful adoption, and mentions automation tools like `nixos-infect` for cloud VMs.