File tree Expand file tree Collapse file tree 4 files changed +102
-0
lines changed
tests/modules/programs/npm Expand file tree Collapse file tree 4 files changed +102
-0
lines changed Original file line number Diff line number Diff line change 1+ # https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/programs/npm.nix
2+ {
3+ config ,
4+ lib ,
5+ pkgs ,
6+ ...
7+ } :
8+ let
9+ cfg = config . programs . npm ;
10+ in
11+ {
12+ meta . maintainers = with lib . maintainers ; [ mirkolenz ] ;
13+
14+ options = {
15+ programs . npm = {
16+ enable = lib . mkEnableOption "{command}`npm` user config" ;
17+
18+ package = lib . mkPackageOption pkgs [ "nodePackages" "npm" ] {
19+ example = "nodePackages_13_x.npm" ;
20+ nullable = true ;
21+ } ;
22+
23+ npmrc = lib . mkOption {
24+ type = lib . types . lines ;
25+ description = ''
26+ The user-specific npm configuration.
27+ See <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=https://www.npmjs.com/
37+ color=true
38+ '' ;
39+ } ;
40+ } ;
41+ } ;
42+ config = lib . mkIf cfg . enable {
43+ home = {
44+ packages = lib . mkIf ( cfg . package != null ) [ cfg . package ] ;
45+ file . ".npmrc" = lib . mkIf ( cfg . npmrc != "" ) {
46+ text = cfg . npmrc ;
47+ } ;
48+ sessionVariables = lib . mkIf ( cfg . npmrc != "" ) {
49+ NPM_CONFIG_USERCONFIG = "${ config . home . homeDirectory } /.npmrc" ;
50+ } ;
51+ } ;
52+ } ;
53+ }
Original file line number Diff line number Diff line change 1+ {
2+ npm-example-settings = ./example-settings.nix ;
3+ npm-no-npmrc = ./no-npmrc.nix ;
4+ }
Original file line number Diff line number Diff line change 1+ { pkgs , ... } :
2+
3+ {
4+ programs . npm = {
5+ enable = true ;
6+ npmrc = ''
7+ prefix = '' ${HOME}/.npm
8+ registry=https://registry.example.com/
9+ color=true
10+ '' ;
11+ package = null ;
12+ } ;
13+
14+ nmt . script =
15+ let
16+ configPath = "home-files/.npmrc" ;
17+ expectedConfig = pkgs . writeText "npmrc-expected" ''
18+ prefix = '' ${HOME}/.npm
19+ registry=https://registry.example.com/
20+ color=true
21+ '' ;
22+ in
23+ ''
24+ assertFileExists "${ configPath } "
25+ assertFileContent "${ configPath } " "${ expectedConfig } "
26+ assertFileContains home-path/etc/profile.d/hm-session-vars.sh \
27+ 'export NPM_CONFIG_USERCONFIG="/home/hm-user/.npmrc"'
28+ '' ;
29+ }
Original file line number Diff line number Diff line change 1+ { pkgs , ... } :
2+
3+ {
4+ programs . npm = {
5+ enable = true ;
6+ npmrc = "" ;
7+ package = null ;
8+ } ;
9+
10+ nmt . script = ''
11+ assertPathNotExists home-files/.npmrc
12+ assertFileExists home-path/etc/profile.d/hm-session-vars.sh
13+ assertFileNotRegex home-path/etc/profile.d/hm-session-vars.sh \
14+ "export NPM_CONFIG_USERCONFIG="
15+ '' ;
16+ }
You can’t perform that action at this time.
0 commit comments