work-in-progress-but-it-works
Related to #57 and more precisely to #393, in whcih @jeandudey provides a very good explanation for the motivation to package xous with Guix. Quoting him directly here:
The main advantage of GNU Guix is that everything is built from source, even the C, and Rust compilers, from a small binary seed and a working Linux system. Packages are defined using DSL made with Guile Scheme.
Also, packages are built in an isolated environment that can't be tampered with, without network access, or access to any other part of the filesystem, so build script can run without modifications. The build stage is separate from the download stage, and the download must match the hash of the file in the source declaration. -- @jeandudey
Tested on dabao development board for:
-
bao1x-alt-boot1andbao1x-boot1 -
dabao-helloworld
TODO:
- See if there can be a better way to get latest stable Rust rather than using rustup (we want a bootstrapped rust ideally) (being actively worked on ... latest efforts at https://codeberg.org/guix/guix/pulls/6101)
- Address the sources of non-determinism (review inline patches and see if we can address them upstream)
- Pin channels to commit hashes
- Use
guix time-machinein CI for better sandboxing and reproducibility - Fix semver's rev tag part as it is just zeros right now (e.g.:
Semver is: v0.9.16-2692-g00000000) - Review and cleanup the code (
bao.scmandbao-crates.scm) - Review how cargo vendoring is done and see whether the process can be improved
- Figure out ways to speed up CI (takes 1+ hour)
- use
guix build --checkand/orguix build --rounds=2to verify that builds are deterministic (bit-for-bit) - fix the non-deterministic build troubleshooting ci step as it does not work when previous step (
guix build --rounds=2) fails - For production releases move the guix build toolchain to a separate repository, which will fetch xous-core source code from github. The current approach using
local-fileyields non deterministic builds as it can pick un-tracked files, which will differ from one machine to another.
Guix Quickstart to build Baochip Firmware
Prerequisites
Install Guix and configure channels in ~/.config/guix/channels.scm:
(cons*
(channel
(name 'rustup)
(url "https://github.com/sbellem/guix-rustup")
(branch "dev")
(introduction
(make-channel-introduction
"d9bcf7f979506b880a5ba25674a606a824d9c890"
(openpgp-fingerprint
"E39D 2B3D 0564 BA43 7BD9 2756 C38A E0EC CAB7 D5C8"))))
(channel
(name 'rust-xous)
(url "https://github.com/sbellem/rust-xous-guix")
(branch "main"))
%default-channels)Then run guix pull to fetch the channels.
Development Shell
Enter dev shell:
guix shell --pure --development --file=guix.scmBuild:
cargo xtask dabao --no-verifyBuilding Packages
From the xous-core directory:
# Build a specific target
guix build bao1x-boot0
# Build with output symlink
guix build bao1x-boot1 --root=target/guixAvailable Targets
bao1x-boot0, bao1x-boot1, bao1x-alt-boot1, bao1x-baremetal-dabao, dabao-helloworld, baosec
Notes on deterministic builds
-
--checkis documented under Additional Build Options: https://guix.gnu.org/manual/en/html_node/Additional-Build-Options.html -
--roundsis documented under Common Build Options: https://guix.gnu.org/manual/en/html_node/Common-Build-Options.html
The Submitting Patches page also has practical guidance on using --rounds=2 as part of the contribution workflow: https://guix.gnu.org/manual/en/html_node/Submitting-Patches.html
Activity
11Post-installation steps
Add the following to ~/.config/guix/channels.scm:
(cons*
(channel
(name 'rustup)
(url "https://github.com/sbellem/guix-rustup")
(branch "dev")
(introduction
(make-channel-introduction
"d9bcf7f979506b880a5ba25674a606a824d9c890"
(openpgp-fingerprint
"E39D 2B3D 0564 BA43 7BD9 2756 C38A E0EC CAB7 D5C8"))))
(channel
(name 'rust-xous)
(url "https://github.com/sbellem/rust-xous-guix")
(branch "main")
(introduction
(make-channel-introduction
"bcdb7bb2b220288545114b140f5079ba4f98a157"
(openpgp-fingerprint
"E39D 2B3D 0564 BA43 7BD9 2756 C38A E0EC CAB7 D5C8"))))
%default-channels)Edit .bashrc, or some other bash profile file
export GUIX_LOCPATH=$HOME/.guix-profile/lib/locale
GUIX_PROFILE="$HOME/.guix-profile"
. "$GUIX_PROFILE/etc/profile"
GUIX_PROFILE="$HOME/.config/guix/current"
. "$GUIX_PROFILE/etc/profile"
# optional, for ncsd
export SSL_CERT_DIR="$HOME/.guix-profile/etc/ssl/certs"
export SSL_CERT_FILE="$HOME/.guix-profile/etc/ssl/certs/ca-certificates.crt"Looks like I'm able to run guix on my local machine to build a version of boot0. Is there a way I can see what version of Rust the build is using to build it?
Looks like I'm able to run guix on my local machine to build a version of boot0. Is there a way I can see what version of Rust the build is using to build it?
You can run:
guix graph -t bag bao1x-boot0 | grep -i rustThis pull request is a draft
Merging is unavailable until it is marked ready for review.
Guix installation on Ubuntu 22.04
@bunnie I used the following script to install
guixon a fresh Ubuntu 22.04 instance. You may just use it as a reference and perform the installation steps manually. Also, notice the app armor related sections which may not apply to your system.