diff --git a/71 b/71 new file mode 100644 index 0000000000..e69de29bb2 diff --git a/assets.nix b/assets.nix index a519a789ec..9ad7287a46 100644 --- a/assets.nix +++ b/assets.nix @@ -1,5 +1,7 @@ -{ pkgs ? import ./nix {} -, bootstrap-js ? import ./src/bootstrap { inherit pkgs; } +{ system ? builtins.currentSystem +, pkgs ? import ./nix {} +, bootstrap-js ? import ./nix/agent-js/bootstrap-js.nix { inherit system pkgs; } +, agent-js ? import ./nix/agent-js/agent-js.nix { inherit system pkgs; } , distributed-canisters ? import ./distributed-canisters.nix { inherit pkgs; } }: pkgs.runCommandNoCCLocal "assets" {} '' @@ -17,5 +19,8 @@ pkgs.runCommandNoCCLocal "assets" {} '' mkdir $out/bootstrap cp -R ${bootstrap-js.out}/* $out/bootstrap/ + mkdir $out/agent-js + cp -R ${agent-js.out}/* $out/agent-js/ + cp -R ${distributed-canisters} $out/canisters '' diff --git a/default.nix b/default.nix index 78c55573a3..7773f97f1b 100644 --- a/default.nix +++ b/default.nix @@ -14,10 +14,10 @@ rec { node-e2e-tests = import ./e2e/node { inherit pkgs dfx; }; # Agents in varous languages - agent-js = import ./src/agent/javascript { inherit pkgs; }; + agent-js = import ./nix/agent-js/agent-js.nix { inherit system pkgs; }; # Bootstrap frontend. - bootstrap-js = import ./src/bootstrap { inherit pkgs agent-js; }; + bootstrap-js = import ./nix/agent-js/bootstrap-js.nix { inherit system pkgs; }; cargo-audit = import ./cargo-audit.nix { inherit pkgs RustSec-advisory-db; }; diff --git a/nix/agent-js/agent-js-monorepo.nix b/nix/agent-js/agent-js-monorepo.nix new file mode 100644 index 0000000000..f812c2a414 --- /dev/null +++ b/nix/agent-js/agent-js-monorepo.nix @@ -0,0 +1,51 @@ +{ pkgs ? import ../. { inherit system; } +, system ? builtins.currentSystem + # This should be via sourcesnix for the git monorepo +, agent-js-monorepo-src +}: +let + src = agent-js-monorepo-src; + agentPackagePath = (src + "/packages/agent"); + monorepo = pkgs.napalm.buildPackage src { + name = "agent-js-monorepo"; + buildInputs = [ + pkgs.python3 + ]; + propagatedNativeBuildInputs = [ + # Required by node-gyp + pkgs.python3 + ]; + propagatedBuildInputs = pkgs.lib.optional pkgs.stdenv.isDarwin + # Required by fsevents + pkgs.darwin.apple_sdk.frameworks.CoreServices; + outputs = [ + "out" + "agent" + "bootstrap" + "lib" + ]; + # HUSKY_DEBUG = "1"; + # HUSKY_SKIP_INSTALL = "1"; + npmCommands = [ + "npm install" + ]; + installPhase = '' + mkdir -p $out + + cp -R ./* $out/ + + # Copy node_modules to be reused elsewhere. + mkdir -p $lib + test -d node_modules && cp -R node_modules $lib || true + + mkdir -p $agent + cp -R node_modules $agent/ + cp -R ./packages/agent/* $agent/ + + mkdir -p $bootstrap + cp -R node_modules $bootstrap/ + cp -R ./packages/bootstrap/* $bootstrap/ + ''; + }; +in +monorepo diff --git a/nix/agent-js/agent-js.nix b/nix/agent-js/agent-js.nix new file mode 100644 index 0000000000..608367a753 --- /dev/null +++ b/nix/agent-js/agent-js.nix @@ -0,0 +1,27 @@ +{ pkgs ? import ../. { inherit system; } +, system ? builtins.currentSystem +}: +pkgs.stdenv.mkDerivation { + name = "agent-js"; + src = "${pkgs.agent-js-monorepo}/packages/agent/"; + buildInputs = [ pkgs.nodejs ]; + outputs = [ + "out" + "lib" + ]; + buildPhase = '' + # Don't run `npm run build` here, which will call `tsc -b`. + # `tsc -b` will use typescrpit project references to build things, + # which may try to read from other packages. But nix will error on read from those dirs. + # Let all building happen on the monorepo package. + ''; + installPhase = '' + mkdir -p $out + + cp -R ./* $out/ + + # Copy node_modules to be reused elsewhere. + mkdir -p $lib + test -d node_modules && cp -R node_modules $lib || true + ''; +} diff --git a/nix/agent-js/bootstrap-js.nix b/nix/agent-js/bootstrap-js.nix new file mode 100644 index 0000000000..83f190eda3 --- /dev/null +++ b/nix/agent-js/bootstrap-js.nix @@ -0,0 +1,27 @@ +{ pkgs ? import ../. { inherit system; } +, system ? builtins.currentSystem +}: +pkgs.stdenv.mkDerivation { + name = "bootstrap-js"; + src = "${pkgs.agent-js-monorepo}/packages/bootstrap/"; + buildInputs = [ pkgs.nodejs ]; + outputs = [ + "out" + "lib" + ]; + buildPhase = '' + # Don't run `npm run build` here, which will call `tsc -b`. + # `tsc -b` will use typescrpit project references to build things, + # which may try to read from other packages. But nix will error on read from those dirs. + # Let all building happen on the monorepo package. + ''; + installPhase = '' + mkdir -p $out + + cp -R ./* $out/ + + # Copy node_modules to be reused elsewhere. + mkdir -p $lib + test -d node_modules && cp -R node_modules $lib || true + ''; +} diff --git a/nix/default.nix b/nix/default.nix index b1ee8c3cd7..0b766936bf 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -43,6 +43,10 @@ let napalm = self.callPackage self.sources.napalm { pkgs = self // { nodejs = self.nodejs-12_x; }; }; + agent-js-monorepo = import ./agent-js/agent-js-monorepo.nix { + inherit system pkgs; + agent-js-monorepo-src = self.sources.agent-js-monorepo; + }; ic-ref = (import self.sources.ic-ref { inherit (self) system; }).ic-ref; nix-fmt = nixFmt.fmt; diff --git a/nix/sources.json b/nix/sources.json index 8e41f4780f..9a9a2f4b40 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -12,6 +12,12 @@ "url": "https://github.com/RustSec/advisory-db/archive/47d125073886d0a7891e6a33a2db4e69b2accaf0.tar.gz", "url_template": "https://github.com///archive/.tar.gz" }, + "agent-js-monorepo": { + "ref": "master", + "repo": "ssh://git@github.com/dfinity-lab/agent-js", + "rev": "c8a44f04bede186abc7c99e3a892a247dea05690", + "type": "git" + }, "bats-support": { "branch": "v0.3.0", "builtin": false, diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000000..48e341a095 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,3 @@ +{ + "lockfileVersion": 1 +}