Skip to content

Instantly share code, notes, and snippets.

@chrisguida
Last active February 10, 2025 22:40
Show Gist options
  • Save chrisguida/54d890f2929f973f45a4e5c3e4f4ddeb to your computer and use it in GitHub Desktop.
Save chrisguida/54d890f2929f973f45a4e5c3e4f4ddeb to your computer and use it in GitHub Desktop.

Installing nix-bitcoin on a OnePlus 6 (enchilada)

Build the image

(See the README for up-to-date instructions)

git clone https://github.com/chrisguida/mobile-nixos-oneplus-enchilada-template -b cguida/nix-bitcoin
cd mobile-nixos-oneplus-enchilada-template

If on nixos, make sure you have this in your configuration to do emulated builds:

{
  boot.binfmt.emulatedSystems = [ "aarch64-linux" ];
}

If not on nixos, for example on Ubuntu, you can build inside a VM:

nix run .#binfmt-sdk-nixos-shell

Now run the build

nix build .#packages.aarch64-linux.oneplus-enchilada-images

This will take a very long time unless you have an extremely fast machine. On my fastest machine it builds in a few hours. Now is a good time to unlock the phone's bootloader

Unlock Bootloader

Ensure correct software / firmware

Instructions taken from here

  • Turn on the phone
  • Connect to wifi
  • Make sure it has the latest updates (Settings -> System -> System updates)
  • Make sure it has Android 11 (Settings -> About phone -> Android version)

Enable USB debugging (on phone)

  • Open Settings, and select “About”.
  • Tap on “Build number” seven times.
  • Go back, and select “Developer options”.
  • Scroll down, and check the “Android debugging” or “USB debugging” entry under “Debugging”.
  • Plug your device into your computer.

Test to make sure it works (on computer)

  • Install adb and fastboot using nix shell nixpkgs#android-tools
  • On the computer, open up a terminal/command prompt and type adb devices.
  • A dialog should show on your device, asking you to allow usb debugging. Check “always allow”, and choose “OK”.
    • If the dialog is not appearing or the list of devices is empty, check if you installed adb properly.
    • Also try a different USB cable if you're not having any luck.
      • On Windows: Make sure your device manager does show your phone and doesn’t show a yellow triangle next to it!

The dialog should look something like this:

$ adb devices
List of devices attached
c0de3d22	device

Once that's done, you're ready to

Unlock the bootloader (Lineage docs)

  • Before you do this step, keep in mind that unlocking the bootloader will delete all your data. Make sure you don't have anything important on the phone.

  • Go to Settings -> System -> Developer Options and enable "OEM unlocking"

  • Enter adb -d reboot bootloader to reboot the phone in fastboot mode

    • You can also boot into fastboot mode via a key combination:
      • With the device powered off, hold Volume Up + Power.
  • Once the device is in fastboot mode, verify your PC finds it by typing:

fastboot devices
  • If you don’t get any output or an error:

    • on Windows: make sure the device appears in the device manager without a triangle. Try other drivers until the command above works!
    • on Linux or macOS: If you see no permissions fastboot try running fastboot as root. When the output is empty, check your USB cable and port!
  • Now type the following command to unlock the bootloader:

fastboot oem unlock

The phone will now display a warning about how you can now gasp install a custom OS. There is also a fairly important warning about the data integrity of the device being essentially compromised now. Take note, then

  • Hit the Volume Up button to highlight the "UNLOCK THE BOOTLOADER" option
  • Hit the Power button to confirm bootloader unlock

The phone will reboot and wipe all your data.

Once the image build from the first step completes, you're ready to install it onto the phone.

Install your new NixOS operating system (Mobile NixOS docs)

Flash boot images

result/flash-critical.sh

Flash system image

fastboot flash userdata result/system.img

Erase both dtbo partitions

fastboot erase dtbo_a
fastboot erase dtbo_b

Hit the power button to boot into NixOS

  • Once you see the login screen, login as defaultUser with password "default".
  • Connect the phone to Wifi. You can find the Wifi settings by swiping down twice from the top of the screen. (Not sure why one swipe isn't sufficient)
  • Now you should be able to log into the phone using SSH.
    • The default hostname is nix-enchilada for now, so ssh [email protected] should work, if your computer supports mDNS. If not, you can find your phone's IP address in the settings of your connected Wifi network.
    • Once ssh'd in, you can clone the configuration inside the phone:
git clone https://github.com/chrisguida/mobile-nixos-oneplus-enchilada-template -b cguida/nix-bitcoin

JUST KIDDING BUILDING ON THE DEVICE IS BROKEN RIGHT NOW, YOU NEED TO REBUILD FROM A REMOTE DEVICE THAT HAS A NEWER NIX VERSION

Then tweak the config to your heart's desire and when you're done, run:

sudo nixos-rebuild switch --flake .#oneplus-enchilada

If you need to rebuild mutliple services, I recommend only one concurrent job, so your phone's poor 5GB memory doesn't get overwhelmed (especially when building bitcoind and mempool simultaneously):

sudo nixos-rebuild switch --flake .#oneplus-enchilada --max-jobs 1

If you have a super fast aarch64 (or emulation-enabled x86) NixOS computer, you can rebuild on your computer instead of the phone, which might be a lot faster.

To do this, you'll need to set a root password or add your SSH key to the root user.

To set the root password run:

sudo passwd

Then run the rebuild and deploy:

nixos-rebuild --target-host root@nix-enchilada --flake .#oneplus-enchilada switch

Be sure to check out my NixOS Mutinynet Tutorial to learn how to configure your bitcoin services!

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