From 6bbfe2d6973fb16137d3ef5e322b4591c22948b1 Mon Sep 17 00:00:00 2001 From: Aguirre Matteo Date: Thu, 2 Oct 2025 12:54:38 -0300 Subject: [PATCH] alistral: add module --- modules/programs/alistral.nix | 52 ++++++++++++++++++++ tests/modules/programs/alistral/config.json | 5 ++ tests/modules/programs/alistral/default.nix | 1 + tests/modules/programs/alistral/settings.nix | 26 ++++++++++ 4 files changed, 84 insertions(+) create mode 100644 modules/programs/alistral.nix create mode 100644 tests/modules/programs/alistral/config.json create mode 100644 tests/modules/programs/alistral/default.nix create mode 100644 tests/modules/programs/alistral/settings.nix diff --git a/modules/programs/alistral.nix b/modules/programs/alistral.nix new file mode 100644 index 000000000..3c8be5138 --- /dev/null +++ b/modules/programs/alistral.nix @@ -0,0 +1,52 @@ +{ + lib, + pkgs, + config, + ... +}: +let + inherit (lib) + mkIf + mkEnableOption + mkPackageOption + mkOption + ; + + cfg = config.programs.alistral; + jsonFormat = pkgs.formats.json { }; +in +{ + meta.maintainers = with lib.hm.maintainers; [ aguirre-matteo ]; + options.programs.alistral = { + enable = mkEnableOption "alistral"; + package = mkPackageOption pkgs "alistral" { nullable = true; }; + settings = mkOption { + inherit (jsonFormat) type; + default = { }; + example = { + default_user = "spanish_inquisition"; + listenbrainz_url = "https://api.listenbrainz.org/1/"; + musicbrainz_url = "http://musicbrainz.org/ws/2"; + }; + description = '' + Configuration settings for alistral. You can see the details here: + . + ''; + }; + }; + + config = + let + configDir = + if pkgs.stdenv.hostPlatform.isDarwin then + "Library/Application Support/alistral" + else + ".config/alistral"; + in + mkIf cfg.enable { + home.packages = mkIf (cfg.package != null) [ cfg.package ]; + home.file."${configDir}/config.json" = mkIf (cfg.settings != { }) { + source = jsonFormat.generate "alistral-config.json" cfg.settings; + }; + }; +} diff --git a/tests/modules/programs/alistral/config.json b/tests/modules/programs/alistral/config.json new file mode 100644 index 000000000..7343dcfcb --- /dev/null +++ b/tests/modules/programs/alistral/config.json @@ -0,0 +1,5 @@ +{ + "default_user": "spanish_inquisition", + "listenbrainz_url": "https://api.listenbrainz.org/1/", + "musicbrainz_url": "http://musicbrainz.org/ws/2" +} diff --git a/tests/modules/programs/alistral/default.nix b/tests/modules/programs/alistral/default.nix new file mode 100644 index 000000000..f41b51393 --- /dev/null +++ b/tests/modules/programs/alistral/default.nix @@ -0,0 +1 @@ +{ alistral-settings = ./settings.nix; } diff --git a/tests/modules/programs/alistral/settings.nix b/tests/modules/programs/alistral/settings.nix new file mode 100644 index 000000000..b9f592e5b --- /dev/null +++ b/tests/modules/programs/alistral/settings.nix @@ -0,0 +1,26 @@ +{ pkgs, ... }: + +{ + programs.alistral = { + enable = true; + settings = { + default_user = "spanish_inquisition"; + listenbrainz_url = "https://api.listenbrainz.org/1/"; + musicbrainz_url = "http://musicbrainz.org/ws/2"; + }; + }; + + nmt.script = + let + configDir = + if pkgs.stdenv.hostPlatform.isDarwin then + "Library/Application Support/alistral" + else + ".config/alistral"; + in + '' + assertFileExists "home-files/${configDir}/config.json" + assertFileContent "home-files/${configDir}/config.json" \ + ${./config.json} + ''; +}