1{ config, lib, pkgs, ... }:
2
3let
4 cfg = config.programs.npm;
5in
6
7{
8 ###### interface
9
10 options = {
11 programs.npm = {
12 enable = lib.mkEnableOption "{command}`npm` global config";
13
14 package = lib.mkPackageOption pkgs [ "nodePackages" "npm" ] {
15 example = "nodePackages_13_x.npm";
16 };
17
18 npmrc = lib.mkOption {
19 type = lib.types.lines;
20 description = ''
21 The system-wide npm configuration.
22 See <https://docs.npmjs.com/misc/config>.
23 '';
24 default = ''
25 prefix = ''${HOME}/.npm
26 '';
27 example = ''
28 prefix = ''${HOME}/.npm
29 https-proxy=proxy.example.com
30 init-license=MIT
31 init-author-url=https://www.npmjs.com/
32 color=true
33 '';
34 };
35 };
36 };
37
38 ###### implementation
39
40 config = lib.mkIf cfg.enable {
41 environment.etc.npmrc.text = cfg.npmrc;
42
43 environment.variables.NPM_CONFIG_GLOBALCONFIG = "/etc/npmrc";
44
45 environment.systemPackages = [ cfg.package ];
46 };
47
48}