Skip to content

fix: nix build and nix check in CI #6274

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

Merged
merged 11 commits into from
Jul 15, 2025
41 changes: 41 additions & 0 deletions .github/workflows/nix-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Check Nix

on:
merge_group:
types:
- checks_requested
push:
branches:
- master
- develop
- next
paths-ignore:
- "**.md"
- "**.yml"
workflow_dispatch:
pull_request:
types:
- opened
- reopened
- synchronize

concurrency:
group: nix-${{ github.head_ref || github.ref || github.run_id }}
## Always cancel duplicate jobs
cancel-in-progress: true

run-name: ${{ github.ref_name }}

permissions: {}

jobs:
build-pkg:
name: Check Nix package
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: DeterminateSystems/determinate-nix-action@d4b23d0b9eeeaeba3648c24d43bcb623dcf75336 # v3.7.0
- uses: DeterminateSystems/magic-nix-cache-action@e1c1dae8e170ed20fd2e6aaf9979ca2d3905d636 # v12
with:
use-flakehub: false # Remove error when trying to authenticate without credentials
- run: nix flake check ./contrib/nix
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.

153 changes: 72 additions & 81 deletions contrib/nix/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,15 @@
inputs.nixpkgs.follows = "nixpkgs";
};

crane = {
url = "github:ipetkov/crane";
};
crane = { url = "github:ipetkov/crane"; };

};

outputs =
{
nixpkgs,
flake-utils,
rust-overlay,
crane,
...
}:
flake-utils.lib.eachDefaultSystem (
system:
outputs = { nixpkgs, flake-utils, rust-overlay, crane, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};
pkgs = import nixpkgs { inherit system overlays; };

inherit (pkgs) lib;

Expand All @@ -51,26 +39,20 @@
commonArgs = {
strictDeps = true;

buildInputs =
[
# Add additional build inputs here
]
++ lib.optionals pkgs.stdenv.isDarwin [
# Darwin specific inputs
pkgs.darwin.apple_sdk.frameworks.SystemConfiguration
];
buildInputs = [
# Add additional build inputs here
] ++ lib.optionals pkgs.stdenv.isDarwin [
# Darwin specific inputs
];
};

# 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 ../..;
}
);
cargoArtifacts = craneLib.buildDepsOnly (commonArgs // {
inherit version;
pname = name;
src = fileSetForCrate ../..;
});

individualCrateArgs = commonArgs // {
inherit cargoArtifacts;
Expand All @@ -80,8 +62,7 @@
};

# TODO: Return minimum fileSets per each crate
fileSetForCrate =
crate:
fileSetForCrate = crate:
lib.fileset.toSource {
root = ../..;
fileset = lib.fileset.unions [
Expand Down Expand Up @@ -111,55 +92,73 @@
(craneLib.fileset.commonCargoSources ../../stackslib)
(craneLib.fileset.commonCargoSources ../../stx-genesis)
(craneLib.fileset.commonCargoSources ../../stacks-node)
(craneLib.fileset.commonCargoSources
../tools/config-docs-generator)
];
};

stacks-signer = craneLib.buildPackage (
individualCrateArgs
// rec {
version = versions.stacks_signer_version;
pname = "stacks-signer";
cargoFeatures = "--features monitoring_prom";
cargoExtraArgs = "${cargoFeatures} -p ${pname}";
src = fileSetForCrate ../../stacks-signer;
}
);
stacks-signer = craneLib.buildPackage (individualCrateArgs // rec {
version = versions.stacks_signer_version;
pname = "stacks-signer";
cargoFeatures = "--features monitoring_prom";
cargoExtraArgs = "${cargoFeatures} -p ${pname}";
src = fileSetForCrate ../../stacks-signer;
});

# Build the actual crate itself, reusing the dependency
# artifacts from above.
stacks-core = craneLib.buildPackage (
commonArgs
// rec {
inherit version cargoArtifacts;
doCheck = false;
pname = name;
cargoFeatures = "--features monitoring_prom,slog_json";
cargoExtraArgs = "${cargoFeatures}";
src = fileSetForCrate ../..;
}
);
in
with pkgs;
{
stacks-core = craneLib.buildPackage (commonArgs // rec {
inherit version cargoArtifacts;
doCheck = false;
pname = name;
cargoFeatures = "--features monitoring_prom,slog_json";
cargoExtraArgs = "${cargoFeatures}";
src = fileSetForCrate ../..;
});

stacks-node-app = {
type = "app";
program = "${stacks-core}/bin/stacks-node";
meta = with lib; {
license = licenses.gpl3;
platforms = platforms.all;
description = "The Stacks blockchain implementation.";
homepage = "https://stacks.co";
};
};

stacks-signer-app = {
type = "app";
program = "${stacks-signer}/bin/stacks-signer";
meta = with lib; {
license = licenses.gpl3;
platforms = platforms.all;
description = "Signer for the Stacks blockchain implementation.";
homepage = "https://stacks.co";
};
};
in with pkgs; {
packages = {
inherit stacks-signer;
inherit stacks-signer stacks-core;
default = stacks-core;
};

apps = rec {
stacks-node = {
type = "app";
program = "${stacks-core}/bin/stacks-node";
};
stacks-signer = {
type = "app";
program = "${stacks-signer}/bin/stacks-signer";
};
default = stacks-node;
apps = {
stacks-node = stacks-node-app;
default = stacks-node-app;
stacks-signer = stacks-signer-app;
};

checks = {
inherit stacks-core;
workspaceCheck = craneLib.buildPackage (commonArgs // rec {
inherit version cargoArtifacts;
cargoBuildCommand = "cargo check --workspace";
doCheck = false;
pname = name;
cargoFeatures = "--features monitoring_prom,slog_json";
cargoExtraArgs = "${cargoFeatures}";
src = fileSetForCrate ../..;
});
};

devShells.default = craneLib.devShell {
Expand All @@ -174,16 +173,8 @@
set +x
'';

packages =
[
rust-analyzer
bitcoind
]
++ lib.optionals pkgs.stdenv.isDarwin [
pkgs.darwin.apple_sdk.frameworks.SystemConfiguration
pkgs.darwin.apple_sdk.frameworks.CoreServices
];
packages = [ rust-analyzer bitcoind ]
++ lib.optionals pkgs.stdenv.isDarwin [ ];
};
}
);
});
}
Loading