Skip to content

Commit

Permalink
Merge branch 'main' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
guillemcordoba committed Sep 23, 2024
2 parents 3174a8e + 316e12a commit cf977f2
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 186 deletions.
103 changes: 38 additions & 65 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,48 +39,15 @@ rec {

]);

filterByHolochainPackageType = holochainPackageType: packages:
inputs.nixpkgs.lib.filterAttrs (key: value:
(builtins.hasAttr "meta" value)
&& (builtins.hasAttr "holochainPackageType" value.meta)
&& value.meta.holochainPackageType == holochainPackageType)
packages;

filterZomes = filterByHolochainPackageType "zome";
filterDnas = filterByHolochainPackageType "dna";
filterHapps = filterByHolochainPackageType "happ";
filterNpmPackages = filterByHolochainPackageType "npm";

holochainPkgs = { system }:
let
pkgs = import inputs.nixpkgs {
inherit system;
overlays = [ (import inputs.rust-overlay) ];
};
in pkgs;

holochainRustToolchain = { system }:
let
pkgs = holochainPkgs { inherit system; };

rustToolchain = pkgs.rust-bin.stable."1.77.2".minimal.override {
# Set the build targets supported by the toolchain,
# wasm32-unknown-unknown is required for trunk.
targets = [ "wasm32-unknown-unknown" ];
};
in rustToolchain;
zomeCargoArtifacts = { system, craneLib ? (let

holochainCraneLib = { system }:
let
pkgs = holochainPkgs { inherit system; };
rustToolchain = holochainRustToolchain { inherit system; };
craneLib =
(inputs.crane.mkLib pkgs).overrideToolchain rustToolchain;
in craneLib;

zomeCargoArtifacts = { system
, craneLib ? (holochainCraneLib { inherit system; }), debug ? false
}:
pkgs = import inputs.nixpkgs {
inherit system;
overlays = [ (import inputs.rust-overlay) ];
};
craneLib = (inputs.crane.mkLib pkgs).overrideToolchain
inputs.holonix.outputs.packages.${system}.rust;
in craneLib), debug ? false }:
let
src =
craneLib.cleanCargoSource (craneLib.path ./nix/reference-happ);
Expand All @@ -98,8 +65,12 @@ rec {

holochainCargoArtifacts = { system }:
let
pkgs = holochainPkgs { inherit system; };
craneLib = holochainCraneLib { inherit system; };
pkgs = import inputs.nixpkgs {
inherit system;
overlays = [ (import inputs.rust-overlay) ];
};
craneLib = (inputs.crane.mkLib pkgs).overrideToolchain
inputs.holonix.outputs.packages.${system}.rust;

buildInputs = holochainDeps {
inherit pkgs;
Expand All @@ -122,40 +93,36 @@ rec {
in cargoArtifacts;

rustZome = { crateCargoToml, system, workspacePath
, nonWasmCrates ? [ ], cargoArtifacts ? null
, matchingZomeHash ? null }:
, cargoArtifacts ? null, matchingZomeHash ? null }:
let
pkgs = import inputs.nixpkgs {
inherit system;
overlays = [ (import inputs.rust-overlay) ];
};
deterministicCraneLib = let
pkgs = import inputs.nixpkgs {
system = "x86_64-linux";
overlays = [ (import inputs.rust-overlay) ];
};

rustToolchain = pkgs.rust-bin.stable."1.80.0".minimal.override {
# Set the build targets supported by the toolchain,
# wasm32-unknown-unknown is required for trunk.
targets = [ "wasm32-unknown-unknown" ];
};
rustToolchain =
inputs.holonix.outputs.packages."x86_64-linux".rust;
in (inputs.crane.mkLib pkgs).overrideToolchain rustToolchain;

pkgs = holochainPkgs { inherit system; };
craneLib = holochainCraneLib { inherit system; };

craneLib = (inputs.crane.mkLib pkgs).overrideToolchain
inputs.holonix.outputs.packages.${system}.rust;
zome-wasm-hash =
(outputs inputs).packages.${system}.zome-wasm-hash;

in pkgs.callPackage ./nix/zome.nix {
inherit deterministicCraneLib craneLib crateCargoToml
cargoArtifacts nonWasmCrates workspacePath matchingZomeHash
zome-wasm-hash;
referenceZomeCargoArtifacts = flake.lib.zomeCargoArtifacts;
cargoArtifacts workspacePath matchingZomeHash zome-wasm-hash;
};
sweettest = { system, dna, workspacePath, crateCargoToml
, buildInputs ? [ ], nativeBuildInputs ? [ ], cargoArtifacts ? null
}:
let
pkgs = holochainPkgs { inherit system; };
craneLib = holochainCraneLib { inherit system; };
pkgs = import inputs.nixpkgs {
inherit system;
overlays = [ (import inputs.rust-overlay) ];
};
craneLib = (inputs.crane.mkLib pkgs).overrideToolchain
inputs.holonix.outputs.packages.${system}.rust;
in pkgs.callPackage ./nix/sweettest.nix {
inherit dna craneLib crateCargoToml cargoArtifacts workspacePath;
buildInputs = buildInputs ++ holochainDeps {
Expand All @@ -165,7 +132,10 @@ rec {
};
dna = { system, dnaManifest, zomes, matchingIntegrityDna ? null }:
let
pkgs = holochainPkgs { inherit system; };
pkgs = import inputs.nixpkgs {
inherit system;
overlays = [ (import inputs.rust-overlay) ];
};
compare-dnas-integrity =
(outputs inputs).packages.${system}.compare-dnas-integrity;
dna-hash = (outputs inputs).packages.${system}.dna-hash;
Expand All @@ -177,7 +147,10 @@ rec {
};
happ = { system, happManifest, dnas }:
let
pkgs = holochainPkgs { inherit system; };
pkgs = import inputs.nixpkgs {
inherit system;
overlays = [ (import inputs.rust-overlay) ];
};
holochain = inputs.holonix.outputs.packages.${system}.holochain;
in pkgs.callPackage ./nix/happ.nix {
inherit dnas holochain happManifest;
Expand Down
70 changes: 34 additions & 36 deletions nix/dna.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,42 @@ let
dnaManifestJson = writeText "dna.json" (builtins.toJSON manifest');
dnaManifestYaml = runCommandLocal "json-to-yaml" { }
" ${json2yaml}/bin/json2yaml ${dnaManifestJson} $out\n"; # Recurse over the zomes, and add the correct bundled zome package by name
release = runCommandLocal manifest.name {
srcs = builtins.map (zome: zome.meta.release) zomeSrcs;
meta = { holochainPackageType = "dna"; };
outputs = [ "out" "hash" ];

# Debug package
debug = runCommandLocal manifest.name {
srcs = builtins.map (zome: zome.meta.debug) zomeSrcs;
} ''
mkdir workdir
cp ${dnaManifestYaml} workdir/dna.yaml
${
builtins.toString (builtins.map (zome: ''
cp ${zomes.${zome.name}.meta.debug} ./workdir/${zome.name}.wasm
'') manifest'.integrity.zomes)
}
${
builtins.toString (builtins.map (zome: ''
cp ${zomes.${zome.name}.meta.debug} ./workdir/${zome.name}.wasm
'') manifest'.coordinator.zomes)
}
${holochain}/bin/hc dna pack workdir
mv workdir/${manifest.name}.dna $out
'';

release = runCommandLocal "${manifest.name}-release" { srcs = zomeSrcs; } ''
mkdir workdir
cp ${dnaManifestYaml} workdir/dna.yaml
${
builtins.toString (builtins.map (zome: ''
cp ${zomes.${zome.name}.meta.release} ./workdir/${zome.name}.wasm
cp ${zomes.${zome.name}} ./workdir/${zome.name}.wasm
'') manifest'.integrity.zomes)
}
${
builtins.toString (builtins.map (zome: ''
cp ${zomes.${zome.name}.meta.release} ./workdir/${zome.name}.wasm
cp ${zomes.${zome.name}} ./workdir/${zome.name}.wasm
'') manifest'.coordinator.zomes)
}
Expand All @@ -48,42 +67,21 @@ let

guardedRelease = if matchingIntegrityDna != null then
runCommandLocal "check-match-dna-${manifest.name}-integrity" {
srcs = [ release matchingIntegrityDna.meta.release ];
srcs = [ release matchingIntegrityDna ];
buildInputs = [ compare-dnas-integrity ];
outputs = [ "out" "hash" ];
} ''
${compare-dnas-integrity}/bin/compare-dnas-integrity ${matchingIntegrityDna.meta.release} ${release}
${compare-dnas-integrity}/bin/compare-dnas-integrity ${matchingIntegrityDna} ${release}
cp ${release} $out
cat ${release.hash} > $hash
''
else
release;

# Debug package
debug = runCommandLocal manifest.name {
srcs = zomeSrcs;
meta = {
release = guardedRelease;
holochainPackageType = "dna";
};
outputs = [ "out" "hash" ];
} ''
mkdir workdir
cp ${dnaManifestYaml} workdir/dna.yaml
${
builtins.toString (builtins.map (zome: ''
cp ${zomes.${zome.name}} ./workdir/${zome.name}.wasm
'') manifest'.integrity.zomes)
}
${
builtins.toString (builtins.map (zome: ''
cp ${zomes.${zome.name}} ./workdir/${zome.name}.wasm
'') manifest'.coordinator.zomes)
}
${holochain}/bin/hc dna pack workdir
mv workdir/${manifest.name}.dna $out
in runCommandLocal manifest.name {
meta = { inherit debug; };
outputs = [ "out" ];
} ''
cp ${guardedRelease} $out
${dna-hash}/bin/dna-hash $out > $hash
'';
in debug
''
51 changes: 23 additions & 28 deletions nix/happ.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Build a hApp
{ happManifest, holochain, writeText, json2yaml, callPackage, runCommandNoCC
, runCommandLocal, dnas ? { } }:
{ happManifest, holochain, writeText, json2yaml, callPackage, runCommandLocal
, dnas ? { } }:

let
dnaSrcs = builtins.attrValues dnas;
Expand All @@ -19,42 +19,37 @@ let
happManifestYaml = runCommandLocal "json-to-yaml" { }
" ${json2yaml}/bin/json2yaml ${happManifestJson} $out\n";

release = runCommandLocal manifest.name {
srcs = builtins.map (dna: dna.meta.release) dnaSrcs;
meta = { holochainPackageType = "happ"; };
} ''
mkdir workdir
cp ${happManifestYaml} workdir/happ.yaml
${
builtins.toString (builtins.map (role: ''
cp ${dnas.${role.name}.meta.release} ./workdir/${role.name}.dna
'') manifest'.roles)
}
${holochain}/bin/hc app pack workdir
mv workdir/${manifest.name}.happ $out
'';

debug = runCommandLocal manifest.name {
srcs = dnaSrcs;
meta = {
inherit release;
holochainPackageType = "happ";
};
debug = runCommandLocal "${manifest.name}-debug" {
srcs = builtins.map (dna: dna.meta.debug) dnaSrcs;
} ''
mkdir workdir
cp ${happManifestYaml} workdir/happ.yaml
${
builtins.toString (builtins.map (role: ''
cp ${dnas.${role.name}} ./workdir/${role.name}.dna
cp ${dnas.${role.name}.meta.debug} ./workdir/${role.name}.dna
'') manifest.roles)
}
${holochain}/bin/hc app pack workdir
mv workdir/${manifest.name}.happ $out
'';
in debug

in runCommandLocal manifest.name {
meta = { inherit debug; };
srcs = dnaSrcs;
} ''
mkdir workdir
cp ${happManifestYaml} workdir/happ.yaml
${
builtins.toString (builtins.map (role: ''
cp ${dnas.${role.name}} ./workdir/${role.name}.dna
'') manifest'.roles)
}
${holochain}/bin/hc app pack workdir
mv workdir/${manifest.name}.happ $out
''
Loading

0 comments on commit cf977f2

Please sign in to comment.