From 1e36429705f9af2d00a517ba46a4f21ef8a8194f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Prudent?= <jprudent@gmail.com>
Date: Sat, 18 Jan 2025 09:22:15 +0100
Subject: [PATCH] sbt: allow irregular plugins to be configured

Sometimes plugins doesn't follow the form

```
addSbtPlugin("${plugin.org}" % "${plugin.artifact}" % "${plugin.version}")
```

for instance

```
addDependencyTreePlugin
```

This commit allow free form plugin dependency.
---
 modules/programs/sbt.nix               | 19 +++++++++++++++++--
 tests/modules/programs/sbt/plugins.nix |  3 +++
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/modules/programs/sbt.nix b/modules/programs/sbt.nix
index de14bc6f3..622768298 100644
--- a/modules/programs/sbt.nix
+++ b/modules/programs/sbt.nix
@@ -130,6 +130,20 @@ in {
       '';
     };
 
+    pluginsExtra = mkOption {
+      type = types.listOf (types.str);
+      default = [ ];
+      example = literalExpression ''
+        [
+          "addDependencyTreePlugin"
+        ]
+      '';
+      description = ''
+        A list of extra commands to put in plugins conf file.
+        Use it in last resort when you can't use the `plugins` option.
+      '';
+    };
+
     credentials = mkOption {
       type = types.listOf (sbtTypes.credential);
       default = [ ];
@@ -183,9 +197,10 @@ in {
   config = mkIf cfg.enable (mkMerge [
     { home.packages = [ cfg.package ]; }
 
-    (mkIf (cfg.plugins != [ ]) {
+    (mkIf (cfg.plugins != [ ] || cfg.pluginsExtra != [ ]) {
       home.file."${cfg.baseUserConfigPath}/1.0/plugins/plugins.sbt".text =
-        concatStrings (map renderPlugin cfg.plugins);
+        concatStrings (map renderPlugin cfg.plugins)
+        + concatStringsSep "\n" cfg.pluginsExtra + "\n";
     })
 
     (mkIf (cfg.credentials != [ ]) {
diff --git a/tests/modules/programs/sbt/plugins.nix b/tests/modules/programs/sbt/plugins.nix
index b413de80e..c898ad465 100644
--- a/tests/modules/programs/sbt/plugins.nix
+++ b/tests/modules/programs/sbt/plugins.nix
@@ -15,12 +15,14 @@ let
   };
 
   plugins = [ dependencyGraph projectGraph ];
+  pluginsExtra = [ "addDependencyTreePlugin" ];
 
   pluginsSbtPath = ".sbt/1.0/plugins/plugins.sbt";
 
   expectedPluginsSbt = pkgs.writeText "plugins.sbt" ''
     addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.10.0-RC1")
     addSbtPlugin("com.dwijnand" % "sbt-project-graph" % "0.4.0")
+    addDependencyTreePlugin
   '';
 
 in {
@@ -28,6 +30,7 @@ in {
     programs.sbt = {
       enable = true;
       plugins = plugins;
+      pluginsExtra = pluginsExtra;
       package = pkgs.writeScriptBin "sbt" "";
     };