Skip to content

Commit 3e80ec3

Browse files
committed
contrib: Add deterministic Guix builds.
1 parent 735d6b5 commit 3e80ec3

File tree

5 files changed

+604
-1
lines changed

5 files changed

+604
-1
lines changed

contrib/guix/README.md

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
# Bootstrappable Bitcoin Core Builds
2+
3+
This directory contains the files necessary to perform bootstrappable Bitcoin
4+
Core builds.
5+
6+
[Bootstrappability][b17e] furthers our binary security guarantees by allowing us
7+
to _audit and reproduce_ our toolchain instead of blindly _trusting_ binary
8+
downloads.
9+
10+
We achieve bootstrappability by using Guix as a functional package manager.
11+
12+
## Requirements
13+
14+
Conservatively, a x86_64 machine with:
15+
16+
- 2 or more logical cores
17+
- 4GB of free disk space on the partition that /gnu/store will reside in
18+
- 24GB of free disk space on the partition that the bitcoin repository resides in
19+
20+
> Note: these requirements are slightly less onerous than those of Gitian builds
21+
22+
## Setup
23+
24+
**If you're just testing this out, you can use the
25+
[Dockerfile][fanquake/guix-docker] for convenience. It automatically speeds up
26+
your builds by [using substitutes](#speeding-up-builds-with-substitute-servers).
27+
Should you choose to use the Dockerfile, you can skip this section.**
28+
29+
Otherwise, follow the [Guix installation guide][guix/bin-install].
30+
31+
> Note: For those who like to keep their filesystems clean, Guix is designed to
32+
> be very standalone and _will not_ conflict with your system's package
33+
> manager/existing setup. It _only_ touches `/var/guix`, `/gnu`, and
34+
> `~/.config/guix`.
35+
36+
After installation, you may want to consider [adding substitute
37+
servers](#speeding-up-builds-with-substitute-servers) to speed up your build if
38+
that fits your security model. (skippable if you're using the
39+
[Dockerfile][fanquake/guix-docker])
40+
41+
Once Guix is installed, deploy our patched version into your current Guix
42+
profile. The changes there are slowly being upstreamed.
43+
44+
```sh
45+
guix pull --url=https://github.com/dongcarl/guix.git \
46+
--branch=2019-05-bitcoin-staging \
47+
--max-jobs=4 # change accordingly
48+
```
49+
50+
Make sure that you are using your current profile. (You are prompted to do this
51+
at the end of the `guix pull`)
52+
53+
```bash
54+
export PATH="${HOME}/.config/guix/current/bin${PATH:+:}$PATH"
55+
```
56+
57+
> Note: There is ongoing work to eliminate this `guix pull` step using Guix
58+
> [inferiors][guix/inferiors] and [channels][guix/channels].
59+
60+
## Usage
61+
62+
### As a Development Environment
63+
64+
For a Bitcoin Core depends development environment, simply invoke
65+
66+
```sh
67+
guix environment --manifest=contrib/guix/manifest.scm
68+
```
69+
70+
And you'll land back in your shell with all the build dependencies required for
71+
a `depends` build injected into your environment.
72+
73+
### As a Tool for Deterministic Builds
74+
75+
From the top of a clean Bitcoin Core repository:
76+
77+
```sh
78+
./contrib/guix/guix-build.sh
79+
```
80+
81+
After the build finishes successfully (check the status code please), compare
82+
hashes:
83+
84+
```sh
85+
find output/ -type f -print0 | sort -z | xargs -r0 sha256sum
86+
```
87+
88+
#### Recognized environment variables
89+
90+
* _**HOSTS**_
91+
92+
Override the space-separated list of platform triples for which to perform a
93+
bootstrappable build. _(defaults to "i686-linux-gnu x86\_64-linux-gnu
94+
arm-linux-gnueabihf aarch64-linux-gnu riscv64-linux-gnu")_
95+
96+
> Windows and OS X platform triplet support are WIP.
97+
98+
* _**SOURCES_PATH**_
99+
100+
Set the depends tree download cache for sources. This is passed through to the
101+
depends tree. Setting this to the same directory across multiple builds of the
102+
depends tree can eliminate unnecessary redownloading of package sources.
103+
104+
* _**MAX_JOBS**_
105+
106+
Override the maximum number of jobs to run simultaneously, you might want to
107+
do so on a memory-limited machine. This may be passed to `make` as in `make
108+
--jobs="$MAX_JOBS"` or `xargs` as in `xargs -P"$MAX_JOBS"`. _(defaults to the
109+
value of `nproc` outside the container)_
110+
111+
* _**SOURCE_DATE_EPOCH**_
112+
113+
Override the reference timestamp used for bit-for-bit reproducibility, the
114+
variable name conforms to [standard][r12e/source-date-epoch]. _(defaults to
115+
the output of `$(git log --format=%at -1)`)_
116+
117+
* _**V**_
118+
119+
If non-empty, will pass `V=1` to all `make` invocations, making `make` output
120+
verbose.
121+
122+
* _**ADDITIONAL_GUIX_ENVIRONMENT_FLAGS**_
123+
124+
Additional flags to be passed to `guix environment`. For a fully-bootstrapped
125+
build, set this to `--bootstrap --no-substitutes`. Note that a
126+
fully-bootstrapped build will take quite a long time on the first run.
127+
128+
## Tips and Tricks
129+
130+
### Speeding up builds with substitute servers
131+
132+
_This whole section is automatically done in the convenience
133+
[Dockerfiles][fanquake/guix-docker]_
134+
135+
For those who are used to life in the fast _(and trustful)_ lane, you can use
136+
[substitute servers][guix/substitutes] to enable binary downloads of packages.
137+
138+
> For those who only want to use substitutes from the official Guix build farm
139+
> and have authorized the build farm's signing key during Guix's installation,
140+
> you don't need to do anything.
141+
142+
#### Authorize the signing keys
143+
144+
For the official Guix build farm at https://ci.guix.gnu.org, run as root:
145+
146+
```
147+
guix archive --authorize < ~root/.config/guix/current/share/guix/ci.guix.gnu.org.pub
148+
```
149+
150+
For dongcarl's substitute server at https://guix.carldong.io, run as root:
151+
152+
```sh
153+
wget -qO- 'https://guix.carldong.io/signing-key.pub' | guix archive --authorize
154+
```
155+
156+
#### Use the substitute servers
157+
158+
The official Guix build farm at https://ci.guix.gnu.org is automatically used
159+
unless the `--no-substitutes` flag is supplied.
160+
161+
This can be overridden for all `guix` invocations by passing the
162+
`--substitute-urls` option to your invocation of `guix-daemon`. This can also be
163+
overridden on a call-by-call basis by passing the same `--substitute-urls`
164+
option to client tools such at `guix environment`.
165+
166+
To use dongcarl's substitute server for Bitcoin Core builds after having
167+
[authorized his signing key](#authorize-the-signing-keys):
168+
169+
```
170+
export ADDITIONAL_GUIX_ENVIRONMENT_FLAGS='--substitute-urls="https://guix.carldong.io https://ci.guix.gnu.org"'
171+
```
172+
173+
## FAQ
174+
175+
### How can I trust the binary installation?
176+
177+
As mentioned at the bottom of [this manual page][guix/bin-install]:
178+
179+
> The binary installation tarballs can be (re)produced and verified simply by
180+
> running the following command in the Guix source tree:
181+
>
182+
> make guix-binary.x86_64-linux.tar.xz
183+
184+
### When will Guix be packaged in debian?
185+
186+
Vagrant Cascadian has been making good progress on this
187+
[here][debian/guix-package]. We have all the pieces needed to put up an APT
188+
repository and will likely put one up soon.
189+
190+
[b17e]: http://bootstrappable.org/
191+
[r12e/source-date-epoch]: https://reproducible-builds.org/docs/source-date-epoch/
192+
193+
[guix/install.sh]: https://git.savannah.gnu.org/cgit/guix.git/plain/etc/guix-install.sh
194+
[guix/bin-install]: https://www.gnu.org/software/guix/manual/en/html_node/Binary-Installation.html
195+
[guix/env-setup]: https://www.gnu.org/software/guix/manual/en/html_node/Build-Environment-Setup.html
196+
[guix/substitutes]: https://www.gnu.org/software/guix/manual/en/html_node/Substitutes.html
197+
[guix/substitute-server-auth]: https://www.gnu.org/software/guix/manual/en/html_node/Substitute-Server-Authorization.html
198+
[guix/inferiors]: https://www.gnu.org/software/guix/manual/en/html_node/Inferiors.html
199+
[guix/channels]: https://www.gnu.org/software/guix/manual/en/html_node/Channels.html
200+
201+
[debian/guix-package]: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=850644
202+
[fanquake/guix-docker]: https://github.com/fanquake/core-review/tree/master/guix

contrib/guix/guix-build.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
export LC_ALL=C
3+
set -e -o pipefail
4+
5+
# Determine the maximum number of jobs to run simultaneously (overridable by
6+
# environment)
7+
MAX_JOBS="${MAX_JOBS:-$(nproc)}"
8+
9+
# Download the depends sources now as we won't have internet access in the build
10+
# container
11+
make -C "${PWD}/depends" -j"$MAX_JOBS" download ${V:+V=1} ${SOURCES_PATH:+SOURCES_PATH="$SOURCES_PATH"}
12+
13+
# Determine the reference time used for determinism (overridable by environment)
14+
SOURCE_DATE_EPOCH="${SOURCE_DATE_EPOCH:-$(git log --format=%at -1)}"
15+
16+
# Deterministically build Bitcoin Core for HOSTs (overriable by environment)
17+
for host in ${HOSTS=i686-linux-gnu x86_64-linux-gnu arm-linux-gnueabihf aarch64-linux-gnu riscv64-linux-gnu}; do
18+
19+
# Display proper warning when the user interrupts the build
20+
trap 'echo "** INT received while building ${host}, you may want to clean up the relevant output and distsrc-* directories before rebuilding"' INT
21+
22+
# Run the build script 'contrib/guix/build.sh' in the build container
23+
# specified by 'contrib/guix/manifest.scm'
24+
# shellcheck disable=SC2086
25+
guix environment --manifest="${PWD}/contrib/guix/manifest.scm" \
26+
--container \
27+
--pure \
28+
--no-cwd \
29+
--share="$PWD"=/bitcoin \
30+
${SOURCES_PATH:+--share="$SOURCES_PATH"} \
31+
${ADDITIONAL_GUIX_ENVIRONMENT_FLAGS} \
32+
-- env HOST="$host" \
33+
MAX_JOBS="$MAX_JOBS" \
34+
SOURCE_DATE_EPOCH="${SOURCE_DATE_EPOCH:?unable to determine value}" \
35+
${V:+V=1} \
36+
${SOURCES_PATH:+SOURCES_PATH="$SOURCES_PATH"} \
37+
bash -c "cd /bitcoin && bash contrib/guix/libexec/build.sh"
38+
39+
done

0 commit comments

Comments
 (0)