fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7renderPlugin = plugin :'' 8addSbtPlugin(" ${ plugin . org } " % " ${ plugin . artifact } " % " ${ plugin . version } ") 9'' ; 10 11renderCredential = idx :cred : 12let symbol = "credential_ ${ toString idx } " ; 13in '' 14lazy val ${ symbol } = " ${ cred . passwordCommand } ".!!.trim 15credentials += Credentials(" ${ cred . realm } ", " ${ cred . host } ", " ${ cred . user } ", ${ symbol } ) 16'' ; 17 18renderCredentials = creds :'' 19import scala.sys.process._ 20${ concatStrings ( imap0 renderCredential creds )} '' ; 21 22renderRepository = value : 23if isString value then '' 24${ value } 25'' else '' 26${ concatStrings ( mapAttrsToList ( name : value : " ${ name } : ${ value } " ) value )} 27'' ; 28 29renderRepositories = repos :'' 30[repositories] 31${ concatStrings ( map renderRepository cfg . repositories )} '' ; 32 33sbtTypes = { 34plugin = types . submodule { 35options = { 36org = mkOption { 37type = types . str ; 38description = "The organization the artifact is published under." ; 39}; 40 41artifact = mkOption { 42type = types . str ; 43description = "The name of the artifact." ; 44}; 45 46version = mkOption { 47type = types . str ; 48description = "The version of the plugin." ; 49}; 50}; 51}; 52 53credential = types . submodule { 54options = { 55realm = mkOption { 56type = types . str ; 57description = "The realm of the repository you're authenticating to." ; 58}; 59 60host = mkOption { 61type = types . str ; 62description = 63"The hostname of the repository you're authenticating to." ; 64}; 65 66user = mkOption { 67type = types . str ; 68description = "The user you're using to authenticate." ; 69}; 70 71passwordCommand = mkOption { 72type = types . str ; 73description = '' 74The command that provides the password or authentication token for 75the repository. 76'' ; 77}; 78}; 79}; 80}; 81 82cfg = config . programs . sbt ; 83 84in { 85imports = [ 86( mkRemovedOptionModule [ "programs" "sbt" "baseConfigPath" ] 87"Use programs.sbt.baseUserConfigPath instead, but note that the semantics are slightly different." ) 88]; 89 90meta . maintainers = [ maintainers . kubukoz ]; 91 92options . programs . sbt = { 93enable = mkEnableOption "sbt" ; 94 95package = mkOption { 96type = types . package ; 97default = pkgs . sbt ; 98defaultText = literalExpression "pkgs.sbt" ; 99description = "The package with sbt to be installed." ; 100}; 101 102baseUserConfigPath = mkOption { 103type = types . str ; 104default = ".sbt" ; 105description = '' 106Where the sbt configuration files should be located, relative 107{env}`HOME`. 108'' ; 109}; 110 111plugins = mkOption { 112type = types . listOf ( sbtTypes . plugin ); 113default = [ ]; 114example = literalExpression '' 115[ 116{ 117org = "net.virtual-void"; 118artifact = "sbt-dependency-graph"; 119version = "0.10.0-RC1"; 120} 121{ 122org = "com.dwijnand"; 123artifact = "sbt-project-graph"; 124version = "0.4.0"; 125} 126] 127'' ; 128description = '' 129A list of plugins to place in the sbt configuration directory. 130'' ; 131}; 132 133credentials = mkOption { 134type = types . listOf ( sbtTypes . credential ); 135default = [ ]; 136example = literalExpression '' 137[{ 138realm = "Sonatype Nexus Repository Manager"; 139host = "example.com"; 140user = "user"; 141passwordCommand = "pass show sbt/user@example.com"; 142}] 143'' ; 144description = '' 145A list of credentials to define in the sbt configuration directory. 146'' ; 147}; 148 149repositories = mkOption { 150type = with types ; 151listOf 152( either ( enum [ "local" "maven-central" "maven-local" ]) ( attrsOf str )); 153default = [ ]; 154example = literalExpression '' 155[ 156"local" 157{ my-ivy-proxy-releases = "http://repo.company.com/ivy-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]" } 158{ my-maven-proxy-releases = "http://repo.company.com/maven-releases/" } 159"maven-central" 160] 161'' ; 162description = '' 163A list of repositories to use when resolving dependencies. Defined as a 164list of pre-defined repository or custom repository as a set of name to 165URL. The list will be used populate the `~/.sbt/repositories` 166file in the order specified. 167 168Pre-defined repositories must be one of `local`, 169`maven-local`, `maven-central`. 170 171Custom repositories are defined as 172`{ name-of-repo = "https://url.to.repo.com"}`. 173 174See 175<https://www.scala-sbt.org/1.x/docs/Launcher-Configuration.html#3.+Repositories+Section> 176about this configuration section and 177<https://www.scala-sbt.org/1.x/docs/Proxy-Repositories.html> 178to read about proxy repositories. 179'' ; 180}; 181}; 182 183config = mkIf cfg . enable ( mkMerge [ 184{ home . packages = [ cfg . package ]; } 185 186( mkIf ( cfg . plugins != [ ]) { 187home . file . " ${ cfg . baseUserConfigPath } /1.0/plugins/plugins.sbt" . text = 188concatStrings ( map renderPlugin cfg . plugins ); 189}) 190 191( mkIf ( cfg . credentials != [ ]) { 192home . file . " ${ cfg . baseUserConfigPath } /1.0/credentials.sbt" . text = 193renderCredentials cfg . credentials ; 194}) 195 196( mkIf ( cfg . repositories != [ ]) { 197home . file . " ${ cfg . baseUserConfigPath } /repositories" . text = 198renderRepositories cfg . repositories ; 199}) 200]); 201}