Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage with private NPM packages? #151

Closed
rpearce opened this issue Aug 6, 2019 · 17 comments
Closed

Usage with private NPM packages? #151

rpearce opened this issue Aug 6, 2019 · 17 comments

Comments

@rpearce
Copy link

rpearce commented Aug 6, 2019

Hi, thanks for the work here! I'm somewhat familiar with nix but definitely am new to this project and was trying to see if there's a current solution for working with private NPM packages?

Thank you!

@svanderburg
Copy link
Owner

Currently there isn't. I actually don't use private NPM packages myself, but it would definitely be an interesting feature to have, but this is something that needs to be investigated.

@rpearce
Copy link
Author

rpearce commented Aug 6, 2019

Thank you for the quick response!

@lionello
Copy link

lionello commented Aug 7, 2019

This worked for me:

let
  netrc = builtins.path { name = "netrc"; path = ~/.netrc; };
  fetchurlPrivate = opts: fetchurl (opts // {
    curlOpts = "${opts.curlOpts or ""} --netrc-file ${netrc}";
  });
  nodeEnv = import ./default.nix {
    inherit pkgs;
    fetchurl = fetchurlPrivate;
  };
in nodeEnv.shell

Put your usernames/passwords in ~/.netrc according to https://ec.haxx.se/usingcurl-netrc.html. Change the generated default.nix and add fetchurl ? pkgs.fetchurl as an arg on top.

@bobvanderlinden
Copy link

Good suggestion, does the .netrc file also need to be included as sandbox-paths in the nix.conf?

@lionello
Copy link

@bobvanderlinden No need!

@rpearce
Copy link
Author

rpearce commented Aug 22, 2019

@lionello I will try this out soon. Thank you for responding

@locallycompact
Copy link

locallycompact commented Sep 24, 2019

How do you get node2nix to run in the first instance in order to generate the default.nix? I get a 401 unauthorized when I try to run node2nix with a custom --registry flag.

@lionello
Copy link

@locallycompact I used a .netrc file

@locallycompact
Copy link

Placed where, used how?

@locallycompact
Copy link

@lionello If I have a ~/.netrc in my home directory node2nix doesn't pick it up. I can't use the snippet you posted above because I can't run node2nix in the first instance to generate the required default.nix. How do I get around this?

@lionello
Copy link

lionello commented Oct 3, 2019

Sorry, I meant ~/.npmrc:

_auth=auth-key-from-private-npm-registry
email=email-for-private-npm-registry
registry=https://url-for-private-npm-registry
always-auth=true

I also noticed that node2nix now has a --use-fetchgit-private option, which you can use with

export NIX_PATH="ssh-config-file=/etc/ssh/ssh_config:ssh-auth-sock=$SSH_AUTH_SOCK:$NIX_PATH"

@codygman
Copy link

codygman commented Feb 5, 2020

I would also find this feature very useful.

MasseGuillaume added a commit to MasseGuillaume/node2nix that referenced this issue Sep 12, 2020
MasseGuillaume added a commit to MasseGuillaume/node2nix that referenced this issue Sep 12, 2020
@jamesottaway
Copy link

https://nixos.wiki/wiki/Enterprise has some relevant info on how to instruct Nix builds to use creds found in /etc/nix/netrc.

@adrian-gierakowski
Copy link

@lionello in your solution the netrc file ends up being copied to nix-store, doesn't it? In which case it's not secure

@lionello
Copy link

Yeah you're right. Nowadays you should be able to use builtins.fetchurl instead.

@camelpunch
Copy link

This is still an issue. If you try to use builtins.fetchurl, you end up with another problem: the derivations generated by node2nix use sha512, which isn't recognised by builtins.fetchurl. You can try to use import <nix/fetchurl.nix> instead, but that doesn't unpack the tarball.

@camelpunch
Copy link

camelpunch commented Oct 11, 2023

I ended up with the following hack. In my case I wanted to build a private npm package that depended upon private npm packages, all located on GitHub packages. I first ran node2nix with:

  --registry https://registry.npmjs.org \
  --registry https://npm.pkg.github.com \
  --registry-auth-token "$token" \
  --registry-scope @my-scope

This generates default.nix, node-env.nix and node-packages.nix.

To avoid changing any of these generated files, I replaced nixpkgs' fetchurl with <nix/fetchurl.nix>. That derivation uses builtins.fetchurl, which cares about netrc files. But it doesn't untar, so I added that:

nodeEnv = import ./default.nix {
  pkgs = pkgs // {
    fetchurl =
      let
        otherFetchurl = import <nix/fetchurl.nix>;
      in
      args: pkgs.runCommand "custom-fetched-${args.url}" { } ''
        mkdir $out
        cd $out
        tar --strip-components=1 -xf ${otherFetchurl args}
      '';
  };
  nodejs = pkgs.nodejs;
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants