Skip to content

Nix: provide stacks-common #5973

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

Open
wants to merge 5 commits into
base: feat/clarity-wasm-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
18 changes: 9 additions & 9 deletions contrib/nix/flake.lock

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

62 changes: 51 additions & 11 deletions contrib/nix/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
crane = {
url = "github:ipetkov/crane";
};

};

outputs =
{
{ self,
nixpkgs,
flake-utils,
rust-overlay,
Expand All @@ -48,7 +47,7 @@
version = versions.stacks_node_version;

# Common arguments can be set here to avoid repeating them later
commonArgs = {
baseArgs = {
strictDeps = true;

buildInputs =
Expand All @@ -59,16 +58,48 @@
# Darwin specific inputs
pkgs.darwin.apple_sdk.frameworks.SystemConfiguration
];

src = fileSetForCrate ../..;
inherit version;
};

isClarityWASM = p: lib.hasPrefix "git+https://github.com/stacks-network/clarity-wasm.git" p.source;

cargoVendorDir = craneLib.vendorCargoDeps (
baseArgs
// {
# Use this function to override crates coming from git dependencies
overrideVendorGitCheckout =
ps: drv:
if lib.any (p: isClarityWASM p) ps then
drv.overrideAttrs (_old: {
patches = [
(builtins.fetchurl {
url = "https://github.com/stacks-network/clarity-wasm/pull/627.patch";
sha256 = "sha256:161mx1m21770lrsc2lfqlwzyydhy8f9bc7pmqb26rcki7s2ar31r";
})
];
})
else
# Nothing to change, leave the derivations as is
drv;

# Use this function to override crates coming from any registry checkout
overrideVendorCargoPackage = p: drv: drv;
}
);

commonArgs = baseArgs // {
inherit cargoVendorDir;
};

# Build *just* the cargo dependencies, so we can reuse
# all of that work (e.g. via cachix) when running in CI
cargoArtifacts = craneLib.buildDepsOnly (
commonArgs
// {
inherit version;
pname = name;
src = fileSetForCrate ../..;
dummySrc = commonArgs.src;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add a comment to remember us why we need this? Effectively, this is disabling pre-building any cargo dependency. I think it's an unfortunate byproduct of how the workspace is structured right now, so not much we can do until we fix that.

Copy link
Author

Choose a reason for hiding this comment

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

Would this still be needed when stacks-network/clarity-wasm#627 is merged?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Unfortunately yes, because of how dependencies refer to each other (with WASM depending on stacks-common).

}
);

Expand All @@ -85,8 +116,8 @@
lib.fileset.toSource {
root = ../..;
fileset = lib.fileset.unions [
../../Cargo.toml
../../Cargo.lock
(craneLib.fileset.commonCargoSources ../..)
(craneLib.fileset.configToml ../..)
#
../../versions.toml
#
Expand Down Expand Up @@ -126,6 +157,17 @@
}
);

stacks-common = craneLib.buildPackage (
individualCrateArgs
// rec {
version = (builtins.fromTOML (builtins.readFile ../../stacks-common/Cargo.toml)).package.version;
pname = "stacks-common";
cargoFeatures = "--features slog_json";
cargoExtraArgs = "${cargoFeatures} -p ${pname}";
src = fileSetForCrate ../../stacks-common;
}
);

# Build the actual crate itself, reusing the dependency
# artifacts from above.
stacks-core = craneLib.buildPackage (
Expand All @@ -143,7 +185,7 @@
with pkgs;
{
packages = {
inherit stacks-signer;
inherit stacks-signer stacks-common;
default = stacks-core;
};

Expand All @@ -159,9 +201,7 @@
default = stacks-node;
};

checks = {
inherit stacks-core;
};
checks = self.packages."${system}";

devShells.default = craneLib.devShell {
RUSTFMT = "${toolchain}/bin/rustfmt";
Expand Down