mirror of
https://github.com/nix-community/home-manager.git
synced 2025-12-05 16:41:04 +01:00
yarn: add module (#7526)
This commit is contained in:
parent
b4752b0eda
commit
e9c599e40c
5 changed files with 91 additions and 0 deletions
53
modules/programs/yarn/default.nix
Normal file
53
modules/programs/yarn/default.nix
Normal file
|
|
@ -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:
|
||||
<https://yarnpkg.com/configuration/yarnrc>
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
home = {
|
||||
file =
|
||||
let
|
||||
yarnRcFileName = ".yarnrc.yml";
|
||||
in
|
||||
{
|
||||
"${yarnRcFileName}" = {
|
||||
source = yamlFormat.generate "${yarnRcFileName}" cfg.settings;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
4
tests/modules/programs/yarn/default.nix
Normal file
4
tests/modules/programs/yarn/default.nix
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
yarn = ./example-config.nix;
|
||||
yarn-empty-config = ./empty-config.nix;
|
||||
}
|
||||
12
tests/modules/programs/yarn/empty-config.nix
Normal file
12
tests/modules/programs/yarn/empty-config.nix
Normal file
|
|
@ -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
|
||||
'';
|
||||
}
|
||||
20
tests/modules/programs/yarn/example-config.nix
Normal file
20
tests/modules/programs/yarn/example-config.nix
Normal file
|
|
@ -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}
|
||||
'';
|
||||
}
|
||||
2
tests/modules/programs/yarn/example-config.yml
Normal file
2
tests/modules/programs/yarn/example-config.yml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
httpProxy: http://proxy.example.org:3128
|
||||
httpsProxy: http://proxy.example.org:3128
|
||||
Loading…
Add table
Add a link
Reference in a new issue