sbt: add new module

This commit is contained in:
Jakub Kozłowski 2021-01-30 03:29:23 +01:00 committed by Robert Helgesson
parent 22ecd0e568
commit 63d5d28db6
No known key found for this signature in database
GPG Key ID: 36BDAA14C2797E89
9 changed files with 241 additions and 0 deletions

3
.github/CODEOWNERS vendored
View File

@ -133,6 +133,9 @@
/modules/programs/rtorrent.nix @marsam
/modules/programs/sbt.nix @kubukoz
/tests/modules/programs/sbt @kubukoz
/modules/programs/ssh.nix @rycee
/modules/programs/starship.nix @marsam

View File

@ -31,6 +31,12 @@
github = "olmokramer";
githubId = 3612514;
};
kubukoz = {
name = "Jakub Kozłowski";
email = "kubukoz@users.noreply.github.com";
github = "kubukoz";
githubId = 894884;
};
matrss = {
name = "Matthias Riße";
email = "matrss@users.noreply.github.com";

View File

@ -1845,6 +1845,13 @@ in
macOS.
'';
}
{
time = "2021-02-04T22:28:26+00:00";
message = ''
A new module is available: 'programs.sbt'.
'';
}
];
};
}

View File

@ -119,6 +119,7 @@ let
(loadModule ./programs/rtorrent.nix { })
(loadModule ./programs/skim.nix { })
(loadModule ./programs/starship.nix { })
(loadModule ./programs/sbt.nix { })
(loadModule ./programs/ssh.nix { })
(loadModule ./programs/taskwarrior.nix { })
(loadModule ./programs/termite.nix { })

141
modules/programs/sbt.nix Normal file
View File

@ -0,0 +1,141 @@
{ config, lib, pkgs, ... }:
with lib;
let
renderPlugin = plugin: ''
addSbtPlugin("${plugin.org}" % "${plugin.artifact}" % "${plugin.version}")
'';
renderCredential = cred: ''
credentials += Credentials("${cred.realm}", "${cred.host}", "${cred.user}", "${cred.passwordCommand}".!!)
'';
renderCredentials = creds: ''
import scala.sys.process._
${concatStrings (map renderCredential creds)}'';
sbtTypes = {
plugin = types.submodule {
options = {
org = mkOption {
type = types.str;
description = "The organization the artifact is published under.";
};
artifact = mkOption {
type = types.str;
description = "The name of the artifact.";
};
version = mkOption {
type = types.str;
description = "The version of the plugin.";
};
};
};
credential = types.submodule {
options = {
realm = mkOption {
type = types.str;
description = "The realm of the repository you're authenticating to.";
};
host = mkOption {
type = types.str;
description =
"The hostname of the repository you're authenticating to.";
};
user = mkOption {
type = types.str;
description = "The user you're using to authenticate.";
};
passwordCommand = mkOption {
type = types.str;
description = ''
The command that provides the password or authentication token for
the repository.
'';
};
};
};
};
cfg = config.programs.sbt;
in {
meta.maintainers = [ maintainers.kubukoz ];
options.programs.sbt = {
enable = mkEnableOption "sbt";
package = mkOption {
type = types.package;
default = pkgs.sbt;
defaultText = literalExample "pkgs.sbt";
description = "The package with sbt to be installed.";
};
baseConfigPath = mkOption {
type = types.str;
default = ".sbt/1.0";
description = "Where the plugins and credentials should be located.";
};
plugins = mkOption {
type = types.listOf (sbtTypes.plugin);
default = [ ];
example = literalExample ''
[
{
org = "net.virtual-void";
artifact = "sbt-dependency-graph";
version = "0.10.0-RC1";
}
{
org = "com.dwijnand";
artifact = "sbt-project-graph";
version = "0.4.0";
}
]
'';
description = ''
A list of plugins to place in the sbt configuration directory.
'';
};
credentials = mkOption {
type = types.listOf (sbtTypes.credential);
default = [ ];
example = literalExample ''
[{
realm = "Sonatype Nexus Repository Manager";
host = "example.com";
user = "user";
passwordCommand = "pass show sbt/user@example.com";
}]
'';
description = ''
A list of credentials to define in the sbt configuration directory.
'';
};
};
config = mkIf cfg.enable (mkMerge [
{ home.packages = [ cfg.package ]; }
(mkIf (cfg.plugins != [ ]) {
home.file."${cfg.baseConfigPath}/plugins/plugins.sbt".text =
concatStrings (map renderPlugin cfg.plugins);
})
(mkIf (cfg.credentials != [ ]) {
home.file."${cfg.baseConfigPath}/credentials.sbt".text =
renderCredentials cfg.credentials;
})
]);
}

View File

@ -68,6 +68,7 @@ import nmt {
./modules/programs/powerline-go
./modules/programs/qutebrowser
./modules/programs/readline
./modules/programs/sbt
./modules/programs/ssh
./modules/programs/starship
./modules/programs/texlive

View File

@ -0,0 +1,39 @@
{ config, lib, pkgs, ... }:
with lib;
let
credentials = [
{
realm = "Sonatype Nexus Repository Manager";
host = "example.com";
user = "user";
passwordCommand = "echo password";
}
{
realm = "Sonatype Nexus Repository Manager X";
host = "v2.example.com";
user = "user1";
passwordCommand = "echo password1";
}
];
expectedCredentialsSbt = pkgs.writeText "credentials.sbt" ''
import scala.sys.process._
credentials += Credentials("Sonatype Nexus Repository Manager", "example.com", "user", "echo password".!!)
credentials += Credentials("Sonatype Nexus Repository Manager X", "v2.example.com", "user1", "echo password1".!!)
'';
credentialsSbtPath = ".sbt/1.0/credentials.sbt";
in {
config = {
programs.sbt = {
enable = true;
credentials = credentials;
package = pkgs.writeScriptBin "sbt" "";
};
nmt.script = ''
assertFileExists "home-files/${credentialsSbtPath}"
assertFileContent "home-files/${credentialsSbtPath}" "${expectedCredentialsSbt}"
'';
};
}

View File

@ -0,0 +1,4 @@
{
sbt-plugins = ./plugins.nix;
sbt-credentials = ./credentials.nix;
}

View File

@ -0,0 +1,39 @@
{ config, lib, pkgs, ... }:
with lib;
let
dependencyGraph = {
org = "net.virtual-void";
artifact = "sbt-dependency-graph";
version = "0.10.0-RC1";
};
projectGraph = {
org = "com.dwijnand";
artifact = "sbt-project-graph";
version = "0.4.0";
};
plugins = [ dependencyGraph projectGraph ];
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")
'';
in {
config = {
programs.sbt = {
enable = true;
plugins = plugins;
package = pkgs.writeScriptBin "sbt" "";
};
nmt.script = ''
assertFileExists "home-files/${pluginsSbtPath}"
assertFileContent "home-files/${pluginsSbtPath}" "${expectedPluginsSbt}"
'';
};
}