canva-public / js2nix

Node.js modules installation using Nix
MIT License
63 stars 14 forks source link

Happy path to run #5

Closed blaggacao closed 1 year ago

blaggacao commented 1 year ago
# where to put overrides
{
    tree = js2nix.load ./yarn.lock {
      overlays = [
       (self: super: {
         "bespoke@1.2.0-dev" = super."bespoke@1.2.0-dev".override (x: {
           src = x.src.override {
             # Let Nix to recognise the type of archive so it unpacks it appropriately
             name = "5dd91d76ba088119836f60f514dc0a0b8b30e78d.tgz";
             sha256 ="1g7davl86xvbbfwirjj66xfbavv9ld9250bbni84wlcj0jmhy7xm";
           };
         });
       })
      ];
    };
}
olebedev commented 1 year ago

Now, how do I run the CLI in the repo:

Hi @blaggacao, thanks for the question.

Do you want to use your "bespoke@1.2.0-dev" available as an executable? Then you would go with something like:

with import <nixpkgs> { };

let
  js2nix = callPackage (builtins.fetchGit {
    url = "ssh://git@github.com/canva-public/js2nix.git";
    ref = "main";
  }) { };
  tree = js2nix.load ./yarn.lock {
    overlays = [
     (self: super: {
       "bespoke@1.2.0-dev" = super."bespoke@1.2.0-dev".override (x: {
         src = x.src.override {
           # Let Nix to recognise the type of archive so it unpacks it appropriately
           name = "5dd91d76ba088119836f60f514dc0a0b8b30e78d.tgz";
           sha256 ="1g7davl86xvbbfwirjj66xfbavv9ld9250bbni84wlcj0jmhy7xm";
         };
       });
     })
    ];
  };
in mkShell {
  passsthru.bespoke = tree."bespoke@1.2.0-dev";
  buildInputs = [
    tree."bespoke@1.2.0-dev"
  ];
}

Assuming you have your binary in your package.json file declared like this:

{
  ...
  "bin": {
    "bespoke": "./lib/bin/bespoke.js"
  }
  ...
}

then you would just do one of the standard nix-provided options:

I hope that helps :-)

blaggacao commented 1 year ago

Oh, no, actually I was referring to the current package marp-cli, of which bespoke is a dependency. I think I checked, but afair, the current pacakages is maybe out of scope for the generated derivations, here? (Since this is a dev tool)

olebedev commented 1 year ago

Ok, no worries. I created a minimal example of how to use js2nix to expose executables from NPM - https://gist.github.com/olebedev/3df80f4206e79c764d4376cd89c67a3e.

Let me know if you have any further questions.

blaggacao commented 1 year ago

Ah! That's the trick, just make it a dependency got ya. Thx!