Home Explore Blog Models CI



nixpkgs

3rd chunk of `nixos/doc/manual/installation/installing-from-other-distro.section.md`
cd5faba92ed9cbf91cd29fa0167c9e596edd053379136eea0000000100000bde
    ::: {.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: Completing NixOS In-Place Installation via NIXOS_LUSTRATE
Summary
This chunk details the final steps for an in-place NixOS installation using the `NIXOS_LUSTRATE` process. It reminds users to defer enabling `boot.initrd.systemd.enable` until after the first boot and advises setting an initial root password for convenience. The instructions cover building and installing the NixOS system closure to the `/nix/var/nix/profiles/system` profile, changing `/nix` ownership to root, and setting up the critical `/etc/NIXOS` and `/etc/NIXOS_LUSTRATE` files. The `/etc/NIXOS_LUSTRATE` file is explained as the mechanism that moves the old distribution to `/old-root` during boot, with specific directories like `/nix` and `/boot` being exempted, and users are instructed to add `/etc/nixos` to it. The chunk concludes by preparing to install NixOS's boot system, noting compatibility for BIOS and specific UEFI configurations.