Skip to content
Merged
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
142 changes: 102 additions & 40 deletions pkgs/id/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,24 @@
#
# This derivation builds the release binary and runs the full test suite
# during the check phase.
#
# Dependency compilation is split from the package build with crane
# (code#8392, following atlas-search #8560 and fleet #8572): crane's
# buildDepsOnly compiles every registry dependency as its OWN
# derivation keyed only on the manifests + Cargo.lock (crane stubs the
# workspace crates' sources in that tier), so a source-only change
# rebuilds just the package derivation instead of the whole dependency
# tree. Callers may pass their own craneLib; standalone nix-build use
# constructs one from the pinned crane rev the repo's flakes already
# carry. The package tier keeps the monolith's exact behaviour —
# same features, same test suite, same postCheck fmt/clippy — except
# that the tests run under the release profile (crane reuses the
# dependency artifacts for the check phase) instead of the ci-check
# profile the monolith's checkType selected.

{
pkgs ? import <nixpkgs> { },
craneLib ? null,
}:

let
Expand All @@ -23,24 +38,66 @@ let
pname = cargoToml.package.name;
inherit (cargoToml.package) version;

in
{
# Main package build
default = pkgs.rustPlatform.buildRustPackage {
inherit pname version;
src = ./.;
# Crane, pinned to the rev the code repo's root lock already carries
# (the same rev atlas-search and fleet use).
craneLibEffective =
if craneLib != null then
craneLib
else
import (pkgs.fetchFromGitHub {
owner = "ipetkov";
repo = "crane";
rev = "01bc1d404a51a0a07e9d8759cd50a7903e218c82";
hash = "sha256-8qxEFpj4dVmIuPn9j9z6NTbU+hrcGjBOvaxTzre5HmM=";
}) { inherit pkgs; };

# Crane takes the lockfile as a path and the git-dependency hashes
# as a separate outputHashes argument (where buildRustPackage nested
# them under cargoLock), keyed by the lockfile's full source string
# instead of crate name-version — same checkout, same hash.
cargoLockPath = ./Cargo.lock;
outputHashesAttrs = {
"git+https://github.com/p2panda/p2panda?rev=da80c05b95269926bf58121cf6a2d3dd5ca41dfc#da80c05b95269926bf58121cf6a2d3dd5ca41dfc" =
"sha256-yq+ySfo14ucU1BWOUdJM0n7/FL3+Ria3Z+MxMHFa4Ls=";
};

buildFeatures = [
"sandbox"
"world"
metaAttrs = with pkgs.lib; {
description = "A peer-to-peer file sharing CLI built with Iroh";
homepage = "https://github.com/developing-today/code";
license = with licenses; [
mit
asl20
];
maintainers = [ ];
};

# Two source tiers. The dependency tier carries only what can change
# dependency compilation: the workspace manifests and lockfile, the
# crate sources (crane stubs the workspace members' Rust targets in
# this tier, so a source edit leaves the tier's output untouched),
# the vendored path dependencies (compiled for real as dependencies),
# the package-root build.rs (stubbed by crane here; its real run —
# the web/dist asset check — happens in the package tier, whose
# source is the full tree), and .cargo/config.toml.
depsSrc = pkgs.lib.fileset.toSource {
root = ./.;
fileset = pkgs.lib.fileset.unions [
./Cargo.toml
./Cargo.lock
./crates
./src
./vendor
./build.rs
./.cargo
];
};

cargoLock = {
lockFile = ./Cargo.lock;
outputHashes = {
"p2panda-core-0.7.1" = "sha256-yq+ySfo14ucU1BWOUdJM0n7/FL3+Ria3Z+MxMHFa4Ls=";
};
};
commonArgs = {
inherit pname version;
strictDeps = true;
cargoLock = cargoLockPath;
outputHashes = outputHashesAttrs;
cargoExtraArgs = "--locked --features sandbox,world";

nativeBuildInputs = with pkgs; [
pkg-config
Expand All @@ -49,33 +106,38 @@ in
buildInputs = with pkgs; [
openssl
];
};

# Run tests during build
doCheck = true;

# Compile and run the test phase under the ci-check profile (#3195)
# instead of release: same opt-level, no LTO / codegen-units=1 /
# strip costs for test binaries. The release binary build
# (cargoBuildType) is unchanged.
checkType = "ci-check";
# The dependency layer: every registry + vendored dependency compiled
# once, keyed on the deps tier above only.
cargoArtifacts = craneLibEffective.buildDepsOnly (commonArgs // { src = depsSrc; });

# Additional check commands (run after cargoTest)
postCheck = ''
echo "Running additional checks..."
cargo fmt -- --check
cargo clippy --all-targets --all-features -- -D warnings
'';

meta = with pkgs.lib; {
description = "A peer-to-peer file sharing CLI built with Iroh";
homepage = "https://github.com/developing-today/code";
license = with licenses; [
mit
asl20
];
maintainers = [ ];
};
};
in
{
# Main package build
default = craneLibEffective.buildPackage (
commonArgs
// {
# The package tier sees the full tree, exactly what the
# buildRustPackage build saw (tests read test-data/, the root
# build.rs checks web/dist, and so on).
src = ./.;
inherit cargoArtifacts;

# Run tests during build (the test suite runs under the release
# profile here — see the header note).
doCheck = true;

# Additional check commands (run after cargo test)
postCheck = ''
echo "Running additional checks..."
cargo fmt -- --check
cargo clippy --all-targets --all-features -- -D warnings
'';

meta = metaAttrs;
}
);

# Standalone check derivation - runs all quality checks
check = pkgs.stdenv.mkDerivation {
Expand Down