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

Add Flake #1502

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Open
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
48 changes: 48 additions & 0 deletions flake.lock

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

99 changes: 99 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{
description = "go-centrifuge";

inputs = {
nixpkgs.url = github:NixOS/nixpkgs/nixos-21.11;
gitignore = {
url = github:hercules-ci/gitignore.nix;
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = { self, nixpkgs, gitignore }:
let
name = "go-centrifuge";
version = "2.0";

system = "x86_64-linux";

pkgs = nixpkgs.legacyPackages.${system};

srcFilter = src:
let
srcIgnored = gitignore.lib.gitignoreFilter src;
ignoreList = [
".envrc"
".github"
"CODE_OF_CONDUCT.md"
"README.md"
"codecov.yml"
"flake.lock"
"flake.nix"
];
in
path: type:
srcIgnored path type
&& builtins.all (name: builtins.baseNameOf path != name) ignoreList;
in
{
packages.${system} = {
go-centrifuge = pkgs.buildGoModule {
Copy link
Contributor

Choose a reason for hiding this comment

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

Sort of same question as in the other PR, how to know the go version is used, probably part of the same presentation we have to shedule.

Copy link
Author

@asymmetric asymmetric Feb 26, 2022

Choose a reason for hiding this comment

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

The most basic way to know that is, is to:

  • inspect which commit of nixpkgs we're using in this repo, which is found in the flake.lock
  • Run nix run nixpkgs/$commit#go -- version

In this specific case:

❯ nix run nixpkgs/6f07605b6916abee5435ea1145a7541299a87c1b#go -- version
go version go1.16.9 linux/amd64

But I've also implemented a simpler solution, which works by dropping you in a shell where Go is installed. Since nixpkgs is pinned, this is the same Go used to build the app.

  • nix develop
  • go version

pname = name;
inherit version;

src = pkgs.lib.cleanSourceWith {
src = ./.;
filter = srcFilter ./.;
name = "${name}-source";
};

vendorSha256 = "sha256-Yr1lxkeW9rvOR+tLn9YBE682hgatsLGRqsalhcz+r9Y=";
};

dockerImage =
let
# This evaluates to the first 6 digits of the git hash of this repo's HEAD
# commit, or to "dirty" if there are uncommitted changes.
commit-substr = builtins.substring 0 6 (self.rev or "dirty");

tag = "${version}-${commit-substr}";
in
pkgs.dockerTools.buildLayeredImage {
name = "centrifugeio/${name}";
inherit tag;
created = builtins.substring 0 8 self.lastModifiedDate;

contents = [
pkgs.busybox
self.defaultPackage.${system}
];

config = {
ExposedPorts = {
# api
"8082/tcp" = { };
# p2p
"38202/tcp" = { };
};
Volumes = {
"/data" = { };
};
Entrypoint = [ "centrifuge" ];
};
};
};

defaultPackage.${system} = self.packages.${system}.go-centrifuge;

apps.${system}.centrifuge = {
type = "app";
program = "${self.defaultPackage.${system}}/bin/centrifuge";
};

defaultApp.${system} = self.apps.${system}.centrifuge;

devShell.${system} = pkgs.mkShellNoCC {
buildInputs = [ self.defaultPackage.${system} ];
};
};
}