Skip to content

Reproducible Build With Nix

yihuang edited this page Sep 1, 2022 · 10 revisions

It's possible to reproducibly build cronosd binaries locally using nix.

Prerequisite

  • Install nix, follow the instructions here: https://nixos.org/download.html
  • Install cachix and enable cronos binary cache:
    $ nix-env -iA cachix -f https://cachix.org/api/v1/install
    $ cachix use cronos
    

Build Type Matrix

  • network type
    • mainnet (default)
    • testnet
  • db backend
    • rocksdb (default)
    • goleveldb
  • build type
    • normal nix package (default)
    • re-distributable bundle
    • re-distributable tarball, the tarball of the above bundle.

The package name is constructed by joining the above properties with separator -, omitting the default values, for example:

  • cronosd means mainnet rocksdb nix package.
  • cronosd-tarball means mainnet rocksdb re-distributable tarball.
  • cronosd-goleveldb-tarball means mainnet goleveldb re-distributable tarball.
  • cronosd-testnet-goleveldb-tarball means testnet goleveldb re-distributable tarball.

The nix flake url is like: github:crypto-org-chain/cronos/$TAG_NAME#$PACKAGE_NAME, replace the $TAG_NAME and $PACKAGE_NAME to the one you needed, for example, the full command to build a v0.7.0 rocksdb mainnet re-distributable tarball is:

$ nix build github:crypto-org-chain/cronos/v0.7.0#cronosd-tarball

The result is reside at ./result by default, then you can copy the tarball to other machines with the same OS and arch. The re-distributable bundle/tarball has dynamic libraries included, no extra runtime dependency is needed.

Tarball Content

To keep the tarball redistributable, it has all the runtime dependencies included, the dynamic linker, and the shared libraries, and they are founded with a relative path, so it's important that the whole package is moved together.

  • bin, a wrapper script that executes the binary with included dynamic linker.
  • exe, the executable.
  • lib, all the shared libraries.
Clone this wiki locally