2018-03-03 21:27:14 +01:00
|
|
|
|
<!-- vim: set expandtab ts=2 softtabstop=2 shiftwidth=2 smarttab textwidth=80 wrapmargin=2 -->
|
|
|
|
|
<section
|
|
|
|
|
xmlns="http://docbook.org/ns/docbook"
|
|
|
|
|
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
|
|
|
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
|
|
|
version="5.0"
|
|
|
|
|
xml:id="sec-installing-from-other-distro">
|
2018-05-02 01:57:09 +02:00
|
|
|
|
<title>Installing from another Linux distribution</title>
|
|
|
|
|
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
Because Nix (the package manager) & Nixpkgs (the Nix packages collection)
|
|
|
|
|
can both be installed on any (most?) Linux distributions, they can be used to
|
|
|
|
|
install NixOS in various creative ways. You can, for instance:
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
|
|
|
|
|
<orderedlist>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
Install NixOS on another partition, from your existing Linux distribution
|
|
|
|
|
(without the use of a USB or optical device!)
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
Install NixOS on the same partition (in place!), from your existing
|
|
|
|
|
non-NixOS Linux distribution using <literal>NIXOS_LUSTRATE</literal>.
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
Install NixOS on your hard drive from the Live CD of any Linux
|
|
|
|
|
distribution.
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
</orderedlist>
|
|
|
|
|
|
|
|
|
|
<para>
|
|
|
|
|
The first steps to all these are the same:
|
|
|
|
|
</para>
|
|
|
|
|
|
|
|
|
|
<orderedlist>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
|
|
|
|
Install the Nix package manager:
|
|
|
|
|
</para>
|
|
|
|
|
<para>
|
|
|
|
|
Short version:
|
|
|
|
|
</para>
|
|
|
|
|
<screen>
|
2019-06-17 12:01:51 +02:00
|
|
|
|
<prompt>$ </prompt>curl https://nixos.org/nix/install | sh
|
|
|
|
|
<prompt>$ </prompt>. $HOME/.nix-profile/etc/profile.d/nix.sh # …or open a fresh shell</screen>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
More details in the
|
|
|
|
|
<link
|
|
|
|
|
xlink:href="https://nixos.org/nix/manual/#chap-quick-start">
|
|
|
|
|
Nix manual</link>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
|
|
|
|
Switch to the NixOS channel:
|
|
|
|
|
</para>
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
If you've just installed Nix on a non-NixOS distribution, you will be on
|
|
|
|
|
the <literal>nixpkgs</literal> channel by default.
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
<screen>
|
2019-06-17 12:01:51 +02:00
|
|
|
|
<prompt>$ </prompt>nix-channel --list
|
2018-03-03 21:27:14 +01:00
|
|
|
|
nixpkgs https://nixos.org/channels/nixpkgs-unstable</screen>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
As that channel gets released without running the NixOS tests, it will be
|
|
|
|
|
safer to use the <literal>nixos-*</literal> channels instead:
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
<screen>
|
2019-06-17 12:01:51 +02:00
|
|
|
|
<prompt>$ </prompt>nix-channel --add https://nixos.org/channels/nixos-<replaceable>version</replaceable> nixpkgs</screen>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
You may want to throw in a <literal>nix-channel --update</literal> for good
|
|
|
|
|
measure.
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
|
|
|
|
Install the NixOS installation tools:
|
|
|
|
|
</para>
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
You'll need <literal>nixos-generate-config</literal> and
|
|
|
|
|
<literal>nixos-install</literal> and we'll throw in some man pages and
|
|
|
|
|
<literal>nixos-enter</literal> just in case you want to chroot into your
|
|
|
|
|
NixOS partition. They are installed by default on NixOS, but you don't have
|
|
|
|
|
NixOS yet..
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
2019-06-17 12:01:51 +02:00
|
|
|
|
<screen><prompt>$ </prompt>nix-env -iE "_: with import <nixpkgs/nixos> { configuration = {}; }; with config.system.build; [ nixos-generate-config nixos-install nixos-enter manual.manpages ]"</screen>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<note>
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
The following 5 steps are only for installing NixOS to another partition.
|
|
|
|
|
For installing NixOS in place using <literal>NIXOS_LUSTRATE</literal>,
|
|
|
|
|
skip ahead.
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
</note>
|
|
|
|
|
<para>
|
|
|
|
|
Prepare your target partition:
|
|
|
|
|
</para>
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
At this point it is time to prepare your target partition. Please refer to
|
|
|
|
|
the partitioning, file-system creation, and mounting steps of
|
|
|
|
|
<xref linkend="sec-installation" />
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
If you're about to install NixOS in place using
|
|
|
|
|
<literal>NIXOS_LUSTRATE</literal> there is nothing to do for this step.
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
|
|
|
|
Generate your NixOS configuration:
|
|
|
|
|
</para>
|
2019-06-17 12:01:51 +02:00
|
|
|
|
<screen><prompt>$ </prompt>sudo `which nixos-generate-config` --root /mnt</screen>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
You'll probably want to edit the configuration files. Refer to the
|
|
|
|
|
<literal>nixos-generate-config</literal> step in
|
|
|
|
|
<xref
|
|
|
|
|
linkend="sec-installation" /> for more
|
|
|
|
|
information.
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
Consider setting up the NixOS bootloader to give you the ability to boot on
|
|
|
|
|
your existing Linux partition. For instance, if you're using GRUB and your
|
|
|
|
|
existing distribution is running Ubuntu, you may want to add something like
|
|
|
|
|
this to your <literal>configuration.nix</literal>:
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
<programlisting>
|
2018-04-05 10:43:56 +02:00
|
|
|
|
<xref linkend="opt-boot.loader.grub.extraEntries"/> = ''
|
2018-03-03 21:27:14 +01:00
|
|
|
|
menuentry "Ubuntu" {
|
|
|
|
|
search --set=ubuntu --fs-uuid 3cc3e652-0c1f-4800-8451-033754f68e6e
|
|
|
|
|
configfile "($ubuntu)/boot/grub/grub.cfg"
|
|
|
|
|
}
|
|
|
|
|
'';</programlisting>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
(You can find the appropriate UUID for your partition in
|
|
|
|
|
<literal>/dev/disk/by-uuid</literal>)
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
Create the <literal>nixbld</literal> group and user on your original
|
|
|
|
|
distribution:
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
<screen>
|
2019-06-17 12:01:51 +02:00
|
|
|
|
<prompt>$ </prompt>sudo groupadd -g 30000 nixbld
|
|
|
|
|
<prompt>$ </prompt>sudo useradd -u 30000 -g nixbld -G nixbld nixbld</screen>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
|
|
|
|
Download/build/install NixOS:
|
|
|
|
|
</para>
|
|
|
|
|
<warning>
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
Once you complete this step, you might no longer be able to boot on
|
|
|
|
|
existing systems without the help of a rescue USB drive or similar.
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
</warning>
|
2019-06-17 12:01:51 +02:00
|
|
|
|
<screen><prompt>$ </prompt>sudo PATH="$PATH" NIX_PATH="$NIX_PATH" `which nixos-install` --root /mnt</screen>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
Again, please refer to the <literal>nixos-install</literal> step in
|
|
|
|
|
<xref linkend="sec-installation" /> for more information.
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
<para>
|
|
|
|
|
That should be it for installation to another partition!
|
|
|
|
|
</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
|
|
|
|
Optionally, you may want to clean up your non-NixOS distribution:
|
|
|
|
|
</para>
|
|
|
|
|
<screen>
|
2019-06-17 12:01:51 +02:00
|
|
|
|
<prompt>$ </prompt>sudo userdel nixbld
|
|
|
|
|
<prompt>$ </prompt>sudo groupdel nixbld</screen>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
If you do not wish to keep the Nix package manager installed either, run
|
|
|
|
|
something like <literal>sudo rm -rv ~/.nix-* /nix</literal> and remove the
|
|
|
|
|
line that the Nix installer added to your <literal>~/.profile</literal>.
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<note>
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
The following steps are only for installing NixOS in place using
|
|
|
|
|
<literal>NIXOS_LUSTRATE</literal>:
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
</note>
|
|
|
|
|
<para>
|
|
|
|
|
Generate your NixOS configuration:
|
|
|
|
|
</para>
|
2019-06-17 12:01:51 +02:00
|
|
|
|
<screen><prompt>$ </prompt>sudo `which nixos-generate-config` --root /</screen>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
Note that this will place the generated configuration files in
|
|
|
|
|
<literal>/etc/nixos</literal>. You'll probably want to edit the
|
|
|
|
|
configuration files. Refer to the <literal>nixos-generate-config</literal>
|
|
|
|
|
step in <xref
|
|
|
|
|
linkend="sec-installation" /> for more
|
|
|
|
|
information.
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
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 initalize 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 <literal>sudo passwd -l root</literal> if you
|
|
|
|
|
use <literal>sudo</literal>)
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
<programlisting>
|
2018-06-28 23:48:38 +02:00
|
|
|
|
<link linkend="opt-users.users._name__.initialHashedPassword">users.users.root.initialHashedPassword</link> = "";
|
2019-06-17 12:01:51 +02:00
|
|
|
|
</programlisting>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
Build the NixOS closure and install it in the <literal>system</literal>
|
|
|
|
|
profile:
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
2019-06-17 12:01:51 +02:00
|
|
|
|
<screen><prompt>$ </prompt>nix-env -p /nix/var/nix/profiles/system -f '<nixpkgs/nixos>' -I nixos-config=/etc/nixos/configuration.nix -iA system</screen>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
Change ownership of the <literal>/nix</literal> tree to root (since your
|
|
|
|
|
Nix install was probably single user):
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
2019-06-17 12:01:51 +02:00
|
|
|
|
<screen><prompt>$ </prompt>sudo chown -R 0.0 /nix</screen>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
Set up the <literal>/etc/NIXOS</literal> and
|
|
|
|
|
<literal>/etc/NIXOS_LUSTRATE</literal> files:
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
<literal>/etc/NIXOS</literal> officializes that this is now a NixOS
|
|
|
|
|
partition (the bootup scripts require its presence).
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
<literal>/etc/NIXOS_LUSTRATE</literal> tells the NixOS bootup scripts to
|
|
|
|
|
move <emphasis>everything</emphasis> that's in the root partition to
|
|
|
|
|
<literal>/old-root</literal>. 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:
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
<itemizedlist>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
|
|
|
|
The <literal>/nix</literal> directory
|
|
|
|
|
</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
|
|
|
|
The <literal>/boot</literal> directory
|
|
|
|
|
</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
Any file or directory listed in <literal>/etc/NIXOS_LUSTRATE</literal>
|
|
|
|
|
(one per line)
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
</itemizedlist>
|
|
|
|
|
<note>
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
Support for <literal>NIXOS_LUSTRATE</literal> was added in NixOS 16.09.
|
|
|
|
|
The act of "lustrating" refers to the wiping of the existing distribution.
|
|
|
|
|
Creating <literal>/etc/NIXOS_LUSTRATE</literal> can also be used on NixOS
|
|
|
|
|
to remove all mutable files from your root partition (anything that's not
|
|
|
|
|
in <literal>/nix</literal> or <literal>/boot</literal> gets "lustrated" on
|
|
|
|
|
the next boot.
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
<para>
|
|
|
|
|
lustrate /ˈlʌstreɪt/ verb.
|
|
|
|
|
</para>
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
purify by expiatory sacrifice, ceremonial washing, or some other ritual
|
|
|
|
|
action.
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
</note>
|
|
|
|
|
<para>
|
|
|
|
|
Let's create the files:
|
|
|
|
|
</para>
|
|
|
|
|
<screen>
|
2019-06-17 12:01:51 +02:00
|
|
|
|
<prompt>$ </prompt>sudo touch /etc/NIXOS
|
|
|
|
|
<prompt>$ </prompt>sudo touch /etc/NIXOS_LUSTRATE
|
|
|
|
|
</screen>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
Let's also make sure the NixOS configuration files are kept once we reboot
|
|
|
|
|
on NixOS:
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
<screen>
|
2019-06-17 12:01:51 +02:00
|
|
|
|
<prompt>$ </prompt>echo etc/nixos | sudo tee -a /etc/NIXOS_LUSTRATE
|
|
|
|
|
</screen>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
Finally, move the <literal>/boot</literal> directory of your current
|
|
|
|
|
distribution out of the way (the lustrate process will take care of the
|
|
|
|
|
rest once you reboot, but this one must be moved out now because NixOS
|
|
|
|
|
needs to install its own boot files:
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
<warning>
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
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.
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
</warning>
|
|
|
|
|
<screen>
|
2019-06-17 12:01:51 +02:00
|
|
|
|
<prompt>$ </prompt>sudo mv -v /boot /boot.bak &&
|
|
|
|
|
sudo /nix/var/nix/profiles/system/bin/switch-to-configuration boot
|
|
|
|
|
</screen>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
<para>
|
|
|
|
|
Cross your fingers, reboot, hopefully you should get a NixOS prompt!
|
|
|
|
|
</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
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:
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
<screen>
|
2018-03-03 21:27:14 +01:00
|
|
|
|
# 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</screen>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
<para>
|
|
|
|
|
This may work as is or you might also need to reinstall the boot loader
|
|
|
|
|
</para>
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
And of course, if you're happy with NixOS and no longer need the old
|
|
|
|
|
distribution:
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
<screen>sudo rm -rf /old-root</screen>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
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,
|
|
|
|
|
<link
|
|
|
|
|
xlink:href="https://github.com/elitak/nixos-infect">nixos-infect</link>
|
|
|
|
|
uses the lustrate process to convert Digital Ocean droplets to NixOS from
|
|
|
|
|
other distributions automatically.
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
</orderedlist>
|
2018-03-03 21:27:14 +01:00
|
|
|
|
</section>
|