Files
home-manager/modules/programs/pnpm.nix
Drew Davis 7e3645c737 pnpm: init
2026-09-13 10:01:07 -05:00

64 lines
1.7 KiB
Nix

# https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/tools/pnpm/default.nix
{
config,
lib,
pkgs,
...
}:
let
inherit (lib) mkIf mkOption types;
cfg = config.programs.pnpm;
# https://pnpm.io/11.x/settings#storedir
defaultPnpmHome =
if config.xdg.enable then
"${config.xdg.dataHome}/pnpm"
else if pkgs.stdenv.hostPlatform.isDarwin then
"${config.home.homeDirectory}/Library/pnpm"
else
"${config.home.homeDirectory}/.local/share/pnpm";
in
{
meta.maintainers = with lib.maintainers; [ typeparameter ];
options = {
programs.pnpm = {
enable = lib.mkEnableOption "{command}`pnpm` user config";
package = lib.mkPackageOption pkgs "pnpm" { nullable = true; };
pnpmHome = mkOption {
type = types.str;
default = defaultPnpmHome;
defaultText = lib.literalExpression ''
if config.xdg.enable then
"''${config.xdg.dataHome}/pnpm"
else if pkgs.stdenv.hostPlatform.isDarwin then
"''${config.home.homeDirectory}/Library/pnpm"
else
"''${config.home.homeDirectory}/.local/share/pnpm"
'';
example = lib.literalExpression "\${config.home.homeDirectory}/.pnpm";
description = ''
The pnpm home directory. This sets {env}`PNPM_HOME`, which controls
the default locations of pnpm's package store, globally installed
packages, and global executables.
'';
};
};
};
config = mkIf cfg.enable {
home = {
packages = mkIf (cfg.package != null) [ cfg.package ];
sessionVariables = {
PNPM_HOME = cfg.pnpmHome;
};
sessionPath = [ "${cfg.pnpmHome}/bin" ];
};
};
}