Home Explore Blog CI



nixpkgs

3rd chunk of `nixos/doc/manual/installation/installing-from-other-distro.section.md`
0c4d727d12f748dddf07d242fb60bcc1972a0f06d169cfad0000000100000be8
    ::: {.note}
    The lustrate process will not work if the [](#opt-boot.initrd.systemd.enable) option is set to `true`.
    If you want to use this option, wait until after the first boot into the NixOS system to enable it and rebuild.
    :::

    You'll likely want to set a root password for your first boot using
    the configuration files because you won't have a chance to enter a
    password until after you reboot. You can initialize the root password
    to an empty one with this line: (and of course don't forget to set
    one once you've rebooted or to lock the account with
    `sudo passwd -l root` if you use `sudo`)

    ```nix
    {
      users.users.root.initialHashedPassword = "";
    }
    ```

1.  Build the NixOS closure and install it in the `system` profile:

    ```ShellSession
    $ nix-env -p /nix/var/nix/profiles/system -f '<nixpkgs/nixos>' -I nixos-config=/etc/nixos/configuration.nix -iA system
    ```

1.  Change ownership of the `/nix` tree to root (since your Nix install
    was probably single user):

    ```ShellSession
    $ sudo chown -R 0:0 /nix
    ```

1.  Set up the `/etc/NIXOS` and `/etc/NIXOS_LUSTRATE` files:

    `/etc/NIXOS` officializes that this is now a NixOS partition (the
    bootup scripts require its presence).

    `/etc/NIXOS_LUSTRATE` tells the NixOS bootup scripts to move
    *everything* that's in the root partition to `/old-root`. This will
    move your existing distribution out of the way in the very early
    stages of the NixOS bootup. There are exceptions (we do need to keep
    NixOS there after all), so the NixOS lustrate process will not
    touch:

    -   The `/nix` directory

    -   The `/boot` directory

    -   Any file or directory listed in `/etc/NIXOS_LUSTRATE` (one per
        line)

    ::: {.note}
    The act of "lustrating" refers to the wiping of the existing distribution.
    Creating `/etc/NIXOS_LUSTRATE` can also be used on NixOS to remove
    all mutable files from your root partition (anything that's not in
    `/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`.

Title: Finalizing NixOS Installation and Boot Setup
Summary
The text outlines the final steps for completing a NixOS installation, specifically focusing on setting a root password, building the NixOS closure and installing it in the system profile, changing ownership of the /nix tree to root, and setting up /etc/NIXOS and /etc/NIXOS_LUSTRATE files for proper boot behavior. It also includes a note about the `boot.initrd.systemd.enable` option and explains the concept of "lustrating" the existing distribution, which involves moving everything from the root partition to `/old-root` during bootup, with exceptions for /nix, /boot, and any files listed in `/etc/NIXOS_LUSTRATE`. Finally, it details the process of installing NixOS's boot system, with considerations for BIOS and UEFI systems.