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