You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Robotnix enables a user to easily and reliably build Android (AOSP) images using the Nix package manager.
9
-
AOSP projects often contain long and complicated build instructions requiring a variety of tools for fetching source code and executing the build.
10
-
This applies not only to Android itself, but also to projects which are to be included in the Android build, such as the Linux kernel, Chromium webview, MicroG, other external/prebuilt privileged apps, etc.
11
-
Robotnix orchestrates the diverse build tools across these multiple projects using Nix, inheriting its reliability and reproducibility benefits, and consequently making the build and signing process very simple for an end-user.
8
+
Robotnix enables a user to easily and reliably build Android (AOSP) images using the Nix package manager / build tool.
9
+
10
+
## Quick Start
11
+
Here is a single command to build an `img` which can be flashed onto a Pixel 3 XL (`crosshatch`).
The command above will build an image signed with publicly known `test-keys`, so definitely don't use this for anything intended to be secure.
18
+
To flash the result to your device, run `fastboot update -w <img.zip>`.
19
+
20
+
## Motivation
21
+
Android projects often contain long and complicated build instructions requiring a variety of tools for fetching source code and executing the build.
22
+
This applies not only to Android itself, but also to projects included in the Android build, such as the Linux kernel, Chromium webview, MicroG, other external/prebuilt privileged apps, etc.
23
+
Robotnix orchestrates the diverse build systems across these multiple projects using Nix, inheriting its reliability and reproducibility benefits, and consequently making the build and signing process very simple for an end-user.
12
24
13
25
Robotnix includes a NixOS-style module system which allows users to easily customize various aspects of the their builds.
14
26
Some optional modules include:
@@ -20,175 +32,45 @@ Some optional modules include:
-[Seamless OTA updates](https://github.com/GrapheneOS/platform_packages_apps_Updater)
22
34
-[MicroG](https://microg.org/)
23
-
- Certain google apps (currently just stuff for Google Fi)
35
+
- Certain Google apps (currently just stuff for Google Fi)
24
36
- Easily setting various framework configuration settings such as those found [here](https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/values/config.xml)
25
37
- Custom built kernels
26
38
- Custom `/etc/hosts` file
27
39
- Extracting vendor blobs from Google's images using [android-prepare-vendor](https://github.com/anestisb/android-prepare-vendor)
28
40
29
-
Future goals include:
30
-
- Support for additional flavors and devices
31
-
- Better documentation, especially for module options
32
-
- Continuous integration / testing for various devices
33
-
- Automating CTS (Compatibility Test Suite) like nixos tests.
34
-
- Automatic verification of build reproducibility
35
-
- Replacing android prebuilt toolchains with nixpkgs equivalents.
36
-
37
-
This has currently only been tested on crosshatch (Pixel 3 XL, my daily driver), sunfish (Pixel 4a), and marlin (Pixel XL, which is now deprecated by google and no longer receiving updates).
41
+
## Documentation
38
42
39
-
## Quick Start
40
-
Here is a single command to build an `img` which can be flashed onto a Pixel 3 XL (`crosshatch`).
The command above will build an image signed with `test-keys`, so definitely don't use this for anything intended to be secure.
47
-
To flash the result to your device, run `fastboot update -w <img.zip>`.
43
+
More detailed robotnix documentation is available at [https://docs.robotnix.org](https://docs.robotnix.org), and should be consulted before use.
44
+
45
+
Robotnix was presented at Nixcon 2020, and a recording of the talk is available [here](https://youtu.be/7sQa04olUA0?t=22314).
46
+
Slides for the talk are also available [here](https://cfp.nixcon.org/media/robotnix-nixcon2020-final.pdf).
48
47
49
48
## Requirements
50
49
The AOSP project recommends at least 250GB free disk space as well as 16GB RAM. (Certain device kernels which use LTO+CFI may require even more memory)
51
-
A typical build requires approximately 45GB free disk space to check out the android source, 14GB for chromium, plus ~100GB of additional free space for intermediate build products.
52
-
Ensure your `/tmp` is not mounted using `tmpfs`, since the intermediate builds products are very large and will easily use all of your RAM (even if you have 32GB)!
53
-
A user can use the `--cores` option for `nix-build` to set the number of cores to
54
-
use, which can also be useful to decrease parallelism in case memory usage of
55
-
certain build steps is too large.
50
+
A typical build requires approximately 45GB free disk space to check out the android source, ~14GB for chromium, plus ~100GB of additional free space for intermediate build products.
51
+
By default, Nix uses `/tmp` to store these intermediate build products, so ensure your `/tmp` is not mounted using `tmpfs`, since the intermediate builds products are very large and will easily use all of your RAM (even if you have 32GB)!
52
+
A user can use the `--cores` option for `nix-build` to set the number of cores to use, which can also be useful to decrease parallelism in case memory usage of certain build steps is too large.
56
53
57
-
A full Android 10 build with chromium webview takes approximately 10 hours on my quad-core i7-3770 with 16GB of memory.
54
+
Robotnix also requires support for user namespaces (`CONFIG_USER_NS` Linux kernel option).
55
+
Currently, using the "signing inside Nix with a sandbox exception" feature also requires a Nix daemon with the sandbox support enabled.
56
+
This feature is currently not supported inside Docker for this reason.
57
+
58
+
A full Android 10 build with Chromium webview takes approximately 10 hours on my quad-core i7-3770 with 16GB of memory.
58
59
AOSP takes approximately 4 hours of that, while webview takes approximately 6 hours.
59
60
I have recently upgraded to a 3970x Threadripper with 32-cores.
60
61
This can build chromium+android in about an hour.
61
62
62
-
## Configuration and Build Options
63
-
A configuration file should be created for anything more complicated, including creating signed builds.
64
-
See my own configuration under `example.nix` for inspiration.
65
-
After creating a configuration file, generate keys for your device:
66
-
67
-
```console
68
-
$ nix-build ./default.nix --arg configuration ./crosshatch.nix -A generateKeysScript -o generate-keys
69
-
$ ./generate-keys ./keys
70
-
```
71
-
72
-
This will create a `keys` directory containing the app and device keys needed for the build.
73
-
Next, build and sign your release.
74
-
There are two ways to do this.
75
-
The first option involves creating a "release script" which does the final build steps of signing target files and creating ota/img files outside of nix:
76
-
```console
77
-
$ nix-build ./default.nix --arg configuration ./crosshatch.nix -A releaseScript -o release
78
-
$ ./release ./keys
79
-
```
80
-
One advantage of using a release script as above is that the build can take place on a different machine than the signing.
81
-
`nix-copy-closure` could be used to transfer this script and its dependencies to another computer to finish the release.
82
-
83
-
The other option is to build the final products entirely inside nix instead of using `releaseScript`
This, however, will require a nix sandbox exception so the secret keys are available to the build scripts.
88
-
To use `extra-sandbox-paths`, the user must be a `trusted-user` in `nix.conf`.
89
-
Additionally, the nix builder will also need read access to these keys.
90
-
This can be set using `chgrp -R nixbld ./keys` and `chmod -R g+r ./keys`.
91
-
92
-
### Installation
93
-
See `docs/installation.md` for details on flashing and updating for Pixel devices.
94
-
95
-
### Binary Cache
96
-
Robotnix now has an optional binary cache provided by cachix.
97
-
Currently, only the device kernels and browser builds are published through the binary cache.
98
-
This is because these derivation outputs are most likely to be shared between
99
-
users, and those outputs also can take a very long time to build.
100
-
The build products previously discussed should be uploaded for at least every robotnix release tag.
101
-
To use, install `cachix`, run `cachix use robotnix`, and then build robotnix like normal.
102
-
103
-
### OTA Updater
104
-
The Over-the-Air (OTA) updater can be enabled using `apps.updater.enable = true;`.
105
-
The URL that the updater will query for updates is set using `apps.updater.url = "...";`.
106
-
This URL needs to point to a directory containing the OTA update file, as well as some metadata.
107
-
Conveniently, these files are generated as part of the `releaseScript` output.
108
-
If instead, you are signing builds inside nix with the sandbox exception, the desired output can be built using `nix-build ... -A otaDir`.
109
-
110
-
### Testing / CI / Reproducibility
111
-
112
-
All devices (Pixel 1-4(a) (XL)) have very basic checks to ensure that the android build process will at least start properly.
113
-
See `release.nix` for the set of configurations with this minimal build testing.
114
-
This check is run using `nix-build ./release.nix -A check`.
115
-
As each build takes approximately 4 hours--I only build marlin and crosshatch builds for myself.
116
-
At some point, I would love to set up a build farm and publish build products on s3 or [cachix](https://cachix.org).
117
-
This would allow an end-user to simply sign releases using their own keys without building the entire AOSP themselves.
118
-
119
-
As of 2020-05-17, `target_files`, `signed_target_files`, `img`, and `ota` files have all been verified to be bit-for-bit reproducible for `crosshatch` and `marlin` using the `vanilla` flavor.
120
-
Automated periodic testing of this is still desired.
121
-
122
-
One option being investigated is to have multiple independent remote builders produce unsigned target files for a number of device and flavor combinations.
123
-
An end-user could then verify that the builders produced the same unsigned target files, and finish the process by signing the target files and producing their own `img` and `ota` files.
124
-
This eliminates the requirement for an end-user to spend hours building android.
125
-
126
-
There are, however, a few places where user-specific public keys are included in the build for key pinning.
127
-
This unfortunately decreases the possibility of sharing build products between users.
128
-
The F-Droid privileged extension and Trichrome (disabled for now) are two components which have this issue.
129
-
Fixes for this are still under investigation.
130
-
131
-
### LineageOS Support
132
-
LineageOS support may be enabled by setting `flavor = "lineageos";`.
133
-
The typical LineageOS flashing process involves first producing a `boot.img` and `ota`, flashing `boot.img` with fastboot, and then flashing the `ota` in recovery mode.
134
-
The `boot.img` and `ota` targets can be built using `nix-build ... -A bootImg` or `nix-build ... -A ota`, respectively.
135
-
136
-
LineageOS support should be considered "experimental," as it does yet have the same level of support I intend to provide for `vanilla` and `grapheneos` flavors.
137
-
LineageOS source metadata may be updated irregularly in robotnix, and certain modules (such as the updater) are not guaranteed to work.
138
-
Moreover, LineageOS does not appear to provide the same level of security as even the vanilla flavor, with dm-verity/AVB often disabled, `userdebug` as the default variant, and vendor files with unclear origin.
139
-
LineageOS support is still valuable to include as it extends preliminary support to a much wider variety of devices, and provides the base that many other Android ROMs use to customize.
140
-
Contributions and fixes from LineageOS users are especially welcome!
141
-
142
-
### Emulator
143
-
144
-
To build and run an emulator with an attached vanilla system image, use (for example):
145
-
```console
146
-
$ nix-build ./default.nix --arg configuration '{device="x86_64"; flavor="vanilla";}' -A emulator
147
-
$ ./result
148
-
```
149
-
This currently only works well when using the generic `x86_64` device.
150
-
151
-
### Fetching android source files
152
-
153
-
Robotnix supports two alternative approaches for fetching source files:
154
-
155
-
- Build-time source fetching with `pkgs.fetchgit`. This is the default.
156
-
An end user wanting to fetch sources not already included in `robotnix` would
157
-
need to create a repo json file using `mk-repo-file.py` and set
158
-
`source.dirs = lib.importJSON ./example.json;`
159
-
- Evaluation-time source fetching with `builtins.fetchGit`.
160
-
This is more convenient for development when changing branches, as it allows use of a shared git cache.
161
-
The end user will need to set `source.manifest.{url,rev,sha256}` and enable `source.evalTimeFetching`.
162
-
However, with `builtins.fetchGit`, the `drv`s themselves depend on the source,
163
-
and `nix-copy-closure` of even just the `.drv` files would require downloading the source as well.
Set `ccache.enable = true` in configuration, and be sure to pass `/var/cache/ccache` as a sandbox exception when building.
176
-
177
-
## Notable mentions
178
-
See also: [NixDroid](https://github.com/ajs124/NixDroid), [RattlesnakeOS](https://github.com/dan-v/rattlesnakeos-stack), [aosp-build](https://github.com/hashbang/aosp-build), and [CalyxOS](https://calyxos.org/)
179
-
180
-
## Donating to Robotnix
63
+
## Community
64
+
The `#robotnix` IRC channel on Freenode is available for a place to chat about the project, ask questions, and discuss robotnix development.
181
65
182
-
If you find Robotnix helpful, please consider donating to the project.
183
-
Especially consider making a donation if you rely on regular Robotnix updates for your personal device.
66
+
## Donating to robotnix
67
+
If you find robotnix helpful, please consider donating to the project.
68
+
Especially consider making a donation if you rely on regular robotnix updates for your personal device.
184
69
Donations will be used to support ongoing Android updates, developer hardware and build infrastructure, as well as future improvements.
185
70
Your support is greatly appreciated.
186
71
- My GitHub sponsors page is [here](https://github.com/sponsors/danielfullmer).
187
72
- Paypal donations may be made using this [link](https://www.paypal.com/donate/?cmd=_donations&business=FAV4QV9CTLXF2¤cy_code=USD).
188
73
- Bitcoin donations may be directed toward `3GEtqfkPkSSrRFpdcfy4T6YALgTwRyufip`.
189
74
190
-
## Community
191
-
The `#robotnix` IRC channel on Freenode is available for a place to chat about the project, ask questions, and discuss robotnix development.
192
-
193
-
## License information
75
+
## License information
194
76
This project is available as open source under the terms of MIT license. However, for accurate information, please check individual files.
0 commit comments