nix-dotfiles/modules/npm.nix
2025-05-22 06:50:56 -06:00

45 lines
967 B
Nix

{
config,
pkgs,
lib,
...
}: let
npmGlobalDir = "~/.npm-global";
npmConf = pkgs.writeText "npmrc" ''
prefix=${npmGlobalDir}
cache=~/.npm
init-module=~/.npm-init.js
'';
in {
options.npm = {
enable = lib.mkEnableOption "System NPM Environment";
};
config = lib.mkIf config.npm.enable {
environment.systemPackages = with pkgs; [
nodejs_22
nodePackages.npm
electron
];
environment.variables = {
PATH = [
"${pkgs.nodejs_22}/bin"
"${npmGlobalDir}/bin"
];
};
environment.etc."npmrc".source = npmConf;
systemd.user.services.npm-setup = {
description = "Set up NPM user configuration";
wantedBy = ["default.target"];
script = ''
if [ ! -f ~/.npmrc ]; then
cp ${npmConf} ~/.npmrc
chmod u+rw ~/.npmrc
fi
'';
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
};
};
};
}