Skip to content

Commit

Permalink
javascript: ensure node build includes npm if npm.enable
Browse files Browse the repository at this point in the history
  • Loading branch information
sandydoo committed Oct 8, 2024
1 parent 24903d2 commit b7d18ba
Showing 1 changed file with 38 additions and 28 deletions.
66 changes: 38 additions & 28 deletions src/modules/languages/javascript.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
};
Expand Down Expand Up @@ -216,32 +218,40 @@ 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" { } ''
mkdir -p $out/bin
${cfg.package}/bin/corepack enable --install-directory $out/bin
'');

enterShell = lib.concatStringsSep "\n" (
(lib.optional cfg.npm.install.enable ''
config = lib.mkIf cfg.enable (lib.mkMerge [
(lib.mkIf cfg.npm.enable {
# Npm ships together with node.
packages = [
cfg.npm.package
];

enterShell = lib.optionalString cfg.npm.install.enable ''
source ${initNpmScript}
'') ++
(lib.optional cfg.pnpm.install.enable ''
source ${initPnpmScript}
'') ++
(lib.optional cfg.yarn.install.enable ''
source ${initYarnScript}
'') ++
(lib.optional cfg.bun.install.enable ''
source ${initBunScript}
'')
);
};
'';
})
(lib.mkIf (!cfg.npm.enable) {
packages = [
cfg.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
'');

enterShell = lib.concatStringsSep "\n" (
(lib.optional cfg.pnpm.install.enable ''
source ${initPnpmScript}
'') ++
(lib.optional cfg.yarn.install.enable ''
source ${initYarnScript}
'') ++
(lib.optional cfg.bun.install.enable ''
source ${initBunScript}
'')
);
})
]);
}

0 comments on commit b7d18ba

Please sign in to comment.