/cosmos.nix

Nix Integration with Cosmos Projects

Primary LanguageNixMIT LicenseMIT

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.7. 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:
Cache Setup with Cachix

With nix installed you can run nix-env -iA cachix -f https://cachix.org/api/v1/install. If you don't want to install cachix globally and just want a one time use, you can run nix-shell -p cachix to enter a temporary shell with cachix available. You can check that this worked by running cachix --version.

You can now run these commands to add all of our cachix caches:

$ cachix use cosmos
$ cachix use pre-commit-hooks
$ cachix use nix-community
Manual Cache Setup

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 https://cosmos.cachix.org
trusted-public-keys = nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs= pre-commit-hooks.cachix.org-1:Pkk3Panw5AW24TOv6kz3PvLhlH8puAsJTBbOPmBo7Rc= cosmos.cachix.org-1:T5U9yg6u2kM48qAOXHO/ayhO8IWFnv0LOhNcq0yKuR8=
cores = 4 # NB: You may want to increase this on machines with more cores

NixOS

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 = {
    package = pkgs.nixFlakes;
    extraOptions = ''
      experimental-features = nix-command flakes
    '';
    binaryCaches = [
      "https://cache.nixos.org"
      "https://nix-community.cachix.org"
      "https://pre-commit-hooks.cachix.org"
      "https://cosmos.cachix.org"
    ];
    binaryCachePublicKeys = [
      "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
      "pre-commit-hooks.cachix.org-1:Pkk3Panw5AW24TOv6kz3PvLhlH8puAsJTBbOPmBo7Rc="
      "cosmos.cachix.org-1:T5U9yg6u2kM48qAOXHO/ayhO8IWFnv0LOhNcq0yKuR8="
    ];
   };

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

Development

Formatting

Formatting will be run via pre-commit hook if you are in the nix shell, otherise you can manually format using the format command like so:

nix develop -c format

Applications

Note: every command has a local and a remote variant. The local variant requires that the command is run from within the cloned repo. The remote variant can be run from wherever.

Local: nix run .#my-app-name

Remote: nix run github:informalsystems/cosmos.nix#my-app-name

For brevity and consistency all the commands are listed in the local variant

Executables provided

Relayers

Validators

  • thor:
    • bifrost: nix run .#bifrost
    • thorcli: nix run .#thorcli
    • thord: nix run .#thord
  • osmosis: nix run .#osmosis
  • gravity dex: nix run .#gdex
  • iris: nix run .#iris
  • regen: nix run .#regen
  • evmos: nix run .#evmos
  • centauri: nix run .#centauri

Development Tools