Evidence
@@ -604,7 +595,36 @@
- phPkg = mkPhPkg pkgs (mkPikaciSrc pkgs.lib);
+ phSrc = mkPhSrc pkgs.lib;
+ phCargoCommonArgs = {
+ pname = "ph";
+ version = "0.1.0";
+ src = phSrc;
+ cargoLock = ./Cargo.lock;
+ outputHashes = {
+ "git+https://github.com/futurepaul/hypernote-mdx?rev=db23b3d..." = "sha256-...";
+ "git+https://github.com/marmot-protocol/mdk?rev=ca0663e..." = "sha256-...";
+ "git+https://github.com/kixelated/moq?rev=5ad5c06..." = "sha256-...";
+ };
+ cargoExtraArgs = "--locked -p ph";
+ strictDeps = true;
+ doCheck = false;
+ nativeBuildInputs = [ pkgs.pkg-config ];
+ buildInputs = [ pkgs.openssl ] ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [ pkgs.libiconv ];
+ };
+ phCargoArtifacts = craneLib.buildDepsOnly ((builtins.removeAttrs phCargoCommonArgs [ "src" ]) // {
+ pname = "ph-deps";
+ dummySrc = craneLib.mkDummySrc phCargoCommonArgs;
+ });
+ phPkg = craneLib.buildPackage (phCargoCommonArgs // {
+ cargoArtifacts = phCargoArtifacts;
+ meta = {
+ mainProgram = "ph";
+ };
+ });
This is the core of the change. Three new bindings replace the old single-line phPkg = mkPhPkg pkgs ...:
phCargoCommonArgs
A shared attribute set holding every option that both build phases need:
src points to the new mkPhSrc-filtered source.
cargoLock / outputHashes tell Crane how to fetch git dependencies (note the keys are now full git URLs instead of short crate names).
cargoExtraArgs = "--locked -p ph" restricts the build to the ph package within the workspace.
buildInputs adds openssl (and libiconv on Darwin) while nativeBuildInputs adds pkg-config so the OpenSSL sys crate can link.
phCargoArtifacts — dependency layer
craneLib.buildDepsOnly ((builtins.removeAttrs phCargoCommonArgs [ "src" ]) // {
pname = "ph-deps";
dummySrc = craneLib.mkDummySrc phCargoCommonArgs;
});
buildDepsOnly compiles every dependency in Cargo.lock against a dummy source tree generated by mkDummySrc. Because the dummy source is derived deterministically from Cargo.toml/Cargo.lock, the resulting derivation hash only changes when dependencies change — not when application source code changes. The real src is explicitly removed from the args and replaced by dummySrc.
phPkg — application layer
craneLib.buildPackage (phCargoCommonArgs // {
cargoArtifacts = phCargoArtifacts;
meta.mainProgram = "ph";
});
buildPackage receives the pre-built cargoArtifacts and compiles only the workspace-local crate code. On incremental rebuilds where only ph source changed, Nix reuses the cached phCargoArtifacts and only re-runs this final compilation step, significantly reducing build times.