Skip to content

Instantly share code, notes, and snippets.

@itsnebulalol
Created March 6, 2024 22:33
Show Gist options
  • Save itsnebulalol/a5b80b996f434649942ece9fe31c9258 to your computer and use it in GitHub Desktop.
Save itsnebulalol/a5b80b996f434649942ece9fe31c9258 to your computer and use it in GitHub Desktop.
Install NixOS on an Oracle Cloud VM

NixOS on an Oracle Cloud VM

This gist was made for my own reference, but feel free to follow along. You should use your own Nix flake.

Booting NixOS

Since NixOS is not an official image for use on Oracle Cloud VM's, and users have reported that uploading the NixOS image does not work, we will use kexec to boot the installer.

sudo -i

# x86_64:
curl -L https://github.com/nix-community/nixos-images/releases/download/nixos-unstable/nixos-kexec-installer-noninteractive-x86_64-linux.tar.gz | tar -xzf- -C /root
# aarch64
curl -L https://github.com/nix-community/nixos-images/releases/download/nixos-unstable/nixos-kexec-installer-noninteractive-aarch64-linux.tar.gz | tar -xzf- -C /root

/root/kexec/run

Reconnect to SSH after being disconnected, using the root user.

Partitioning

from Ming Di Leom

fdisk /dev/sda
Command: g
Created a new GPT disklabel (GUID: xxx).

# 512MB ESP
Command: n
Partition: 1
First sector: <press Enter>
Last sector: +512M

# root partition
Command: n
Partition: 2
First sector: <press Enter>
Last sector: -1G # Use what size you want your swap partition

# Swap
Command: n
Partition: 3
First sector: <press Enter>
Last sector: <press Enter>

# Mark first partition as ESP
Command: t
Partition: 1
Type: uefi

# Verify
Command: p
Disk /dev/sda: 46.58 GiB, 50010783744 bytes, 97677312 sectors
Disk model: BlockVolume     
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 1048576 bytes
Disklabel type: gpt
Disk identifier: xxx

Device        Start      End  Sectors  Size Type
/dev/sda1      2048  1050623  1048576  512M EFI System
/dev/sda2   1050624 95580159 94529536 45.1G Linux filesystem
/dev/sda3  95580160 97677278  2097119 1024M Linux filesystem

# Write partition table
Command: w

Format

mkfs.fat -F 32 -n boot /dev/sda1
mkfs.ext4 -L nixos /dev/sda2
mkswap -L swap /dev/sda3

Mount

mkdir -p /mnt
mount /dev/disk/by-label/nixos /mnt
mkdir -p /mnt/boot
mount /dev/disk/by-label/boot /mnt/boot
swapon /dev/sda3

Configuration

Add channel

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

Prep

nixos-generate-config --root /mnt

Files

# /etc/nixos/configuration.nix

{ config, lib, pkgs, ... }: {
  imports = [ ./hardware-configuration.nix ];

  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;

  networking.hostName = "maniae";
  networking.networkmanager.enable = true;

  time.timeZone = "America/New_York";

  users.users.nebula = {
    isNormalUser = true;
    extraGroups = [ "wheel" ];
  };

  environment.systemPackages = with pkgs; [
    curl
    git
  ];

  services.openssh.enable = true;
  users.users.root.openssh.authorizedKeys.keys = [
    "ssh key here"
  ];

  system.stateVersion = "23.11";
}

Install

nixos-install

nixos-enter --root "/mnt"
passwd nebula
reboot

Apply flake

SSH into your user after reboot.

Create SSH key

ssh-keygen -t ed25519 -C "me@itsnebula.net"
cat ~/.ssh/ssh_ed25519.pub
cat /etc/ssh/ssh_host_ed25519_key.pub

# Run after adding user key to GitHub. This is done to add to known_hosts.
ssh git@github.com

secrets/secrets.nix will need to be updated with the keys.

Installation

git clone https://github.com/itsnebulalol/nixfiles
cd nixfiles
nixos-rebuild switch --flake ".#maniae"

Approve device in Tailscale admin console.

Resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment