From 6045b68ee725167ed0487f0fb88123202ba61923 Mon Sep 17 00:00:00 2001 From: Luna Simons Date: Fri, 16 Jun 2023 21:38:29 +0200 Subject: [PATCH] cava: add module --- modules/misc/news.nix | 7 +++ modules/modules.nix | 1 + modules/programs/cava.nix | 52 +++++++++++++++++++ tests/default.nix | 1 + .../cava-basic-configuration-expected.ini | 15 ++++++ .../cava/cava-basic-configuration.nix | 25 +++++++++ tests/modules/programs/cava/default.nix | 1 + 7 files changed, 102 insertions(+) create mode 100644 modules/programs/cava.nix create mode 100644 tests/modules/programs/cava/cava-basic-configuration-expected.ini create mode 100644 tests/modules/programs/cava/cava-basic-configuration.nix create mode 100644 tests/modules/programs/cava/default.nix diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 524bded3..6a494739 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 c9822486..2e9d237b 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 00000000..63173248 --- /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 50c40478..704ce793 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 00000000..124f7ab3 --- /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 00000000..98936d83 --- /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 00000000..90f5c2e7 --- /dev/null +++ b/tests/modules/programs/cava/default.nix @@ -0,0 +1 @@ +{ cava-basic-configuration = ./cava-basic-configuration.nix; }