diff --git a/flake.lock b/flake.lock index 770554c..bc832a8 100644 --- a/flake.lock +++ b/flake.lock @@ -34,10 +34,27 @@ "type": "github" } }, + "nixpkgs-23-05": { + "locked": { + "lastModified": 1685566663, + "narHash": "sha256-btHN1czJ6rzteeCuE/PNrdssqYD2nIA4w48miQAFloM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "4ecab3273592f27479a583fb6d975d4aba3486fe", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "23.05", + "repo": "nixpkgs", + "type": "github" + } + }, "root": { "inputs": { "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "nixpkgs-23-05": "nixpkgs-23-05" } }, "systems": { diff --git a/flake.nix b/flake.nix index ab4ee5f..da615c1 100644 --- a/flake.nix +++ b/flake.nix @@ -1,12 +1,17 @@ { description = "A nixpkgs analogue for Kadena's packages"; inputs = { + # We currently need nixpkgs-23-05 for a working version of rollup + # we can avoid this input when this issue is fixed: + # https://github.com/NixOS/nixpkgs/issues/294183 + nixpkgs-23-05.url = "github:NixOS/nixpkgs/23.05"; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; flake-utils.url = "github:numtide/flake-utils"; }; outputs = inputs: inputs.flake-utils.lib.eachDefaultSystem (system: let inherit (inputs) self; pkgs = inputs.nixpkgs.legacyPackages.${system}; + pkgs-23-05 = inputs.nixpkgs-23-05.legacyPackages.${system}; nodePackages = import "${self}/pkgs/nodePackages" { inherit pkgs system; nodejs = pkgs.nodejs; @@ -14,10 +19,15 @@ graph = import pkgs/graph { inherit pkgs system nodePackages; }; + kadena-cli = import pkgs/kadena-cli { + inherit pkgs system nodePackages; + rollup = pkgs-23-05.nodePackages.rollup; + }; in { packages = { inherit (graph) kadena-graph kadena-graph-unbundled; - kadena-cli = nodePackages."@kadena/kadena-cli"; + clibundle = nodePackages."clibundle-../kadena-cli"; + kadena-cli = kadena-cli.kadena-cli-bundled; }; apps = { update-node-packages = { diff --git a/pkgs/graph/default.nix b/pkgs/graph/default.nix index 6821cf3..90972ec 100644 --- a/pkgs/graph/default.nix +++ b/pkgs/graph/default.nix @@ -1,6 +1,7 @@ { pkgs ? import {inherit system;} , system ? builtins.currentSystem , nodejs ? pkgs.nodejs +, nodejs-slim ? pkgs.nodejs-slim , nodePackages ? import ../nodePackages { inherit pkgs system nodejs; } }: let @@ -48,7 +49,7 @@ let remove-references-to -t ${kadena-graph-unbundled} $out/bin/kadena-graph substituteInPlace $out/bin/kadena-graph \ - --replace "/usr/bin/env node" ${pkgs.nodejs-slim}/bin/node + --replace "/usr/bin/env node" ${nodejs-slim}/bin/node wrapProgram $out/bin/kadena-graph \ --set PRISMA_QUERY_ENGINE_LIBRARY "${prisma-slim}/lib/libquery_engine.node" \ diff --git a/pkgs/kadena-cli/default.nix b/pkgs/kadena-cli/default.nix new file mode 100644 index 0000000..2617019 --- /dev/null +++ b/pkgs/kadena-cli/default.nix @@ -0,0 +1,49 @@ +{ pkgs ? import {inherit system;} +, system ? builtins.currentSystem +, nodejs ? pkgs.nodejs +, nodejs-slim ? pkgs.nodejs-slim +, rollup ? pkgs.nodePackages.rollup +, nodePackages ? import ../nodePackages { inherit pkgs system nodejs; } +}: +with pkgs.lib; +let + clibundle = nodePackages."clibundle-../kadena-cli"; + kadena-cli-archive = lists.findSingle + (d: d.packageName == "@kadena/kadena-cli") + (builtins.abort "@kadena/kadena-cli not found in clibundle dependencies") + (builtins.abort "Multiple @kadena/kadena-cli found in clibundle dependencies") + clibundle.dependencies; + kadena-cli-bundled = pkgs.stdenv.mkDerivation rec { + inherit (kadena-cli-archive) version packageName; + buildInputs = [rollup pkgs.makeWrapper pkgs.removeReferencesTo]; + name = "kadena-${version}"; + enableParallelBuilding = true; + passAsFile = [ "buildCommand" ]; + buildCommand = '' + mkdir -p $out + cp -r ${clibundle} clibundle + chmod -R +w clibundle + + KADENACLI="clibundle/lib/node_modules/clibundle/" + + ( cd "$KADENACLI" && + rollup -c rollup.config.mjs + ) + + mkdir -p $out/lib + cp $KADENACLI/lib/cli.mjs $out/lib/cli.mjs + cp $KADENACLI/package.json $out/package.json + + remove-references-to -t ${clibundle} $out/lib/cli.mjs + + mkdir -p $out/bin + cat - > $out/bin/kadena <