From f47b6c153ad31187a519bd569ccbcb20acb16ce0 Mon Sep 17 00:00:00 2001 From: bricked Date: Wed, 18 Dec 2024 16:42:28 +0100 Subject: [PATCH] cavalier: add module --- modules/misc/news.nix | 10 ++ modules/modules.nix | 1 + modules/programs/cavalier.nix | 102 ++++++++++++++++++ tests/default.nix | 1 + .../cavalier-cava-settings-expected.ini | 21 ++++ .../cavalier/cavalier-cava-settings.nix | 35 ++++++ .../cavalier-general-settings-expected.json | 1 + .../cavalier/cavalier-general-settings.nix | 59 ++++++++++ tests/modules/programs/cavalier/default.nix | 4 + 9 files changed, 234 insertions(+) create mode 100644 modules/programs/cavalier.nix create mode 100644 tests/modules/programs/cavalier/cavalier-cava-settings-expected.ini create mode 100644 tests/modules/programs/cavalier/cavalier-cava-settings.nix create mode 100644 tests/modules/programs/cavalier/cavalier-general-settings-expected.json create mode 100644 tests/modules/programs/cavalier/cavalier-general-settings.nix create mode 100644 tests/modules/programs/cavalier/default.nix diff --git a/modules/misc/news.nix b/modules/misc/news.nix index f2f62dd82..d09176e54 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1909,6 +1909,16 @@ in { and thefuck replacement written in Rust. ''; } + + { + time = "2024-12-22T08:24:29+00:00"; + condition = hostPlatform.isLinux; + message = '' + A new module is available: 'programs.cavalier'. + + Cavalier is a GUI wrapper around the Cava audio visualizer. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index ba85135de..d7f139333 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -77,6 +77,7 @@ let ./programs/bun.nix ./programs/carapace.nix ./programs/cava.nix + ./programs/cavalier.nix ./programs/chromium.nix ./programs/cmus.nix ./programs/command-not-found/command-not-found.nix diff --git a/modules/programs/cavalier.nix b/modules/programs/cavalier.nix new file mode 100644 index 000000000..0b57cf8e2 --- /dev/null +++ b/modules/programs/cavalier.nix @@ -0,0 +1,102 @@ +{ pkgs, config, lib, ... }: + +with lib; + +let + + cfg = config.programs.cavalier; + + iniFmt = pkgs.formats.ini { }; + + jsonFmt = pkgs.formats.json { }; + +in { + meta.maintainers = [ hm.maintainers.bricked ]; + + options.programs.cavalier = { + enable = mkEnableOption "Cava audio visualizer GUI"; + + package = mkPackageOption pkgs "cavalier" { }; + + settings = { + general = mkOption { + type = jsonFmt.type; + default = { }; + example = literalExpression '' + { + ShowControls = true; + ColorProfiles = [ + { + Name = "Default"; + FgColors = [ + "#ffed333b" + "#ffffa348" + "#fff8e45c" + "#ff57e389" + "#ff62a0ea" + "#ffc061cb" + ]; + BgColors = [ + "#ff1e1e2e" + ]; + Theme = 1; + } + ]; + ActiveProfile = 0; + } + ''; + description = '' + Settings to be written to the Cavalier configuration file. See + + for all available options. + ''; + }; + + cava = 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 underlying Cava configuration file. See + for + all available options. + ''; + }; + }; + }; + + config = mkIf cfg.enable { + assertions = [ + (lib.hm.assertions.assertPlatform "programs.cavalier" pkgs + lib.platforms.linux) + ]; + + home.packages = [ cfg.package ]; + + xdg.configFile = { + "Nickvision Cavalier/config.json" = mkIf (cfg.settings.general != { }) { + text = '' + ${generators.toJSON { } cfg.settings.general} + ''; + }; + + "Nickvision Cavalier/cava_config" = mkIf (cfg.settings.cava != { }) { + text = '' + ; Generated by Home Manager + + ${generators.toINI { } cfg.settings.cava} + ''; + }; + }; + }; +} diff --git a/tests/default.nix b/tests/default.nix index 1acdc43dd..f7a1b283f 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -199,6 +199,7 @@ in import nmtSrc { ./modules/programs/beets # One test relies on services.mpd ./modules/programs/bemenu ./modules/programs/boxxy + ./modules/programs/cavalier ./modules/programs/firefox/firefox.nix ./modules/programs/firefox/floorp.nix ./modules/programs/foot diff --git a/tests/modules/programs/cavalier/cavalier-cava-settings-expected.ini b/tests/modules/programs/cavalier/cavalier-cava-settings-expected.ini new file mode 100644 index 000000000..609629d6f --- /dev/null +++ b/tests/modules/programs/cavalier/cavalier-cava-settings-expected.ini @@ -0,0 +1,21 @@ +; Generated by Home Manager + +[general] +autosens=1 +bars=12 +framerate=60 +sensitivity=100 + +[input] +method=pulse + +[output] +bit_format=16bit +channels=stereo +method=raw +raw_target=/dev/stdout + +[smoothing] +monstercat=1 +noise_reduction=77 + diff --git a/tests/modules/programs/cavalier/cavalier-cava-settings.nix b/tests/modules/programs/cavalier/cavalier-cava-settings.nix new file mode 100644 index 000000000..0d64b84a5 --- /dev/null +++ b/tests/modules/programs/cavalier/cavalier-cava-settings.nix @@ -0,0 +1,35 @@ +{ config, pkgs, ... }: + +{ + programs.cavalier = { + enable = true; + + package = config.lib.test.mkStubPackage { }; + + settings.cava = { + general = { + framerate = 60; + bars = 12; + autosens = 1; + sensitivity = 100; + }; + input = { method = "pulse"; }; + output = { + method = "raw"; + raw_target = "/dev/stdout"; + bit_format = "16bit"; + channels = "stereo"; + }; + smoothing = { + monstercat = 1; + noise_reduction = 77; + }; + }; + }; + + nmt.script = '' + configFile="home-files/.config/Nickvision Cavalier/cava_config" + assertFileExists "$configFile" + assertFileContent "$configFile" ${./cavalier-cava-settings-expected.ini} + ''; +} diff --git a/tests/modules/programs/cavalier/cavalier-general-settings-expected.json b/tests/modules/programs/cavalier/cavalier-general-settings-expected.json new file mode 100644 index 000000000..c05f3b049 --- /dev/null +++ b/tests/modules/programs/cavalier/cavalier-general-settings-expected.json @@ -0,0 +1 @@ +{"ActiveProfile":0,"AreaMargin":0,"AreaOffsetX":0,"AreaOffsetY":0,"AutohideHeader":false,"Autosens":true,"BarPairs":6,"BgImageAlpha":1,"BgImageIndex":-1,"BgImageScale":1,"Borderless":false,"ColorProfiles":[{"BgColors":["#ff242424"],"FgColors":["#ff3584e4"],"Name":"Default","Theme":1}],"Direction":1,"FgImageAlpha":1,"FgImageIndex":-1,"FgImageScale":1,"Filling":true,"Framerate":60,"InnerRadius":0.5,"ItemsOffset":0.1,"ItemsRoundness":0.5,"LinesThickness":5,"Mirror":0,"Mode":0,"Monstercat":true,"NoiseReduction":0.77,"ReverseMirror":false,"ReverseOrder":true,"Rotation":0,"Sensitivity":10,"SharpCorners":false,"ShowControls":false,"Stereo":true,"WindowHeight":521,"WindowMaximized":false,"WindowWidth":1908} diff --git a/tests/modules/programs/cavalier/cavalier-general-settings.nix b/tests/modules/programs/cavalier/cavalier-general-settings.nix new file mode 100644 index 000000000..24dcc5dfe --- /dev/null +++ b/tests/modules/programs/cavalier/cavalier-general-settings.nix @@ -0,0 +1,59 @@ +{ config, pkgs, ... }: + +{ + programs.cavalier = { + enable = true; + + package = config.lib.test.mkStubPackage { }; + + settings.general = { + WindowWidth = 1908; + WindowHeight = 521; + WindowMaximized = false; + AreaMargin = 0; + AreaOffsetX = 0; + AreaOffsetY = 0; + Borderless = false; + SharpCorners = false; + ShowControls = false; + AutohideHeader = false; + Framerate = 60; + BarPairs = 6; + Autosens = true; + Sensitivity = 10; + Stereo = true; + Monstercat = true; + NoiseReduction = 0.77; + ReverseOrder = true; + Direction = 1; + ItemsOffset = 0.1; + ItemsRoundness = 0.5; + Filling = true; + LinesThickness = 5; + Mode = 0; + Mirror = 0; + ReverseMirror = false; + InnerRadius = 0.5; + Rotation = 0; + ColorProfiles = [{ + Name = "Default"; + FgColors = [ "#ff3584e4" ]; + BgColors = [ "#ff242424" ]; + Theme = 1; + }]; + ActiveProfile = 0; + BgImageIndex = -1; + BgImageScale = 1; + BgImageAlpha = 1; + FgImageIndex = -1; + FgImageScale = 1; + FgImageAlpha = 1; + }; + }; + + nmt.script = '' + configFile="home-files/.config/Nickvision Cavalier/config.json" + assertFileExists "$configFile" + assertFileContent "$configFile" ${./cavalier-general-settings-expected.json} + ''; +} diff --git a/tests/modules/programs/cavalier/default.nix b/tests/modules/programs/cavalier/default.nix new file mode 100644 index 000000000..6f488f2fc --- /dev/null +++ b/tests/modules/programs/cavalier/default.nix @@ -0,0 +1,4 @@ +{ + cavalier-general-settings = ./cavalier-general-settings.nix; + cavalier-cava-settings = ./cavalier-cava-settings.nix; +}