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 Gaia #8

Merged
merged 7 commits into from
Aug 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 56 additions & 5 deletions flake.lock

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

43 changes: 31 additions & 12 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
flake = false;
};

# Go Inputs
gomod2nix.url = "github:tweag/gomod2nix";

# Cosmos Sources
ibc-rs-src = {
url = github:informalsystems/ibc-rs;
Expand Down Expand Up @@ -48,6 +51,7 @@
, flake-utils
, rust-overlay
, crate2nix
, gomod2nix
, ibc-rs-src
, tendermint-rs-src
, gaia-src
Expand All @@ -65,6 +69,7 @@
rustc = final.rust-bin.stable.latest.default;
cargo = final.rust-bin.stable.latest.default;
})
gomod2nix.overlay
];
in
utils.eachDefaultSystem (system:
Expand All @@ -80,6 +85,7 @@
#
# Github Issue: https://github.com/NixOS/nix/issues/4265
generateCargoNix = (import "${crate2nix}/tools.nix" { pkgs = evalPkgs; }).generatedCargoNix;
goProjectSrcs = { inherit gaia-src; };
in
rec {
# nix build .#<app>
Expand All @@ -99,6 +105,7 @@
'';
};
hermes = (import ./hermes) { inherit pkgs ibc-rs-src generateCargoNix; };
gaia = (import ./gaia) { inherit gaia-src pkgs; };
};

# nix flake check
Expand All @@ -113,22 +120,34 @@
};

# nix develop
devShell = pkgs.mkShell {
inherit (self.checks.${system}.pre-commit-check) shellHook;
nativeBuildInputs = with pkgs; [
rustc
cargo
pkg-config
];
buildInputs = with pkgs; [
openssl
pkgs.crate2nix
];
};
devShell =
let
syncGoModulesInputs = with builtins; concatStringsSep " "
(attrValues (builtins.mapAttrs (name: value: "${name}${value}") goProjectSrcs));
syncGoModulesScript = pkgs.writeShellScriptBin "syncGoModules" ''
echo "${syncGoModulesInputs}" | ./syncGoModules.hs
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of syncing the narHash?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, so this is a bit complicated, but gomod2nix does not provide any tooling for generating dependency information dynamically from within nix. So we need to clone the go repo, call gomod2nix from the command line, and then use the generated go-modules.toml. So I wrote a script that does that for us, this way if we add more go repos or have to update the dependencies we can update our gomod2nix file as well. However, this would be pretty easy to forget to do, so when my script generates the go-modules.toml, it also spits out the narHash from the flake.lock file, this allows us to keep track of when we last synced the go modules.

Once I am done packaging all the software I want to add a flake check that will go into each go package's subdirectory and check to see if the narHash matches the one in flake.lock this way we can get a CI failure if someone updates the flake input but forgets to run syncGoModules

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation. I didn't look too much into it, but I guess this is similar to the hashes generated by Haskell.nix which needs to be checked in to source control. I think a potential issue is that users may encounter hash mismatch if they update the source code for Gaia to a different version and didn't execute the sync script.

This should work for now until we find a better solution.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a potential issue is that users may encounter hash mismatch if they update the source code for Gaia to a different version and didn't execute the sync script.

This is absolutely correct. That's why I want to either set up an assertion in the flake as a pre-commit hook that will fail if the hash is different, or setup a check that will fail in CI if the hashes are different. I will probably do both actually

'';
in
pkgs.mkShell {
inherit (self.checks.${system}.pre-commit-check) shellHook;
nativeBuildInputs = with pkgs; [
rustc
cargo
pkg-config
];
buildInputs = with pkgs; [
openssl
# need to prefix with pkgs because of they shadow the name of inputs
pkgs.crate2nix
pkgs.gomod2nix
syncGoModulesScript
];
};

# nix run .#<app>
apps = {
hermes = utils.mkApp { name = "hermes"; drv = packages.hermes; };
gaia = utils.mkApp { name = "gaia"; drv = packages.gaia; exePath = "/bin/gaiad"; };
};
});
}
12 changes: 12 additions & 0 deletions gaia/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{ pkgs, gaia-src }:
pkgs.buildGoApplication {
name = "gaia";
src = "${gaia-src}";
modules = ./go-modules.toml;

# NOTE: we need to create a tmp home directory for gaia's tests
preCheck = ''
export HOME="$(mktemp -d)"
'';
}

Loading