diff --git a/modules/programs/radio-cli.nix b/modules/programs/radio-cli.nix new file mode 100644 index 000000000..f290daa55 --- /dev/null +++ b/modules/programs/radio-cli.nix @@ -0,0 +1,51 @@ +{ + lib, + pkgs, + config, + ... +}: +let + inherit (lib) + mkIf + mkEnableOption + mkPackageOption + mkOption + ; + + cfg = config.programs.radio-cli; + jsonFormat = pkgs.formats.json { }; +in +{ + meta.maintainers = with lib.hm.maintainers; [ aguirre-matteo ]; + + options.programs.radio-cli = { + enable = mkEnableOption "radio-cli"; + package = mkPackageOption pkgs "radio-cli" { nullable = true; }; + settings = mkOption { + type = jsonFormat.type; + default = { }; + example = { + config_version = "2.3.0"; + max_lines = 7; + country = "ES"; + data = [ + { + station = "lofi"; + url = "https://www.youtube.com/live/jfKfPfyJRdk?si=WDl-XdfuhxBfe6XN"; + } + ]; + }; + description = '' + Configuration settings for radio-cli. For an example config, + refer to: + ''; + }; + }; + + config = mkIf cfg.enable { + home.packages = mkIf (cfg.package != null) [ cfg.package ]; + xdg.configFile."radio-cli/config.json" = mkIf (cfg.settings != { }) { + source = jsonFormat.generate "radio-cli-config" cfg.settings; + }; + }; +} diff --git a/tests/modules/programs/radio-cli/config.json b/tests/modules/programs/radio-cli/config.json new file mode 100644 index 000000000..95909ecd2 --- /dev/null +++ b/tests/modules/programs/radio-cli/config.json @@ -0,0 +1,11 @@ +{ + "config_version": "2.3.0", + "country": "ES", + "data": [ + { + "station": "lofi", + "url": "https://www.youtube.com/live/jfKfPfyJRdk?si=WDl-XdfuhxBfe6XN" + } + ], + "max_lines": 7 +} diff --git a/tests/modules/programs/radio-cli/default.nix b/tests/modules/programs/radio-cli/default.nix new file mode 100644 index 000000000..5179407ba --- /dev/null +++ b/tests/modules/programs/radio-cli/default.nix @@ -0,0 +1 @@ +{ radio-cli-example = ./example-config.nix; } diff --git a/tests/modules/programs/radio-cli/example-config.nix b/tests/modules/programs/radio-cli/example-config.nix new file mode 100644 index 000000000..75af22990 --- /dev/null +++ b/tests/modules/programs/radio-cli/example-config.nix @@ -0,0 +1,22 @@ +{ + programs.radio-cli = { + enable = true; + settings = { + config_version = "2.3.0"; + max_lines = 7; + country = "ES"; + data = [ + { + station = "lofi"; + url = "https://www.youtube.com/live/jfKfPfyJRdk?si=WDl-XdfuhxBfe6XN"; + } + ]; + }; + }; + + nmt.script = '' + assertFileExists home-files/.config/radio-cli/config.json + assertFileContent home-files/.config/radio-cli/config.json \ + ${./config.json} + ''; +}