[Xiaomi Mi 9 ROMs, Kernels, Recoveries, & Other Dev] photonmedia:
ThePiGuy already has a great overview of building for unsupported/unofficial devices here

You'll need to install all the base requirements on your build distro before you proceed. This includes the adb and fastboot tools, the build packages, and the java versions as mentioned in this LineageOS build guide for one of their other Xiaomi "supported" devices.

What I post here is basically my method of pulling the relevant info from the two build guides above to get a successful build for the Xiaomi Mi 9 (cepheus).

I will say as for the Requirements, it really needs to be 16GB of RAM. I tried building in a VM with 8GB multiple times and it failed due to running out of memory. This could just be because I run on SSDs and do not use SWAP space/files...

When it comes to your Proprietary Blobs, I pulled mine from Demon000's Github Source

You will need these repos, and we will cover these steps further down:

vendor_xiaomi

kernel_xiaomi_sm8150

device_xiaomi_cepheus

device_xiaomi_sm8150_common

When performing the "ccache -M $G" command I used:

ccache -M 50G

Now let's create your base folder where you want to make all the magic happen. Be sure to have plenty of storage available. In my case, I needed about 200GB.

mkdir -p ~/android/lineage
cd ~/android/lineage

When performing your repo init commands, reference branch 17.1:

repo init -u https://github.com/LineageOS/android.git -b lineage-17.1

Sync the repo to your current working directory, in this case the lineage folder you created above (which should still be your working directory):

repo sync

This will pull down 100+GB of files, so this takes quite some time.

Following along, you should be in your folder called "lineage" where you ran your repo init and repo sync commands. In my case this is:

~/android/lineage/

Attached is my manifest file called "cepheus.xml" that references the Demon000 github source.

Place this cepheus.xml file here:

~/android/lineage/.repo/local_manifests/cepheus.xml

(creating the local_manifests folder if necessary)

Now you need to complete the build of your device tree.

You will clone each of the four repositories above into their respective locations in the device tree:

vendor_xiaomi -> ~/android/lineage/vendor/xiaomi/

kernel_xiaomi_sm8150 -> ~/android/lineage/kernel/xiaomi/sm8150

device_xiaomi_cepheus -> ~/android/lineage/device/xiaomi/cepheus

device_xiaomi_sm8150_common -> ~/android/lineage/device/sm8150_common

Note: Be sure to check each of those four locations and make sure the contents of the repository are in those folders, not, for example: ~/android/lineage/device/sm8150_common/device_xiaomi_sm8150_common. You don't want the repo contents within that extra subfolder...

In my case, I created the necessary directory structure and changed to that directory, then cloned the repo and moved the contents from the subfolder created by the clone operation into the correct location.

mkdir -p ~/android/lineage/vendor/xiaomi/
cd ~/android/lineage/vendor/xiaomi
git clone https://github.com/Demon000/vendor_xiaomi.git
mv vendor_xiaomi/* .
rm -r vendor_xiaomi

mkdir -p ~/android/lineage/kernel/xiaomi/sm8150
cd ~/android/lineage/kernel/xiaomi/sm8150
git clone https://github.com/Demon000/kernel_xiaomi_sm8150.git
mv kernel_xiaomi_sm8150/* .
rm -r kernel_xiaomi_sm8150

mkdir -p ~/android/lineage/device/xiaomi/cepheus
cd ~/android/lineage/device/xiaomi/cepheus
git clone https://github.com/Demon000/device_xiaomi_cepheus.git
mv device_xiaomi_cepheus/* .
rm -r device_xiaomi_cepheus

mkdir -p ~/android/lineage/device/xiaomi/sm8150_common
cd ~/android/lineage/device/xiaomi/sm8150_common
git clone https://github.com/Demon000/device_xiaomi_sm8150_common.git
mv device_xiaomi_sm8150_common/* .
rm -r device_xiaomi_sm8150_common

Now return to your base lineage folder:

cd ~/android/lineage

Now that you have init'd and synced your repo and pulled your proprietary blobs into their respective folders, you are ready to build with the brunch command:

export ANDROID_JACK_VM_ARGS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4G"
export USE_CCACHE=1
ccache -M 50G
source build/envsetup.sh
brunch lineage_cepheus-userdebug

For me, I have no idea how long this took to complete as I left it running overnight. I would imaging at least 4 hours on my i5 device. Once it's done, you should have a TWRP-flashable zip and an OTA zip in the ~/android/lineage/out folder.

Note: If after compiling for some time, the process fails with errors, it should provide you with information on how to track down the error. In my case, I ended up with it stopping with a failure a couple times, but I just re-ran the above brunch command and it picked up where it left off, eventually completing successfully. YMMV

I'm sure there are cleaner, simpler ways of going about this, but I'm just getting my feet wet with current Android source. I haven't really done any sort of Android "development" since the days of KitKat...