2021-01-30 03:29:23 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
renderPlugin = plugin: ''
|
|
|
|
addSbtPlugin("${plugin.org}" % "${plugin.artifact}" % "${plugin.version}")
|
|
|
|
'';
|
|
|
|
|
2022-10-03 03:26:14 +02:00
|
|
|
renderCredential = idx: cred:
|
|
|
|
let symbol = "credential_${toString idx}";
|
|
|
|
in ''
|
|
|
|
lazy val ${symbol} = "${cred.passwordCommand}".!!.trim
|
|
|
|
credentials += Credentials("${cred.realm}", "${cred.host}", "${cred.user}", ${symbol})
|
|
|
|
'';
|
2021-01-30 03:29:23 +01:00
|
|
|
|
|
|
|
renderCredentials = creds: ''
|
|
|
|
import scala.sys.process._
|
2022-10-03 03:26:14 +02:00
|
|
|
${concatStrings (imap0 renderCredential creds)}'';
|
2021-01-30 03:29:23 +01:00
|
|
|
|
2022-10-03 04:52:33 +02:00
|
|
|
renderRepository = value:
|
|
|
|
if isString value then ''
|
|
|
|
${value}
|
|
|
|
'' else ''
|
|
|
|
${concatStrings (mapAttrsToList (name: value: "${name}: ${value}") value)}
|
|
|
|
'';
|
|
|
|
|
|
|
|
renderRepositories = repos: ''
|
|
|
|
[repositories]
|
|
|
|
${concatStrings (map renderRepository cfg.repositories)}'';
|
|
|
|
|
2021-01-30 03:29:23 +01:00
|
|
|
sbtTypes = {
|
|
|
|
plugin = types.submodule {
|
|
|
|
options = {
|
|
|
|
org = mkOption {
|
|
|
|
type = types.str;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "The organization the artifact is published under.";
|
2021-01-30 03:29:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
artifact = mkOption {
|
|
|
|
type = types.str;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "The name of the artifact.";
|
2021-01-30 03:29:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
version = mkOption {
|
|
|
|
type = types.str;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "The version of the plugin.";
|
2021-01-30 03:29:23 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
credential = types.submodule {
|
|
|
|
options = {
|
|
|
|
realm = mkOption {
|
|
|
|
type = types.str;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "The realm of the repository you're authenticating to.";
|
2021-01-30 03:29:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
host = mkOption {
|
|
|
|
type = types.str;
|
2023-07-02 01:45:18 +02:00
|
|
|
description =
|
2021-01-30 03:29:23 +01:00
|
|
|
"The hostname of the repository you're authenticating to.";
|
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "The user you're using to authenticate.";
|
2021-01-30 03:29:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
passwordCommand = mkOption {
|
|
|
|
type = types.str;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2021-01-30 03:29:23 +01:00
|
|
|
The command that provides the password or authentication token for
|
|
|
|
the repository.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
cfg = config.programs.sbt;
|
|
|
|
|
|
|
|
in {
|
2022-10-03 04:52:33 +02:00
|
|
|
imports = [
|
|
|
|
(mkRemovedOptionModule [ "programs" "sbt" "baseConfigPath" ]
|
|
|
|
"Use programs.sbt.baseUserConfigPath instead, but note that the semantics are slightly different.")
|
|
|
|
];
|
|
|
|
|
2021-01-30 03:29:23 +01:00
|
|
|
meta.maintainers = [ maintainers.kubukoz ];
|
|
|
|
|
|
|
|
options.programs.sbt = {
|
2023-07-02 01:45:18 +02:00
|
|
|
enable = mkEnableOption "sbt";
|
2021-01-30 03:29:23 +01:00
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.sbt;
|
2021-10-09 11:14:08 +02:00
|
|
|
defaultText = literalExpression "pkgs.sbt";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "The package with sbt to be installed.";
|
2021-01-30 03:29:23 +01:00
|
|
|
};
|
|
|
|
|
2022-10-03 04:52:33 +02:00
|
|
|
baseUserConfigPath = mkOption {
|
2021-01-30 03:29:23 +01:00
|
|
|
type = types.str;
|
2022-10-03 04:52:33 +02:00
|
|
|
default = ".sbt";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2022-10-03 04:52:33 +02:00
|
|
|
Where the sbt configuration files should be located, relative
|
2023-07-01 01:30:13 +02:00
|
|
|
{env}`HOME`.
|
2022-10-03 04:52:33 +02:00
|
|
|
'';
|
2021-01-30 03:29:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
plugins = mkOption {
|
|
|
|
type = types.listOf (sbtTypes.plugin);
|
|
|
|
default = [ ];
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2021-01-30 03:29:23 +01:00
|
|
|
[
|
|
|
|
{
|
|
|
|
org = "net.virtual-void";
|
|
|
|
artifact = "sbt-dependency-graph";
|
|
|
|
version = "0.10.0-RC1";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
org = "com.dwijnand";
|
|
|
|
artifact = "sbt-project-graph";
|
|
|
|
version = "0.4.0";
|
|
|
|
}
|
|
|
|
]
|
|
|
|
'';
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2021-01-30 03:29:23 +01:00
|
|
|
A list of plugins to place in the sbt configuration directory.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
credentials = mkOption {
|
|
|
|
type = types.listOf (sbtTypes.credential);
|
|
|
|
default = [ ];
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2021-01-30 03:29:23 +01:00
|
|
|
[{
|
|
|
|
realm = "Sonatype Nexus Repository Manager";
|
|
|
|
host = "example.com";
|
|
|
|
user = "user";
|
|
|
|
passwordCommand = "pass show sbt/user@example.com";
|
|
|
|
}]
|
|
|
|
'';
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2021-01-30 03:29:23 +01:00
|
|
|
A list of credentials to define in the sbt configuration directory.
|
|
|
|
'';
|
|
|
|
};
|
2022-10-03 04:52:33 +02:00
|
|
|
|
|
|
|
repositories = mkOption {
|
|
|
|
type = with types;
|
|
|
|
listOf
|
|
|
|
(either (enum [ "local" "maven-central" "maven-local" ]) (attrsOf str));
|
|
|
|
default = [ ];
|
|
|
|
example = literalExpression ''
|
|
|
|
[
|
|
|
|
"local"
|
|
|
|
{ my-ivy-proxy-releases = "http://repo.company.com/ivy-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]" }
|
|
|
|
{ my-maven-proxy-releases = "http://repo.company.com/maven-releases/" }
|
|
|
|
"maven-central"
|
|
|
|
]
|
|
|
|
'';
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2022-10-03 04:52:33 +02:00
|
|
|
A list of repositories to use when resolving dependencies. Defined as a
|
|
|
|
list of pre-defined repository or custom repository as a set of name to
|
2023-07-01 01:30:13 +02:00
|
|
|
URL. The list will be used populate the `~/.sbt/repositories`
|
2022-10-03 04:52:33 +02:00
|
|
|
file in the order specified.
|
|
|
|
|
2023-07-01 01:30:13 +02:00
|
|
|
Pre-defined repositories must be one of `local`,
|
|
|
|
`maven-local`, `maven-central`.
|
2022-10-03 04:52:33 +02:00
|
|
|
|
|
|
|
Custom repositories are defined as
|
2023-07-01 01:30:13 +02:00
|
|
|
`{ name-of-repo = "https://url.to.repo.com"}`.
|
2022-10-03 04:52:33 +02:00
|
|
|
|
|
|
|
See
|
2023-07-01 01:30:13 +02:00
|
|
|
<https://www.scala-sbt.org/1.x/docs/Launcher-Configuration.html#3.+Repositories+Section>
|
2022-10-03 04:52:33 +02:00
|
|
|
about this configuration section and
|
2023-07-01 01:30:13 +02:00
|
|
|
<https://www.scala-sbt.org/1.x/docs/Proxy-Repositories.html>
|
2022-10-03 04:52:33 +02:00
|
|
|
to read about proxy repositories.
|
|
|
|
'';
|
|
|
|
};
|
2021-01-30 03:29:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable (mkMerge [
|
|
|
|
{ home.packages = [ cfg.package ]; }
|
|
|
|
|
|
|
|
(mkIf (cfg.plugins != [ ]) {
|
2022-10-03 04:52:33 +02:00
|
|
|
home.file."${cfg.baseUserConfigPath}/1.0/plugins/plugins.sbt".text =
|
2021-01-30 03:29:23 +01:00
|
|
|
concatStrings (map renderPlugin cfg.plugins);
|
|
|
|
})
|
|
|
|
|
|
|
|
(mkIf (cfg.credentials != [ ]) {
|
2022-10-03 04:52:33 +02:00
|
|
|
home.file."${cfg.baseUserConfigPath}/1.0/credentials.sbt".text =
|
2021-01-30 03:29:23 +01:00
|
|
|
renderCredentials cfg.credentials;
|
|
|
|
})
|
2022-10-03 04:52:33 +02:00
|
|
|
|
|
|
|
(mkIf (cfg.repositories != [ ]) {
|
|
|
|
home.file."${cfg.baseUserConfigPath}/repositories".text =
|
|
|
|
renderRepositories cfg.repositories;
|
|
|
|
})
|
2021-01-30 03:29:23 +01:00
|
|
|
]);
|
|
|
|
}
|