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

Enhance Nix packaging to build the crates and CometBFT #4145

Merged
merged 11 commits into from
Apr 2, 2024
1 change: 1 addition & 0 deletions .envrc.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ book
# Used for deployments
firebase-tmp/

# Nix build output goes here
result

# Direnv files
.envrc
.direnv

plaidfinch marked this conversation as resolved.
Show resolved Hide resolved
## Rust / Cargo
# will have compiled files and executables
debug/
Expand Down
7 changes: 4 additions & 3 deletions crates/core/component/dex/src/lp/trading_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,10 @@ impl BareTradingFunction {
/// Since the fee `f` is bound by `0 <= < 5_000`, we have `1/2 <= gamma <= 1`.
///
/// ## Examples:
/// * A fee of 0% (0 bps) results in a discount factor of 1.
/// * A fee of 30 bps (30 bps) results in a discount factor of 0.997.
/// * A fee of 100% (10_000bps) results in a discount factor of 0.
///
/// * A fee of 0% (0 bps) results in a discount factor of 1.
/// * A fee of 30 bps (30 bps) results in a discount factor of 0.997.
/// * A fee of 100% (10_000bps) results in a discount factor of 0.
pub fn gamma(&self) -> U128x128 {
(U128x128::from(10_000 - self.fee) / U128x128::from(10_000u64)).expect("10_000 != 0")
}
Expand Down
47 changes: 46 additions & 1 deletion flake.lock

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

122 changes: 101 additions & 21 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,37 +1,117 @@
{
description = "a nix development shell for penumbra";
description = "A nix development shell and build environment for penumbra";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
};
};
plaidfinch marked this conversation as resolved.
Show resolved Hide resolved
crane = {
url = "github:ipetkov/crane";
inputs = { nixpkgs.follows = "nixpkgs"; };
};
};

outputs = { self, nixpkgs, flake-utils }:
outputs = { self, nixpkgs, flake-utils, rust-overlay, crane, ... }:
flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = import nixpkgs {
inherit system;
# Define versions of Penumbra and CometBFT
penumbraRelease = null; # Use the local working copy
# penumbraRelease = { # Use a specific release
# version = "0.71.0";
# sha256 = "sha256-2mpyBEt44UlXm6hahJG9sHGxj6nzh7z9lnj/vLtAAzs=";
# };
cometBftRelease = {
version = "0.37.5";
sha256 = "sha256-wNVHsifieAtZgedavCEJLgG0kRDqUhG4Lk5ciTPoNzI=";
vendorHash = "sha256-JPEGMa0HDesEtKFvgLUP2UfTB0DlParepE2p+n06Igc=";
};
nativeBuildInputs = with pkgs; [
pkg-config
];
buildInputs = with pkgs; [
clang
openssl
rustup
];
in
with pkgs;
{
devShells.default = mkShell {
inherit buildInputs nativeBuildInputs;

# Set up for Rust builds, pinned to the Rust toolchain version in the Penumbra repository
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs { inherit system overlays; };
rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;

# Important environment variables so that the build can find the necessary libraries
PKG_CONFIG_PATH="${pkgs.openssl.dev}/lib/pkgconfig";
LIBCLANG_PATH="${pkgs.libclang.lib}/lib";
in with pkgs; with pkgs.lib; let
# All the Penumbra binaries
penumbra = (craneLib.buildPackage {
pname = "penumbra";
src = cleanSourceWith {
src = if penumbraRelease == null then craneLib.path ./. else fetchFromGitHub {
owner = "penumbra-zone";
repo = "penumbra";
rev = "v${penumbraRelease.version}";
sha256 = "${penumbraRelease.sha256}";
};
plaidfinch marked this conversation as resolved.
Show resolved Hide resolved
filter = path: type:
# Retain proving and verification parameters, and no-lfs marker file ...
(builtins.match ".*\.(no_lfs|param||bin)$" path != null) ||
# ... as well as all the normal cargo source files:
(craneLib.filterCargoSources path type);
};
nativeBuildInputs = [ pkg-config ];
buildInputs = [ clang openssl ];
inherit system PKG_CONFIG_PATH LIBCLANG_PATH;
cargoExtraArgs = "-p pd -p pcli -p pclientd";
meta = {
description = "A fully private proof-of-stake network and decentralized exchange for the Cosmos ecosystem";
homepage = "https://penumbra.zone";
license = [ licenses.mit licenses.asl20 ];
};
}).overrideAttrs (_: { doCheck = false; }); # Disable tests to improve build times

# CometBFT
cometbft = (buildGoModule rec {
pname = "cometbft";
version = cometBftRelease.version;
subPackages = [ "cmd/cometbft" ];
src = fetchFromGitHub {
owner = "cometbft";
repo = "cometbft";
rev = "v${cometBftRelease.version}";
hash = cometBftRelease.sha256;
};
vendorHash = cometBftRelease.vendorHash;
meta = {
description = "CometBFT (fork of Tendermint Core): A distributed, Byzantine fault-tolerant, deterministic state machine replication engine";
homepage = "https://github.com/cometbft/cometbft";
license = licenses.asl20;
};
}).overrideAttrs (_: { doCheck = false; }); # Disable tests to improve build times
in rec {
packages = { inherit penumbra cometbft; };
apps = {
pd.type = "app";
pd.program = "${penumbra}/bin/pd";
pcli.type = "app";
pcli.program = "${penumbra}/bin/pcli";
pclientd.type = "app";
pclientd.program = "${penumbra}/bin/pclientd";
cometbft.type = "app";
cometbft.program = "${cometbft}/bin/cometbft";
};
defaultPackage = symlinkJoin {
name = "penumbra-and-cometbft";
paths = [ penumbra cometbft ];
};
devShells.default = craneLib.devShell {
inherit LIBCLANG_PATH;
inputsFrom = [ penumbra ];
packages = [ cargo-watch ];
shellHook = ''
export CC="${pkgs.clang}/bin/clang"
export CXX="${pkgs.clang}/bin/clang++"
export LIBCLANG_PATH="${pkgs.libclang.lib}/lib"
export LIBCLANG_PATH=${LIBCLANG_PATH}
export RUST_SRC_PATH=${pkgs.rustPlatform.rustLibSrc} # Required for rust-analyzer
'';
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang}/lib/libclang.so";
};
}
);
Expand Down
2 changes: 2 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[toolchain]
channel = "stable"
Loading