From e9c599e40c8d0d754980f51e580d00ebef3f2fea Mon Sep 17 00:00:00 2001 From: Friedrich Altheide <11352905+FriedrichAltheide@users.noreply.github.com> Date: Wed, 23 Jul 2025 17:42:37 +0200 Subject: [PATCH] yarn: add module (#7526) --- modules/programs/yarn/default.nix | 53 +++++++++++++++++++ tests/modules/programs/yarn/default.nix | 4 ++ tests/modules/programs/yarn/empty-config.nix | 12 +++++ .../modules/programs/yarn/example-config.nix | 20 +++++++ .../modules/programs/yarn/example-config.yml | 2 + 5 files changed, 91 insertions(+) create mode 100644 modules/programs/yarn/default.nix create mode 100644 tests/modules/programs/yarn/default.nix create mode 100644 tests/modules/programs/yarn/empty-config.nix create mode 100644 tests/modules/programs/yarn/example-config.nix create mode 100644 tests/modules/programs/yarn/example-config.yml diff --git a/modules/programs/yarn/default.nix b/modules/programs/yarn/default.nix new file mode 100644 index 00000000..1f879218 --- /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 00000000..86086e95 --- /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 00000000..9ec25e9c --- /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 00000000..baf8c690 --- /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 00000000..1936833d --- /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