From 502ecd02c3a2d2b7ada4558ce06410c6af445e73 Mon Sep 17 00:00:00 2001 From: Sander Date: Tue, 8 Oct 2024 23:57:30 +0400 Subject: [PATCH] javascript: ensure node build includes npm if `npm.enable` --- src/modules/languages/javascript.nix | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/modules/languages/javascript.nix b/src/modules/languages/javascript.nix index 6bd864c8d..06938b7d3 100644 --- a/src/modules/languages/javascript.nix +++ b/src/modules/languages/javascript.nix @@ -171,7 +171,9 @@ in enable = lib.mkEnableOption "install npm"; package = lib.mkOption { type = lib.types.package; - default = cfg.package; + default = cfg.package.override { + enableNpm = true; + }; defaultText = lib.literalExpression "languages.javascript.package"; description = "The Node.js package to use."; }; @@ -217,14 +219,14 @@ in }; config = lib.mkIf cfg.enable { - packages = [ - cfg.package - ] - ++ lib.optional cfg.npm.enable (cfg.npm.package) - ++ lib.optional cfg.pnpm.enable (cfg.pnpm.package) - ++ lib.optional cfg.yarn.enable (cfg.yarn.package.override { nodejs = cfg.package; }) - ++ lib.optional cfg.bun.enable (cfg.bun.package) - ++ lib.optional cfg.corepack.enable (pkgs.runCommand "corepack-enable" { } '' + packages + # Node ships with npm. If npm is enabled, use its package instead. + = lib.optional (!cfg.npm.enable) cfg.package + ++ lib.optional cfg.npm.enable (cfg.npm.package) + ++ lib.optional cfg.pnpm.enable (cfg.pnpm.package) + ++ lib.optional cfg.yarn.enable (cfg.yarn.package.override { nodejs = cfg.package; }) + ++ lib.optional cfg.bun.enable (cfg.bun.package) + ++ lib.optional cfg.corepack.enable (pkgs.runCommand "corepack-enable" { } '' mkdir -p $out/bin ${cfg.package}/bin/corepack enable --install-directory $out/bin '');