bitcoin/contrib/guix
fanquake 0fe225e378
Merge bitcoin/bitcoin#26470: guix: Clean up libexec/build.sh
d3e5779f11 guix: Drop non-existent directories (Hennadii Stepanov)
43c4afc407 guix: Drop no longer used `prepend_to_search_env_var()` (Hennadii Stepanov)

Pull request description:

  1. The `prepend_to_search_env_var()` function was introduced in c1ae726a13, and it has no longer been used since 1dd8cbfbc6.

  2. The `${NATIVE_GCC}/lib64` and `${NATIVE_GCC_STATIC}/lib64` do not exist at all.

  Guix builds:
  ```
  0a1ed84ba127853fdeb14e6104e97d853116bf3ac9fa4cdd4b72c428ca738f7a  guix-build-d3e5779f110a/output/aarch64-linux-gnu/SHA256SUMS.part
  c69fddab6384ece4061606109acce2f4f991129b5ad2005e9977bc74ad88f60c  guix-build-d3e5779f110a/output/aarch64-linux-gnu/bitcoin-d3e5779f110a-aarch64-linux-gnu-debug.tar.gz
  b8a0968e7057ed6b1703cc5b5213178b06c51c7649c2639d32523f049b082a69  guix-build-d3e5779f110a/output/aarch64-linux-gnu/bitcoin-d3e5779f110a-aarch64-linux-gnu.tar.gz
  9624c5f331d6e2e4f6bb63a3573ff8f688e2662bf8a1959068511ee76fea1b31  guix-build-d3e5779f110a/output/arm-linux-gnueabihf/SHA256SUMS.part
  4b2fecfac94aa55489a9e7316944a1c0216750bfc8658e8dbe2266ad6abed7cd  guix-build-d3e5779f110a/output/arm-linux-gnueabihf/bitcoin-d3e5779f110a-arm-linux-gnueabihf-debug.tar.gz
  db413d3ed5e4917a236dea10d121953c01812d7f3202bf503fb3a7bb40e9655e  guix-build-d3e5779f110a/output/arm-linux-gnueabihf/bitcoin-d3e5779f110a-arm-linux-gnueabihf.tar.gz
  f4952abe163f536c085a3ad9249840f940f5a2670b77042e2c355886301174a0  guix-build-d3e5779f110a/output/arm64-apple-darwin/SHA256SUMS.part
  3f9b76ed00e90547e980062114de435c10b0253a3fa3bca867758c413f68d465  guix-build-d3e5779f110a/output/arm64-apple-darwin/bitcoin-d3e5779f110a-arm64-apple-darwin-unsigned.dmg
  ec30943bf796c7c55f9d5fb186054070483b888c87d1c79a02ba2828c85d9643  guix-build-d3e5779f110a/output/arm64-apple-darwin/bitcoin-d3e5779f110a-arm64-apple-darwin-unsigned.tar.gz
  31fccaf6ff6f70ef3fe09c592f2630f5b2bc39f5c8eadf4f7660e379389442be  guix-build-d3e5779f110a/output/arm64-apple-darwin/bitcoin-d3e5779f110a-arm64-apple-darwin.tar.gz
  6df55d847ad0f3c4cdd35c3fc9603ab58e44bf76a4a942c4f2f268fa02e710e1  guix-build-d3e5779f110a/output/dist-archive/bitcoin-d3e5779f110a.tar.gz
  1e264b6cd129e1353c271049fd3c8338a1d2183aea847cb4ea9d4095fba56a54  guix-build-d3e5779f110a/output/powerpc64-linux-gnu/SHA256SUMS.part
  03d325d8bffa72e79638ae0e5cd7d6c761cdc5e9d664158c83a5f9ff9f393634  guix-build-d3e5779f110a/output/powerpc64-linux-gnu/bitcoin-d3e5779f110a-powerpc64-linux-gnu-debug.tar.gz
  8d459c2fca6e6712cde54ce030cddae9c3fa0607dd9fb4a951f8d62f3e456162  guix-build-d3e5779f110a/output/powerpc64-linux-gnu/bitcoin-d3e5779f110a-powerpc64-linux-gnu.tar.gz
  0ef58af43e18dc7490ea8f01d392e6645b7f978817a8fb0727d90559680a0105  guix-build-d3e5779f110a/output/powerpc64le-linux-gnu/SHA256SUMS.part
  fe4be346506e5f9cc3c5f8a952f4d4b2ac13a2562854d26deee536f411847189  guix-build-d3e5779f110a/output/powerpc64le-linux-gnu/bitcoin-d3e5779f110a-powerpc64le-linux-gnu-debug.tar.gz
  52c0961bfca3985899f872145c566b5220245096a3edc94347800e1de199a17e  guix-build-d3e5779f110a/output/powerpc64le-linux-gnu/bitcoin-d3e5779f110a-powerpc64le-linux-gnu.tar.gz
  ade3eb3f496a5904d12cb09095e7f05c69961d759aba1acc82e01bcfcc2c6ef1  guix-build-d3e5779f110a/output/riscv64-linux-gnu/SHA256SUMS.part
  05a9d0921b5706e210fb0b5a1a70890604ee22a7bbdc25f011cd1bbff1420120  guix-build-d3e5779f110a/output/riscv64-linux-gnu/bitcoin-d3e5779f110a-riscv64-linux-gnu-debug.tar.gz
  fb897b1b527450da6a033802c218722d69176c2572c321ad3e18b2ef3bf398ed  guix-build-d3e5779f110a/output/riscv64-linux-gnu/bitcoin-d3e5779f110a-riscv64-linux-gnu.tar.gz
  a76da4a5d3fd3ed98adbe1e4f1b1c974937e401801d65b55a14e21339b072f9d  guix-build-d3e5779f110a/output/x86_64-apple-darwin/SHA256SUMS.part
  3eb30a851466d4dcf08fbf1d94071d8d6a253fee52540ab109ae9cf629cb36d2  guix-build-d3e5779f110a/output/x86_64-apple-darwin/bitcoin-d3e5779f110a-x86_64-apple-darwin-unsigned.dmg
  6a350a4ea7afbdfba07d1d51039d9c3da5f5ff0a3d4e40095006d0cb571a5c65  guix-build-d3e5779f110a/output/x86_64-apple-darwin/bitcoin-d3e5779f110a-x86_64-apple-darwin-unsigned.tar.gz
  32761153c68431c3bf1eb6638caa00bd4d7daf7372cdea2a9cc711c4c1f68326  guix-build-d3e5779f110a/output/x86_64-apple-darwin/bitcoin-d3e5779f110a-x86_64-apple-darwin.tar.gz
  79fa0b6b25a74c4681679a04ceb9fab1ae0e339ed9e44a30e3c84ee019255e85  guix-build-d3e5779f110a/output/x86_64-linux-gnu/SHA256SUMS.part
  dd496a120f99a818fe453f23f607dd064c855e6d5d199870ce3ab924aca6fed0  guix-build-d3e5779f110a/output/x86_64-linux-gnu/bitcoin-d3e5779f110a-x86_64-linux-gnu-debug.tar.gz
  6dc03d9ad75126ad67c29afbf3ef12e99a97f0792cd8fac6407a2f4ca911f9d1  guix-build-d3e5779f110a/output/x86_64-linux-gnu/bitcoin-d3e5779f110a-x86_64-linux-gnu.tar.gz
  32fb6e76ed757d9d4693c3ef2cea7bd7b9151cadbf9976ed64ab1e3a7ee71e9e  guix-build-d3e5779f110a/output/x86_64-w64-mingw32/SHA256SUMS.part
  93bbc60e546571e14268e25efcf83375c5ec4ed13c546cbf5b76d849a0f50f35  guix-build-d3e5779f110a/output/x86_64-w64-mingw32/bitcoin-d3e5779f110a-win64-debug.zip
  b85932e7cde8616c2d7342735ad8c6247d556fa86ccee8d0ecd326debeb93d8c  guix-build-d3e5779f110a/output/x86_64-w64-mingw32/bitcoin-d3e5779f110a-win64-setup-unsigned.exe
  f77431e1d5b7a356c065dd81383222116cf8254bda0666a169b25415cfba1810  guix-build-d3e5779f110a/output/x86_64-w64-mingw32/bitcoin-d3e5779f110a-win64-unsigned.tar.gz
  8d1a43386648ef5d97aae806f0e38f7fa3ec5f39b30b495fdcf6be6590a392eb  guix-build-d3e5779f110a/output/x86_64-w64-mingw32/bitcoin-d3e5779f110a-win64.zip
  ```

ACKs for top commit:
  fanquake:
    ACK d3e5779f11

Tree-SHA512: bd32442c81146a5558a4f5bc79e1eb841e7c920551289a2c910f8a697c0a70ea26926e9ca7cdb486176b772ee42544559939417a2bdf3ab6cc4b65dba816a087
2022-11-25 17:17:28 +00:00
..
libexec guix: Drop non-existent directories 2022-11-08 13:13:45 +00:00
patches guix: consistently use -ffile-prefix-map 2022-09-06 09:51:55 +01:00
guix-attest guix: make it possible to override gpg binary 2022-03-15 14:35:09 +01:00
guix-build guix: Improve error message about missed macOS SDK 2022-04-24 11:51:38 +02:00
guix-clean test: Bump shellcheck version to 0.8.0 2021-11-30 21:15:40 +02:00
guix-codesign build: Fix "ERR: Unsigned tarballs do not exist" 2022-04-01 10:28:10 +02:00
guix-verify guix-verify: Non-zero exit code when anything fails 2021-08-05 19:05:16 -04:00
INSTALL.md doc: move Guix uninstall instructions to INSTALL.md 2022-11-03 14:20:44 +01:00
manifest.scm Merge bitcoin/bitcoin#26057: build, guix: Get rid of perl dependency 2022-09-16 10:47:35 +01:00
README.md doc: move Guix uninstall instructions to INSTALL.md 2022-11-03 14:20:44 +01:00

Bootstrappable Bitcoin Core Builds

This directory contains the files necessary to perform bootstrappable Bitcoin Core builds.

Bootstrappability furthers our binary security guarantees by allowing us to audit and reproduce our toolchain instead of blindly trusting binary downloads.

We achieve bootstrappability by using Guix as a functional package manager.

Requirements

Conservatively, you will need an x86_64 machine with:

  • 16GB of free disk space on the partition that /gnu/store will reside in
  • 8GB of free disk space per platform triple you're planning on building (see the HOSTS environment variable description)

Installation and Setup

If you don't have Guix installed and set up, please follow the instructions in INSTALL.md

Usage

If you haven't considered your security model yet, please read the relevant section before proceeding to perform a build.

Making the Xcode SDK available for macOS cross-compilation

In order to perform a build for macOS (which is included in the default set of platform triples to build), you'll need to extract the macOS SDK tarball using tools found in the macdeploy directory.

You can then either point to the SDK using the SDK_PATH environment variable:

# Extract the SDK tarball to /path/to/parent/dir/of/extracted/SDK/Xcode-<foo>-<bar>-extracted-SDK-with-libcxx-headers
tar -C /path/to/parent/dir/of/extracted/SDK -xaf /path/to/Xcode-<foo>-<bar>-extracted-SDK-with-libcxx-headers.tar.gz

# Indicate where to locate the SDK tarball
export SDK_PATH=/path/to/parent/dir/of/extracted/SDK

or extract it into depends/SDKs:

mkdir -p depends/SDKs
tar -C depends/SDKs -xaf /path/to/SDK/tarball

Building

The author highly recommends at least reading over the common usage patterns and examples section below before starting a build. For a full list of customization options, see the recognized environment variables section.

To build Bitcoin Core reproducibly with all default options, invoke the following from the top of a clean repository:

./contrib/guix/guix-build

Codesigning build outputs

The guix-codesign command attaches codesignatures (produced by codesigners) to existing non-codesigned outputs. Please see the release process documentation for more context.

It respects many of the same environment variable flags as guix-build, with 2 crucial differences:

  1. Since only Windows and macOS build outputs require codesigning, the HOSTS environment variable will have a sane default value of x86_64-w64-mingw32 x86_64-apple-darwin arm64-apple-darwin instead of all the platforms.
  2. The guix-codesign command requires a DETACHED_SIGS_REPO flag.
    • DETACHED_SIGS_REPO

      Set the directory where detached codesignatures can be found for the current Bitcoin Core version being built.

      REQUIRED environment variable

An invocation with all default options would look like:

env DETACHED_SIGS_REPO=<path/to/bitcoin-detached-sigs> ./contrib/guix/guix-codesign

Cleaning intermediate work directories

By default, guix-build leaves all intermediate files or "work directories" (e.g. depends/work, guix-build-*/distsrc-*) intact at the end of a build so that they are available to the user (to aid in debugging, etc.). However, these directories usually take up a large amount of disk space. Therefore, a guix-clean convenience script is provided which cleans the current git worktree to save disk space:

./contrib/guix/guix-clean

Attesting to build outputs

Much like how Gitian build outputs are attested to in a gitian.sigs repository, Guix build outputs are attested to in the guix.sigs repository.

After you've cloned the guix.sigs repository, to attest to the current worktree's commit/tag:

env GUIX_SIGS_REPO=<path/to/guix.sigs> SIGNER=<gpg-key-name> ./contrib/guix/guix-attest

See ./contrib/guix/guix-attest --help for more information on the various ways guix-attest can be invoked.

Verifying build output attestations

After at least one other signer has uploaded their signatures to the guix.sigs repository:

git -C <path/to/guix.sigs> pull
env GUIX_SIGS_REPO=<path/to/guix.sigs> ./contrib/guix/guix-verify

Common guix-build invocation patterns and examples

Keeping caches and SDKs outside of the worktree

If you perform a lot of builds and have a bunch of worktrees, you may find it more efficient to keep the depends tree's download cache, build cache, and SDKs outside of the worktrees to avoid duplicate downloads and unnecessary builds. To help with this situation, the guix-build script honours the SOURCES_PATH, BASE_CACHE, and SDK_PATH environment variables and will pass them on to the depends tree so that you can do something like:

env SOURCES_PATH="$HOME/depends-SOURCES_PATH" BASE_CACHE="$HOME/depends-BASE_CACHE" SDK_PATH="$HOME/macOS-SDKs" ./contrib/guix/guix-build

Note that the paths that these environment variables point to must be directories, and NOT symlinks to directories.

See the recognized environment variables section for more details.

Building a subset of platform triples

Sometimes you only want to build a subset of the supported platform triples, in which case you can override the default list by setting the space-separated HOSTS environment variable:

env HOSTS='x86_64-w64-mingw32 x86_64-apple-darwin' ./contrib/guix/guix-build

See the recognized environment variables section for more details.

Controlling the number of threads used by guix build commands

Depending on your system's RAM capacity, you may want to decrease the number of threads used to decrease RAM usage or vice versa.

By default, the scripts under ./contrib/guix will invoke all guix build commands with --cores="$JOBS". Note that $JOBS defaults to $(nproc) if not specified. However, astute manual readers will also notice that guix build commands also accept a --max-jobs= flag (which defaults to 1 if unspecified).

Here is the difference between --cores= and --max-jobs=:

Note: When I say "derivation," think "package"

--cores=

  • controls the number of CPU cores to build each derivation. This is the value passed to make's --jobs= flag.

--max-jobs=

  • controls how many derivations can be built in parallel
  • defaults to 1

Therefore, the default is for guix build commands to build one derivation at a time, utilizing $JOBS threads.

Specifying the $JOBS environment variable will only modify --cores=, but you can also modify the value for --max-jobs= by specifying $ADDITIONAL_GUIX_COMMON_FLAGS. For example, if you have a LOT of memory, you may want to set:

export ADDITIONAL_GUIX_COMMON_FLAGS='--max-jobs=8'

Which allows for a maximum of 8 derivations to be built at the same time, each utilizing $JOBS threads.

Or, if you'd like to avoid spurious build failures caused by issues with parallelism within a single package, but would still like to build multiple packages when the dependency graph allows for it, you may want to try:

export JOBS=1 ADDITIONAL_GUIX_COMMON_FLAGS='--max-jobs=8'

See the recognized environment variables section for more details.

Recognized environment variables

  • HOSTS

    Override the space-separated list of platform triples for which to perform a bootstrappable build.

    (defaults to "x86_64-linux-gnu arm-linux-gnueabihf aarch64-linux-gnu riscv64-linux-gnu powerpc64-linux-gnu powerpc64le-linux-gnu x86_64-w64-mingw32 x86_64-apple-darwin arm64-apple-darwin")

  • SOURCES_PATH

    Set the depends tree download cache for sources. This is passed through to the depends tree. Setting this to the same directory across multiple builds of the depends tree can eliminate unnecessary redownloading of package sources.

    The path that this environment variable points to must be a directory, and NOT a symlink to a directory.

  • BASE_CACHE

    Set the depends tree cache for built packages. This is passed through to the depends tree. Setting this to the same directory across multiple builds of the depends tree can eliminate unnecessary building of packages.

    The path that this environment variable points to must be a directory, and NOT a symlink to a directory.

  • SDK_PATH

    Set the path where extracted SDKs can be found. This is passed through to the depends tree. Note that this is should be set to the parent directory of the actual SDK (e.g. SDK_PATH=$HOME/Downloads/macOS-SDKs instead of $HOME/Downloads/macOS-SDKs/Xcode-12.2-12B45b-extracted-SDK-with-libcxx-headers).

    The path that this environment variable points to must be a directory, and NOT a symlink to a directory.

  • JOBS

    Override the number of jobs to run simultaneously, you might want to do so on a memory-limited machine. This may be passed to:

    • guix build commands as in guix environment --cores="$JOBS"
    • make as in make --jobs="$JOBS"
    • xargs as in xargs -P"$JOBS"

    See here for more details.

    (defaults to the value of nproc outside the container)

  • SOURCE_DATE_EPOCH

    Override the reference UNIX timestamp used for bit-for-bit reproducibility, the variable name conforms to standard.

    (defaults to the output of $(git log --format=%at -1))

  • V

    If non-empty, will pass V=1 to all make invocations, making make output verbose.

    Note that any given value is ignored. The variable is only checked for emptiness. More concretely, this means that V= (setting V to the empty string) is interpreted the same way as not setting V at all, and that V=0 has the same effect as V=1.

  • SUBSTITUTE_URLS

    A whitespace-delimited list of URLs from which to download pre-built packages. A URL is only used if its signing key is authorized (refer to the substitute servers section for more details).

  • ADDITIONAL_GUIX_COMMON_FLAGS

    Additional flags to be passed to all guix commands.

  • ADDITIONAL_GUIX_TIMEMACHINE_FLAGS

    Additional flags to be passed to guix time-machine.

  • ADDITIONAL_GUIX_ENVIRONMENT_FLAGS

    Additional flags to be passed to the invocation of guix environment inside guix time-machine.

Choosing your security model

No matter how you installed Guix, you need to decide on your security model for building packages with Guix.

Guix allows us to achieve better binary security by using our CPU time to build everything from scratch. However, it doesn't sacrifice user choice in pursuit of this: users can decide whether or not to use substitutes (pre-built packages).

Option 1: Building with substitutes

Step 1: Authorize the signing keys

Depending on the installation procedure you followed, you may have already authorized the Guix build farm key. In particular, the official shell installer script asks you if you want the key installed, and the debian distribution package authorized the key during installation.

You can check the current list of authorized keys at /etc/guix/acl.

At the time of writing, a /etc/guix/acl with just the Guix build farm key authorized looks something like:

(acl
 (entry
  (public-key
   (ecc
    (curve Ed25519)
    (q #8D156F295D24B0D9A86FA5741A840FF2D24F60F7B6C4134814AD55625971B394#)
    )
   )
  (tag
   (guix import)
   )
  )
 )

If you've determined that the official Guix build farm key hasn't been authorized, and you would like to authorize it, run the following as root:

guix archive --authorize < /var/guix/profiles/per-user/root/current-guix/share/guix/ci.guix.gnu.org.pub

If /var/guix/profiles/per-user/root/current-guix/share/guix/ci.guix.gnu.org.pub doesn't exist, try:

guix archive --authorize < <PREFIX>/share/guix/ci.guix.gnu.org.pub

Where <PREFIX> is likely:

  • /usr if you installed from a distribution package
  • /usr/local if you installed Guix from source and didn't supply any prefix-modifying flags to Guix's ./configure

For dongcarl's substitute server at https://guix.carldong.io, run as root:

wget -qO- 'https://guix.carldong.io/signing-key.pub' | guix archive --authorize

Removing authorized keys

To remove previously authorized keys, simply edit /etc/guix/acl and remove the (entry (public-key ...)) entry.

Step 2: Specify the substitute servers

Once its key is authorized, the official Guix build farm at https://ci.guix.gnu.org is automatically used unless the --no-substitutes flag is supplied. This default list of substitute servers is overridable both on a guix-daemon level and when you invoke guix commands. See examples below for the various ways of adding dongcarl's substitute server after having authorized his signing key.

Change the default list of substitute servers by starting guix-daemon with the --substitute-urls option (you will likely need to edit your init script):

guix-daemon <cmd> --substitute-urls='https://guix.carldong.io https://ci.guix.gnu.org'

Override the default list of substitute servers by passing the --substitute-urls option for invocations of guix commands:

guix <cmd> --substitute-urls='https://guix.carldong.io https://ci.guix.gnu.org'

For scripts under ./contrib/guix, set the SUBSTITUTE_URLS environment variable:

export SUBSTITUTE_URLS='https://guix.carldong.io https://ci.guix.gnu.org'

Option 2: Disabling substitutes on an ad-hoc basis

If you prefer not to use any substitutes, make sure to supply --no-substitutes like in the following snippet. The first build will take a while, but the resulting packages will be cached for future builds.

For direct invocations of guix:

guix <cmd> --no-substitutes

For the scripts under ./contrib/guix/:

export ADDITIONAL_GUIX_COMMON_FLAGS='--no-substitutes'

Option 3: Disabling substitutes by default

guix-daemon accepts a --no-substitutes flag, which will make sure that, unless otherwise overridden by a command line invocation, no substitutes will be used.

If you start guix-daemon using an init script, you can edit said script to supply this flag.