Skip to content

Latest commit

 

History

History
167 lines (127 loc) · 7.35 KB

README.md

File metadata and controls

167 lines (127 loc) · 7.35 KB

Cosmos ecosystem Built with nix License

Cosmos.nix

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

NOTE: If you already have nix installed, make sure you are on version >=2.18. Instructions to upgrade nix can be found here

Non-NixOS

This project is developed entirely in Nix Flakes. To get started, run the following:

  1. Install Nix:
$ curl -L https://nixos.org/nix/install | sh
  1. Install Nix Unstable:
$ nix-env -iA nixpkgs.nixFlakes
  1. Enable experimental features:
mkdir -p ~/.config/nix
echo 'experimental-features = nix-command flakes' >> ~/.config/nix/nix.conf
  1. Setup Caches:

Run this to add the cosmos-nix cache as a substituter

cachix use cosmos-nix

Shell

If you are just here for a remote nix shell (a development environment where you don't need to clone the repo) you can run the following command:

nix develop github:informalsystems/cosmos.nix#cosmos-shell

This will build the development environment. The environment will then be cached in your nix store and should be very fast. If you want to pull the latest development environment you should run:

nix develop github:informalsystems/cosmos.nix#cosmos-shell --refresh

Overlays

There are a few nix utilities provided as a nix library. There is also an overlay for all the cosmos packages exported by this flake, so you can fold them into your nixpkgs package set.

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs";
    cosmos-nix.url = "github:informalsystems/cosmos.nix";
  };
  outputs = { cosmos-nix, nixpkgs }: {
    let pkgs = import nixpkgs { 
            system = "x86_64-linux"; # Or whatever system you are on
            overlays = [
                cosmos-nix.overlays.cosmosNixLib       # Provides just the nix utility lib
                cosmos-nix.overlays.cosmosNixPackages  # Provides all the cosmos packages provided by cosmos.nix
                cosmos-nix.overlay                     # The default overlay gives you everything in the previous two combined
            ];
        }
    in ...
  };
}

Development

Formatting

Formatting will be run via the default nix command. You can find the formatter configuration in modules/formatter.nix

nix fmt

Contribution Guide

  1. Add the chains source code as a flake input
    inputs = {
        my-chain-src.url = "github:my-chains-organization/my-chains-repo";
        my-chain-src.flake = false;
    };
  1. Add a new file in packages/ named after the chain that you are packaging

Usually you will use this structure for cosmos-sdk chains, there are other examples of non-sdk chains in the repo

# packages/my-chain.nix
{
  mkCosmosGoApp,
  my-chain-src,
}:
mkCosmosGoApp {
  name = "my-chain";
  version = "v0.1.0";
  src = my-chain-src;
  rev = my-chain-src.rev;
  vendorHash = "sha256-WLLQKXjPRhK19oEdqp2UBZpi9W7wtYjJMj07omH41K0=";
  tags = ["netgo"];
  engine = "cometbft/cometbft";
}
  1. Import your new derivation into the modules/packages.nix file
    my-chain = import ../packages/my-chain.nix {
      inherit (cosmosLib) mkCosmosGoApp;
      inherit (inputs) my-chain-src;
    };
  1. Test that it works by running:
> git add .
> nix build .#my-chain
  1. Add the package to apps.nix, after you have built the package in step 4 you can check what the binary path is by running ls result/
  my-chain = {
    type = "app";
    program = "${packages.my-chain}/bin/mychaind";
  };