fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Robert HelgessonMerge PR #421575790441

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