This is an experimental Nix project for integrating the Rust and Go projects in Cosmos as Nix packages. Use this at your own risk.
NOTE: If you already have nix installed, make sure you are on version >=2.18. Instructions to upgrade nix can be found here
This project is developed entirely in Nix Flakes. To get started, run the following:
$ curl -L https://nixos.org/nix/install | sh
$ nix-env -iA nixpkgs.nixFlakes
mkdir -p ~/.config/nix
echo 'experimental-features = nix-command flakes' >> ~/.config/nix/nix.conf
Run this to add the cosmos-nix
cache as a substituter
cachix use cosmos-nix
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
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 ...
};
}
Formatting will be run via the default nix command. You can find the formatter configuration in modules/formatter.nix
nix fmt
- 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;
};
- 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";
}
- 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;
};
- Test that it works by running:
> git add .
> nix build .#my-chain
- 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";
};