diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 524bded3f5af..6a4947394f3e 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1281,6 +1281,13 @@ in A new module is available: 'services.darkman'. ''; } + + { + time = "2023-10-24T06:14:53+00:00"; + message = '' + A new module is available: 'programs.cava'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index c982248621c1..2e9d237b732c 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -70,6 +70,7 @@ let ./programs/browserpass.nix ./programs/btop.nix ./programs/carapace.nix + ./programs/cava.nix ./programs/chromium.nix ./programs/command-not-found/command-not-found.nix ./programs/comodoro.nix diff --git a/modules/programs/cava.nix b/modules/programs/cava.nix new file mode 100644 index 000000000000..63173248f1f1 --- /dev/null +++ b/modules/programs/cava.nix @@ -0,0 +1,52 @@ +{ pkgs, config, lib, ... }: + +with lib; + +let + + cfg = config.programs.cava; + + iniFmt = pkgs.formats.ini { }; + +in { + meta.maintainers = [ maintainers.bddvlpr ]; + + options.programs.cava = { + enable = mkEnableOption "Cava audio visualizer"; + + package = mkPackageOption pkgs "cava" { }; + + settings = mkOption { + type = iniFmt.type; + default = { }; + example = literalExpression '' + { + general.framerate = 60; + input.method = "alsa"; + smoothing.noise_reduction = 88; + color = { + background = "'#000000'"; + foreground = "'#FFFFFF'"; + }; + } + ''; + description = '' + Settings to be written to the Cava configuration file. See + for + all available options. + ''; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ cfg.package ]; + + xdg.configFile."cava/config" = mkIf (cfg.settings != { }) { + text = '' + ; Generated by Home Manager + + ${generators.toINI { } cfg.settings} + ''; + }; + }; +} diff --git a/tests/default.nix b/tests/default.nix index 50c404787b28..704ce793b0f5 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -70,6 +70,7 @@ import nmt { ./modules/programs/browserpass ./modules/programs/btop ./modules/programs/carapace + ./modules/programs/cava ./modules/programs/comodoro ./modules/programs/darcs ./modules/programs/dircolors diff --git a/tests/modules/programs/cava/cava-basic-configuration-expected.ini b/tests/modules/programs/cava/cava-basic-configuration-expected.ini new file mode 100644 index 000000000000..124f7ab36fa6 --- /dev/null +++ b/tests/modules/programs/cava/cava-basic-configuration-expected.ini @@ -0,0 +1,15 @@ +; Generated by Home Manager + +[color] +background='#000000' +foreground='#ffffff' + +[general] +framerate=30 + +[input] +source=alsa + +[smoothing] +noise_reduction=65 + diff --git a/tests/modules/programs/cava/cava-basic-configuration.nix b/tests/modules/programs/cava/cava-basic-configuration.nix new file mode 100644 index 000000000000..98936d839368 --- /dev/null +++ b/tests/modules/programs/cava/cava-basic-configuration.nix @@ -0,0 +1,25 @@ +{ config, pkgs, ... }: + +{ + programs.cava = { + enable = true; + + package = config.lib.test.mkStubPackage { }; + + settings = { + general.framerate = 30; + input.source = "alsa"; + smoothing.noise_reduction = 65; + color = { + background = "'#000000'"; + foreground = "'#ffffff'"; + }; + }; + }; + + nmt.script = '' + configFile=home-files/.config/cava/config + assertFileExists $configFile + assertFileContent $configFile ${./cava-basic-configuration-expected.ini} + ''; +} diff --git a/tests/modules/programs/cava/default.nix b/tests/modules/programs/cava/default.nix new file mode 100644 index 000000000000..90f5c2e78db1 --- /dev/null +++ b/tests/modules/programs/cava/default.nix @@ -0,0 +1 @@ +{ cava-basic-configuration = ./cava-basic-configuration.nix; }