pinephone blog: address most TODOs

This commit is contained in:
colin 2022-06-14 02:28:34 -07:00
parent 5e34b2a895
commit f63d91e06f
1 changed files with 174 additions and 55 deletions

View File

@ -7,7 +7,7 @@ extra.hidden = true
there is no official, easy-to-grab NixOS image to download and flash to devices like the pinephone today. although there is [a way](https://news.ycombinator.com/item?id=30010178) to do that via the hydra build cache, it's a bit tortured and since the images built in automation don't have a user, you'll have to manually edit `/etc/fstab` (from a different machine) to add a user and then login with a USB-C keyboard to setup ssh or a desktop.
so first, provision an existing Nix install. the architecture doesn't matter -- i'll assume it's x86_64 and show you how to cross-compile. i recommend using a flake for this. i'm basing this around nix-22.05, so something like this:
so let's bootstrap from an existing Nix install. first, provision a machine. the architecture doesn't matter -- i'll assume it's x86_64 and show you how to cross-compile. i recommend using a flake for this. i'm basing this around nix-22.05, so something like this:
```flake.nix
{
inputs = {
@ -15,7 +15,7 @@ so first, provision an existing Nix install. the architecture doesn't matter --
};
outputs = { self, nixpkgs }: {
host = nixpkgs.lib.nixosSystem {
nixosConfigurations.host = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
./host.nix
@ -31,7 +31,7 @@ TODO: does one need the configuration.nix wrapper on nixos-22.05?
## Bare-minimal Build
for our Pinephone machine, we'll let [mobile-nixos](https://github.com/NixOS/mobile-nixos/) do the heavy lifting. add it as an input
for our Pinephone machine, we'll let [mobile-nixos](https://github.com/NixOS/mobile-nixos/) do the heavy lifting. add it as an input to `flake.nix`:
```diff -u a/flake.nix b/flake.nix
inputs = {
@ -43,24 +43,11 @@ for our Pinephone machine, we'll let [mobile-nixos](https://github.com/NixOS/mob
};
```
things here move fast. depending on where things are at any moment, you might be able to use the upstream `nixpkgs` in your mobile builds, or you might need to freeze the nixpkgs to a specific commit. `mobile-nixos` pins its own pkgs. if you look at [`pkgs.nix`](https://github.com/NixOS/mobile-nixos/blob/master/pkgs.nix) you can copy the rev and track it:
```diff -u a/flake.nix b/flake.nix
inputs = {
nixpkgs.url = "nixpkgs/nixos-22.05";
mobile-nixos = {
url = "github:nixos/mobile-nixos";
flake = false;
};
+ pkgs-mobile.url = "nixpkgs/dfd82985c273aac6eced03625f454b334daae2e8";
};
```
and then add a new target for building a `pinephone-img`:
```diff -u a/flake.nix b/flake.nix
- outputs = { self, nixpkgs }: {
+ outputs = { self, nixpkgs, mobile-nixos, pkgs-mobile }: {
+ pinephone-img = (pkgs-mobile.lib.nixosSystem {
+ outputs = { self, nixpkgs, mobile-nixos }: {
+ pinephone-img = (nixpkgs.lib.nixosSystem {
+ system = "aarch64-linux";
+ modules = [
+ (import "${mobile-nixos}/lib/configuration.nix" {
@ -68,13 +55,17 @@ and then add a new target for building a `pinephone-img`:
+ })
+ ];
+ }).config.mobile.outputs.u-boot.disk-image;
nixosConfigurations.host = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
...
```
if your host machine isn't aarch64, you'll have to enable cross compiling. the trivial way is emulation (i.e. qemu), though it could make the build take a full afternoon depending on how much of your system is available through nixcache.
```diff -u a/flake.nix b/flake.nix
outputs = { self, nixpkgs }: {
host = nixpkgs.lib.nixosSystem {
outputs = { self, nixpkgs, mobile-nixos }: {
...
nixosConfigurations.host = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
./host.nix
@ -110,11 +101,115 @@ insert the card to the Pinephone and boot it. the SD slot takes precedent over t
## Making the Image More Usable
we'll want to rebuild the image and include a user, desktop environment, and some basic applications. i tried Phosh, Plasma Mobile, and Gnome: of these, Phosh works the best OOTB _by far_ (Plasma Mobile is _slow_ and crash-prone, Gnome lacks an on-screen keyboard outside the core apps and its navigation is less tailored to phones).
we'll use home-manager to make user setup a bit nicer. add that to `flake.nix`:
```diff -u a/flake.nix b/flake.nix
TODO: show how to setup users and Phosh
inputs = {
nixpkgs.url = "nixpkgs/nixos-22.05";
mobile-nixos = {
url = "github:nixos/mobile-nixos";
flake = false;
};
+ home-manager.url = "github:nix-community/home-manager/release-22.05";
};
```
build and flash the image as before. this is the final image we'll flash, so before you eject the card resize the rootfs so you can make use of the full device. do NOT use `fdisk` or `parted` for this. it disrupts some on-disk structures required by the bootloader (this won't be a worry after mobile-nixos officially switches to tow-boot). instead, use the ncurses frontend to fdisk: `cfdisk`:
add a module for this pinephone build:
```diff -u a/flake.nix b/flake.nix
- outputs = { self, nixpkgs, mobile-nixos }: {
+ outputs = { self, nixpkgs, mobile-nixos, home-manager }: {
pinephone-img = (pkgs-mobile.lib.nixosSystem {
system = "aarch64-linux";
modules = [
(import "${mobile-nixos}/lib/configuration.nix" {
device = "pine64-pinephone";
})
+ ./pinephone.nix
];
}).config.mobile.outputs.u-boot.disk-image;
...
```
and populate `pinephone.nix` as such:
```pinephone.nix
{ home-manager, pkgs }:
{
system.stateVersion = "21.11";
## enable the hardware rotation sensor
hardware.sensor.iio.enable = true;
## configure a user:
users.mutableUsers = false;
users.users.colin = {
isNormalUser = true;
home = "/home/colin";
uid = 1000;
# make this numeric so that you can enter it in the phosh lockscreen.
# DON'T leave this empty: not all greeters support passwordless users.
initialPassword = "147147";
shell = pkgs.zsh;
extraGroups = [ "wheel" ];
};
security.sudo = {
enable = true;
wheelNeedsPassword = false;
};
services.openssh = {
enable = true;
permitRootLogin = "no";
passwordAuthentication = true;
};
## configure a basic GUI:
services.xserver.desktopManager.phosh = {
enable = true;
user = "colin";
group = "users";
};
hardware.opengl.enable = true;
hardware.opengl.driSupport = true;
## set up home-manager and some useful packages:
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users.colin = {
home.stateVersion = "21.11";
home.username = "colin";
home.homeDirectory = "/home/colin";
programs = {
home-manager.enable = true;
firefox.enable = true;
};
# a few useful packages to start with
packages = with pkgs; [
# useful CLI/admin tools to have during setup
fatresize
gptfdisk
networkmanager
sudo
vim
wget
plasma5Packages.konsole
# desktop goodies
element-desktop
gnome-podcasts
vlc
];
};
}
```
build and flash the image as before. this is the final image we'll flash, so before you eject the card resize the rootfs to make use of the full device. do NOT use `fdisk` or `parted` for this. it disrupts some on-disk structures required by the bootloader (this won't be a worry after mobile-nixos officially switches to tow-boot). instead, use the ncurses frontend to fdisk: `cfdisk`:
```sh
$ sudo cfdisk /dev/sdb
@ -132,7 +227,23 @@ eject the card and boot the phone, login, and toy around with it. open the displ
we don't want to re-flash the device _every_ time we change something. let's update the flake to allow on-device updates.
```diff -u a/flake.nix b/flake.nix
TODO: add toplevel nixosConfigurations.pinephone
- outputs = { self, nixpkgs, mobile-nixos, home-manager }: {
- pinephone-img = (nixpkgs.lib.nixosSystem {
+ outputs = { self, nixpkgs, mobile-nixos, home-manager }: rec {
+ nixosConfigurations.pinephone = (nixpkgs.lib.nixosSystem {
system = "aarch64-linux";
modules = [
(import "${mobile-nixos}/lib/configuration.nix" {
device = "pine64-pinephone";
})
./pinephone.nix
];
- }).config.mobile.outputs.u-boot.disk-image;
+ });
+ pinephone-img = nixosConfigurations.pinephone.config.mobile.outputs.u-boot.disk-image;
nixosConfigurations.host = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
...
```
copy your flake over to the phone at `/etc/nixos/flake.nix`. i use git for this. on the phone:
@ -150,47 +261,55 @@ happy nixing :-)
# Troubleshooting
TODO
unbootable; unflashable (e.g. eMMC not exposed over USB)... tend to be power related issues.
the base jumpdrive image does NOT appear to charge the battery (definitely not when connected to a PC; unsure about when connected to the wall).
flash postmarketOS to SD & boot: this will charge and you'll see battery percentage
- **device is unbootable or unflashable (eMMC isn't exposed as a /dev node over USB):**
use dd flags.
these issues tend to be power-related. flash a minimal, known-good image (like [postmarketOS](https://images.postmarketos.org/pinephone/)) to the SD card and boot with the battery and USB charger plugged in. wait until the battery gets to a good charge and resume.
eMMC has a dozen or two write cycles: prefer SD card.
- **fs appears to be corrupted:**
WiFi without GUI: `nmcli device wifi connect <wifiname>`
jumpdrive
validating the built, but unflashed, image:
validate the built, but unflashed, image:
```sh
$ sudo losetup -Pf /nix/store/rp9nsr9zympcc1vqah4rckija2lb34xx-pine64-pinephone_full-disk-image.img
# create a loopback device from our .img file:
# ./result should be a symlink to /nix/store/<hash>-pine64-pinephone_full-disk-image.img
$ sudo losetup -Pf $(readlink ./result)
# check the rootfs partition (partition #4):
# you might see a single, inconsequential error about "Padding at end of inode bitmap is not set."
$ sudo fsck -f /dev/loop0p4
# close the loopback device:
$ sudo losetup -d /dev/loop0
```
validate a flashed image with `sudo fsck -f /dev/sdb4`. you might see a single, inconsequential error about `Padding at end of inode bitmap is not set.`
then flash the image using the dd flags i show in the article. while the SD card is still attached to the host, validate it with `sudo fsck -f /dev/sdb4`.
finally, the eMMC has a dozen or so write cycles: prefer an SD card.
- **i want to build a new nixos generation on the device but it needs network access:**
if you included `networkmanager` in the package list, open the `konsole` terminal, type `sudo nmtui` and follow the prompts. or directly use `nmcli device wifi connect <wifiname>`. or plug in a USB-C ethernet dongle to get a hardwired connection.
- **the nix config won't build:**
nixos moves fast, but does occasionally break. you might need to freeze the nixpkgs to a specific commit. `mobile-nixos` pins its own pkgs. if you look at [`pkgs.nix`](https://github.com/NixOS/mobile-nixos/blob/master/pkgs.nix) you can copy the rev and track it:
```diff -u a/flake.nix b/flake.nix
inputs = {
- nixpkgs.url = "nixpkgs/nixos-22.05";
+ nixpkgs.url = "nixpkgs/dfd82985c273aac6eced03625f454b334daae2e8";
mobile-nixos = {
url = "github:nixos/mobile-nixos";
flake = false;
};
};
```
# Additional Resources:
TODO: clean this section up
[NixOS from a working install](https://git.sr.ht/~tomf/notes/tree/master/item/pinephone-nixos-getting-started.md)
configuration is from a mobile-nixos local.nix repo. workable (leverages the hydra cache), but unclear how one would configure this after install (flake support?)
[HN cached build](https://news.ycombinator.com/item?id=30010178)
to get a minimal, PoC, image, flash this using Jumpdrive and it should just boot
[Jumpdrive](https://github.com/dreemurrs-embedded/Jumpdrive/releases)
[postmarketOS](https://images.postmarketos.org/pinephone/)
useful to validate flashing method
[NixOS Flakes Intro](https://nixos.wiki/wiki/Flakes)
[Mobile NixOS Flake Support](https://github.com/NixOS/mobile-nixos/pull/404)
[noneucat's pinephone config](https://git.sr.ht/~noneucat/nixos-configs/tree/master/item/deployment/pinephone/configuration.nix)
[building install media](https://hoverbear.org/blog/nix-flake-live-media/)
include module: "${nixos}/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix"
[phosh on mobile-nixos](https://github.com/mhuesch/pinephone-mobile-nixos-flake-example/blob/main/configuration-pinephone.nix)
someone's config. linked from https://github.com/NixOS/mobile-nixos/pull/352
-- closed because upstreamed: https://github.com/NixOS/nixpkgs/pull/153940
[colemicken's multi-machine flake (incl pinephone)](https://github.com/colemickens/nixcfg/blob/main/flake.nix)
- Tom Fitzhenry [building a minimal Pinephone image](https://git.sr.ht/~tomf/notes/tree/master/item/pinephone-nixos-getting-started.md) by dropping his config straight into a mobile-nixos checkout, no `flake.nix` required.
- Ana, Hoverbear on [making an install image](https://hoverbear.org/blog/nix-flake-live-media/) from an existing NixOS configuration.
- Cole Mickens' [public nix config](https://github.com/colemickens/nixcfg/blob/main) shows how to maintain a shared repo for multiple machines with more advanced things like custom packages, modules, and secrets.
- [my own nix config](https://git.uninsane.org/colin/nix-files/) which targets multiple machines with one of these operating a nix cache to speed up pinephone builds.
- Pavel Makhov showing a better way to [distribute builds across machines](https://eno.space/blog//2021/08/nixos-on-underpowered-devices) which i haven't got around to trying.
- the [NixOS Matrix space]https://matrix.to/#/#community:nixos.org) which contains chat rooms like `#nixos-on-arm:nixos.org`.
- or contact me directly via the links in my [about](/about) page.