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

WIP feat: add language.nodejs extra #233

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions extra/language/nodejs.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{ lib, config, pkgs, ... }:
let
cfg = config.language.nodejs;
strOrPackage = import ../../nix/strOrPackage.nix { inherit lib pkgs; };
in
with lib;
{
options.language.nodejs = {
package = mkOption {
type = strOrPackage;
default = pkgs.nodejs; # latest
example = literalExpression "pkgs.nodejs-18_x";
description = "Which nodejs package to use";
};
};

config = {
devshell.packages = [
cfg.package # nodejs itself

# TODO: npm

# Yarn
(pkgs.yarn.override {
nodejs = cfg.package;
})

# Pnpm
(pkgs.nodePackages.pnpm.override {
nodejs = cfg.package; # sadly doesn't suffice, but I found this:
Comment on lines +23 to +30
Copy link

@r17x r17x Nov 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it could be like this:

  • override nodejs pkg in pkgs.nodePackages
let nodePackages = pkgs.nodePackages.override {
  nodejs = cfg.package
};
  • define packages
devshell.packages = [
  cfg.package
 
  nodePackages.yarn
  nodePackages.pnpm
]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I tried this, but don't remember.

I figured that the overlay is much better and will then cover everything dependant on nodejs (e.g. yarn toplevel)

But I don't know how to do that in a devshell extra, do you?


# From discourse: https://discourse.nixos.org/t/how-to-use-pnpm-with-recent-nodejs/21867/2?u=tennox
nativeBuildInputs = [ pkgs.makeWrapper ];
preRebuild = ''
sed 's/"link:/"file:/g' --in-place package.json
'';
postInstall =
let
pnpmLibPath = pkgs.lib.makeBinPath [
cfg.package.passthru.python
cfg.package
];
in
''
for prog in $out/bin/*; do
wrapProgram "$prog" --prefix PATH : ${pnpmLibPath}
done
'';
})
];
};
}