blog: pinephone nixos: fill in some of the code TODOs
This commit is contained in:
parent
74750128ee
commit
b9b7d34a35
|
@ -5,34 +5,93 @@ description = "a flake-based quickstart and some tuning"
|
|||
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.
|
||||
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:
|
||||
```flake.nix
|
||||
TODO
|
||||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "nixpkgs/nixos-22.05";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs }: {
|
||||
host = nixpkgs.lib.nixosSystem {
|
||||
system = "x86_64-linux";
|
||||
modules = [
|
||||
./host.nix
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
```configuration.nix
|
||||
TODO
|
||||
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.
|
||||
for our Pinephone machine, we'll let [mobile-nixos](https://github.com/NixOS/mobile-nixos/) do the heavy lifting. add it as an input
|
||||
|
||||
```diff -u a/flake.nix b/flake.nix
|
||||
TODO: minimal NixOS install
|
||||
inputs = {
|
||||
nixpkgs.url = "nixpkgs/nixos-22.05";
|
||||
+ mobile-nixos = {
|
||||
+ url = "github:nixos/mobile-nixos";
|
||||
+ flake = false;
|
||||
+ };
|
||||
};
|
||||
```
|
||||
|
||||
if your host machine isn't aarch64, you'll have to enable cross compiling.
|
||||
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
|
||||
TODO: enable cross compiling
|
||||
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 {
|
||||
+ system = "aarch64-linux";
|
||||
+ modules = [
|
||||
+ (import "${mobile-nixos}/lib/configuration.nix" {
|
||||
+ device = "pine64-pinephone";
|
||||
+ })
|
||||
+ ];
|
||||
+ }).config.mobile.outputs.u-boot.disk-image;
|
||||
```
|
||||
|
||||
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 {
|
||||
system = "x86_64-linux";
|
||||
modules = [
|
||||
./host.nix
|
||||
+ { ... }: {
|
||||
+ boot.binfmt.emulatedSystems = [ "aarch64-linux" ];
|
||||
+ }
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
if you added this emulation, rebuild your host machine to enable it (`nixos-rebuild --flake './#host' switch).
|
||||
|
||||
then build the image with:
|
||||
```sh
|
||||
nix build './#imgs.moby'
|
||||
nix build './#pinephone-img'
|
||||
```
|
||||
|
||||
the resulting image is effectively the same as what Hydra spits out in the automation: no users, and no way to login. if you're brand new to the Pinephone, i recommend flashing the image and booting as a sanity check. otherwise, skip to _Making the Image More Usable_ where we'll build a more usable image. at any time, consult the _Troubleshooting_ section if you hit something unexpected.
|
||||
|
@ -76,7 +135,7 @@ we don't want to re-flash the device _every_ time we change something. let's upd
|
|||
TODO: add toplevel nixosConfigurations.pinephone
|
||||
```
|
||||
|
||||
copy your flake over to the phone at `/etc/nixos/flake.nix` somehow. i use git for this. on the phone:
|
||||
copy your flake over to the phone at `/etc/nixos/flake.nix`. i use git for this. on the phone:
|
||||
```sh
|
||||
~$ git clone https://git.uninsane.org/colin/nix-files.git
|
||||
~$ sudo rmdir /etc/nixos && sudo mv nix-files /etc/nixos
|
||||
|
@ -85,7 +144,9 @@ copy your flake over to the phone at `/etc/nixos/flake.nix` somehow. i use git f
|
|||
/etc/nixos$ sudo nixos-rebuild --flake "./#pinephone" switch
|
||||
```
|
||||
|
||||
validate this with a reboot, and you should be golden! happy nixing :-)
|
||||
validate this with a reboot, and you should be golden! i recommend mirroring your `/etc/nixos` folder to at least one other place: a github repo, `rsync` to a desktop, `duplicity` to cloud storage, etc. that way if you ever brick your phone you can restore from your latest config using the `dd` approach. managing generations and rolling back to a good one doesn't seem quite as easy to do on a phone.
|
||||
|
||||
happy nixing :-)
|
||||
|
||||
|
||||
# Troubleshooting
|
||||
|
|
Loading…
Reference in New Issue