diff --git a/modules/programs/yarn/default.nix b/modules/programs/yarn/default.nix new file mode 100644 index 000000000..1f879218b --- /dev/null +++ b/modules/programs/yarn/default.nix @@ -0,0 +1,53 @@ +{ + lib, + pkgs, + config, + ... +}: +let + inherit (lib) + mkIf + mkEnableOption + mkOption + ; + + cfg = config.programs.yarn; + + yamlFormat = pkgs.formats.yaml { }; +in +{ + meta.maintainers = [ lib.maintainers.friedrichaltheide ]; + + options.programs.yarn = { + enable = mkEnableOption "management of yarn config"; + + settings = mkOption { + type = yamlFormat.type; + default = { }; + example = '' + { + httpProxy = "http://proxy.example.org:3128"; + httpsProxy = "http://proxy.example.org:3128"; + } + ''; + description = '' + Available configuration options for yarn see: + + ''; + }; + }; + + config = mkIf cfg.enable { + home = { + file = + let + yarnRcFileName = ".yarnrc.yml"; + in + { + "${yarnRcFileName}" = { + source = yamlFormat.generate "${yarnRcFileName}" cfg.settings; + }; + }; + }; + }; +} diff --git a/tests/modules/programs/yarn/default.nix b/tests/modules/programs/yarn/default.nix new file mode 100644 index 000000000..86086e950 --- /dev/null +++ b/tests/modules/programs/yarn/default.nix @@ -0,0 +1,4 @@ +{ + yarn = ./example-config.nix; + yarn-empty-config = ./empty-config.nix; +} diff --git a/tests/modules/programs/yarn/empty-config.nix b/tests/modules/programs/yarn/empty-config.nix new file mode 100644 index 000000000..9ec25e9c6 --- /dev/null +++ b/tests/modules/programs/yarn/empty-config.nix @@ -0,0 +1,12 @@ +{ + programs.yarn = { + settings = { + httpProxy = "http://proxy.example.org:3128"; + httpsProxy = "http://proxy.example.org:3128"; + }; + }; + + nmt.script = '' + assertPathNotExists home-files/.yarnrc.yml + ''; +} diff --git a/tests/modules/programs/yarn/example-config.nix b/tests/modules/programs/yarn/example-config.nix new file mode 100644 index 000000000..baf8c690d --- /dev/null +++ b/tests/modules/programs/yarn/example-config.nix @@ -0,0 +1,20 @@ +{ + programs.yarn = { + enable = true; + + settings = { + httpProxy = "http://proxy.example.org:3128"; + httpsProxy = "http://proxy.example.org:3128"; + }; + }; + + nmt.script = + let + configPath = "home-files/.yarnrc.yml"; + in + '' + assertFileExists ${configPath} + assertFileContent ${configPath} \ + ${./example-config.yml} + ''; +} diff --git a/tests/modules/programs/yarn/example-config.yml b/tests/modules/programs/yarn/example-config.yml new file mode 100644 index 000000000..1936833d4 --- /dev/null +++ b/tests/modules/programs/yarn/example-config.yml @@ -0,0 +1,2 @@ +httpProxy: http://proxy.example.org:3128 +httpsProxy: http://proxy.example.org:3128