Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package Hermes #5

Merged
33 changes: 22 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
This is an experimental Nix project for integrating the Rust and Go projects in Cosmos
as Nix packages. Use this at your own risk.

## Setup Non-NixOS
## Setup

### Non-NixOS

This project is developed entirely in [Nix Flakes](https://nixos.wiki/wiki/Flakes).
To get started, run the following:
Expand All @@ -29,17 +31,21 @@ echo 'experimental-features = nix-command flakes' >> ~/.config/nix/nix.conf

[Setup Caches](https://nixos.org/manual/nix/unstable/package-management/sharing-packages.html)

Add these lines to your Nix config (either ~/.config/nix/nix.conf [for MacOS] or /etc/nix/nix.conf [for flavors of Linux, depending on your distro]):
Add these lines to your Nix config (either ~/.config/nix/nix.conf [for MacOS] or
/etc/nix/nix.conf [for flavors of Linux, depending on your distro]):

```
extra-substituters = https://cache.nixos.org https://nix-community.cachix.org https://pre-commit-hooks.cachix.org
trusted-public-keys = nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs= pre-commit-hooks.cachix.org-1:Pkk3Panw5AW24TOv6kz3PvLhlH8puAsJTBbOPmBo7Rc=
cores = 4 # NB: You may want to increase this on machines with more cores
```

### Setup NixOS
### NixOS

In your `configuration.nix` file add this. Note, you can add the suggested binary caches in addition to your existing ones.
In your `configuration.nix` file you can add code below. It does 2 things, the
first is that it enables nix experimental features (which enables flakes) and
second it adds cache information so you don't have to build everything yourself.
Note, you can add the suggested binary caches in addition to your existing ones.

```nix
nix = {
Expand All @@ -61,8 +67,8 @@ In your `configuration.nix` file add this. Note, you can add the suggested binar

## Sources

Right now only the sources of the upstream projects are given as
a Nix derivation. You can build them by running:
Right now only the sources of the upstream projects are given as a Nix
derivation. You can build them by running:

```bash
$ nix build
Expand All @@ -71,9 +77,14 @@ cosmos-sdk gaia ibc-go ibc-rs tendermint-rs
```

This is just to show that our Nix derivations now have access to the source code
of the upstream projects we want to support. The exact versions of the source code
are pinned inside the `flake.lock` file, and can be updated using the
`nix flake lock` command.
of the upstream projects we want to support. The exact versions of the source
code are pinned inside the `flake.lock` file, and can be updated using the `nix
flake lock` command.

We will then build actual Nix derivations based on these source files in
upcoming development.

## Applications

We will then build actual Nix derivations based on these source files
in upcoming development.
Here is a list of the commands you can invoke to run specific packges.
- [hermes](https://hermes.informal.systems/): `nix run .#hermes`
104 changes: 86 additions & 18 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 52 additions & 9 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
{
description = "A flake for building Hello World";
description = "A reproducible Cosmos";

inputs = {
# Nix Inputs
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
flake-utils.url = "github:numtide/flake-utils";

# Rust Inputs
rust-overlay.url = "github:oxalica/rust-overlay";
crate2nix = {
url = "github:yusdacra/crate2nix/feat/builtinfetchgit";
flake = false;
};

# Cosmos Sources
ibc-rs-src = {
flake = false;
url = github:informalsystems/ibc-rs;
flake = false;
};

tendermint-rs-src = {
Expand Down Expand Up @@ -39,16 +46,43 @@
, nixpkgs
, pre-commit-hooks
, flake-utils
, rust-overlay
, crate2nix
, ibc-rs-src
, tendermint-rs-src
, gaia-src
, cosmos-sdk-src
, ibc-go-src
}:
let utils = flake-utils.lib; in
let
utils = flake-utils.lib;
overlays = [
rust-overlay.overlay
(final: _: {
# Because rust-overlay bundles multiple rust packages into one
# derivation, specify that mega-bundle here, so that crate2nix
# will use them automatically.
rustc = final.rust-bin.stable.latest.default;
cargo = final.rust-bin.stable.latest.default;
})
];
in
utils.eachDefaultSystem (system:
let pkgs = nixpkgs.legacyPackages.${system}; in
let
pkgs = import nixpkgs { inherit system overlays; };
evalPkgs = import nixpkgs { system = "x86_64-linux"; inherit overlays; };
# Note: below is the only use of eval pkgs. This is due to an issue with import from
# derivation (IFD), which requires nix derivations to be built at evaluation time.
# Since we can't build on all system types (`utils.eachDefaultSystem` requires us
# to evaluate all possible systems) we need to pick a system for building during
# evaluation. With proper caching this flake should still work for running on all
# system types.
#
# Github Issue: https://github.com/NixOS/nix/issues/4265
generateCargoNix = (import "${crate2nix}/tools.nix" { pkgs = evalPkgs; }).generatedCargoNix;
in
rec {
# nix build .#<app>
packages = utils.flattenTree
{
sources = pkgs.stdenv.mkDerivation {
Expand All @@ -58,13 +92,13 @@
installPhase = ''
mkdir -p $out
ls -la $out
ln -s ${ibc-rs-src} $out/ibc-rs
ln -s ${tendermint-rs-src} $out/tendermint-rs
ln -s ${gaia-src} $out/gaia
ln -s ${cosmos-sdk-src} $out/cosmos-sdk
ln -s ${ibc-go-src} $out/ibc-go
'';
};
hermes = (import ./hermes) { inherit pkgs ibc-rs-src generateCargoNix; };
};

# nix flake check
Expand All @@ -81,11 +115,20 @@
# nix develop
devShell = pkgs.mkShell {
inherit (self.checks.${system}.pre-commit-check) shellHook;
# Add dev shell dependencies here
# buildInputs = with pkgs; [ ];
nativeBuildInputs = with pkgs; [
rustc
cargo
pkg-config
];
buildInputs = with pkgs; [
openssl
pkgs.crate2nix
];
};

# nix build
defaultPackage = packages.sources;
# nix run .#<app>
apps = {
hermes = utils.mkApp { name = "hermes"; drv = packages.hermes; };
};
});
}
25 changes: 25 additions & 0 deletions hermes/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{ pkgs, ibc-rs-src, generateCargoNix }:
let
name = "ibc-rs";

# Create the cargo2nix project
cargoNix = pkgs.callPackage
(generateCargoNix {
inherit name;
src = ibc-rs-src;
})
{
# Individual crate overrides
defaultCrateOverrides = pkgs.defaultCrateOverrides // {
${name} = _: {
nativeBuildInputs = with pkgs; [ rustc cargo pkgconfig ];
buildInputs = with pkgs; [ openssl ];
};
openssl-sys = _: {
nativeBuildInputs = with pkgs; [ rustc cargo pkgconfig ];
buildInputs = with pkgs; [ openssl ];
};
};
};
in
cargoNix.workspaceMembers.ibc-relayer-cli.build