Skip to content

How to Install NixOS on Oracle ARM machine

Posted on:August 11, 2023 at 03:12 AM

Table of contents

Open Table of contents

Step 0: Log in to Ubuntu

When setting up your Oracle server, remember to add your key or download the auto-generated keys. This ensures you can SSH into the machine:

ssh ubuntu@${your oracle machine ip}

Step 1: Install Nix(Not OS, just a command line tool)

Run the following command. When prompted, answer with n, y, y.

sh <(curl -L https://nixos.org/nix/install) --daemon

After this, you can either log out and log back in or just type bash and press enter. Next, add the NixOS channels (as of this writing, the latest stable channel is 23.05):

nix-channel --add https://nixos.org/channels/nixos-23.05 nixpkgs
nix-channel --update

Step 2: Prepare an In-memory NixOS

Following the NixOS Wiki, use cleverca22’s scripts to create the installation system:

git clone https://github.com/cleverca22/nix-tests.git
cd nix-tests/kexec
vim myconfig.nix

Here’s an example of myconfig.nix, ensure you include your SSH public key.

{
  imports = [
    ./configuration.nix
  ];

  # Make it use predictable interface names starting with eth0
  boot.kernelParams = [ "net.ifnames=0" ];

  networking.useDHCP = true;

  kexec.autoReboot = false;

  users.users.root.openssh.authorizedKeys.keys = [
    "{your id_rsa.pub file content}"
  ];
}

You can now build a full kexec-capable NixOS system from this configuration. This will produce a tarball.tar.xz file. Once this process completes, you can untar the file and run kexec to initiate the installation. In the meantime, take a break, perhaps brew yourself a cup of coffee, or gaze up at the sky for a moment of reflection. Once the process is finished, you will be automatically logged out from the current terminal session.

nix-build '<nixpkgs/nixos>' -A config.system.build.kexec_tarball -I nixos-config=./myconfig.nix
tar -xf ./result/tarball/nixos-system-aarch64-linux.tar.xz
sudo ./kexec_nixos

Step 3: Installing NixOS to disk

First, remove the old SSH known host since the system has changed, and then SSH in again:

ssh-keygen -R ${your oracle machine ip}
ssh root@${your oracle machine ip}

This will make you the root on an in-memory NixOS system. If you restart now, it reverts to Ubuntu. So, to stick with NixOS, follow the disk setup steps provided.
Once done, initiate the installation with:

# parted
(parted) rm 1
(parted) rm 15
(parted) mkpart
Partition name?  []? boot
File system type?  [ext2]? fat32
Start? 2048s
End? 10GB
(parted) print all
Model: ORACLE BlockVolume (scsi)
Disk /dev/sda: 50.0GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name  Flags
 1      1049kB  10.0GB  9999MB  fat32        boot  msftdata


(parted) set 1 boot on
(parted) set 1 esp on
(parted) mkpart
Partition name?  []?
File system type?  [ext2]? ext4
Start? 10GB
End? -1s
Warning: You requested a partition from 10.0GB to 50.0GB (sectors 19531250..97677311).
The closest location we can manage is 10.0GB to 50.0GB (sectors 19531776..97677278).
Is this still acceptable to you?
Yes/No? yes
(parted) quit

We can now make filesystems on our brand new partitions, mount them, and configure NixOS to use them, You want to at least set openssh.enable = true; and add an ssh key for root, like we did in the temporary system above.

mkfs.fat -F 32 /dev/sda1
mkfs.ext4 /dev/sda2
mkdir -p /mnt/boot
mount /dev/sda2 /mnt/
mount /dev/sda1 /mnt/boot/
nixos-generate-config --root /mnt
vim /mnt/etc/nixos/configuration.nix

Once done, initiate the installation with:

nixos-install

Then, reboot the system.

Step 4: All done

As before, remove the old SSH known host entry and SSH back in:

ssh-keygen -R ${your oracle machine ip}
ssh root@${your oracle machine ip}

Congratulations! Your Oracle machine now runs NixOS. I’ll be testing more NixOS features and will organize my findings in a subsequent post.