1
0
mirror of https://github.com/nix-community/home-manager synced 2024-06-03 05:23:32 +02:00
home-manager/modules/programs/gradle.nix
Benedikt Ritter 433120e47d
gradle: add module
Introduces a new program called gradle for managing files stored in
the home directory by the [Gradle Build Tool](https://gradle.org).
Gradle uses the $HOME/.gradle folder for all it's configuration.

Features of the new program module are:

- Automatically setting programs.java.enable = true to make a Java
  installation available for running Gradle.
- Specifying an alternate Gradle home directory
- Setting of abitrary values for gradle.properties stored inside the
  Gradle home directory.
- Defining init scripts that will be linked into the init.d inside
  the Gradle home directory.

Co-authored-by: Olli Helenius <liff@iki.fi>
Co-authored-by: Robert Helgesson <robert@rycee.net>
2023-12-20 12:41:17 +01:00

115 lines
3.1 KiB
Nix

{ config, pkgs, lib, ... }:
with lib;
let
cfg = config.programs.gradle;
defaultHomeDirectory = ".gradle";
settingsFormat = pkgs.formats.javaProperties { };
initScript = types.submodule ({ name, config, ... }: {
options = {
text = mkOption {
type = types.nullOr types.lines;
default = null;
description = ''
Text of the init script file. if this option is null
then `source` must be set.
'';
};
source = mkOption {
type = types.path;
description = ''
Path of the init script file. If
`text` is non-null then this option will automatically point
to a file containing that text.
'';
};
};
config.source = mkIf (config.text != null) (mkDefault (pkgs.writeTextFile {
inherit (config) text;
name = hm.strings.storeFileName name;
}));
});
in {
meta.maintainers = [ maintainers.britter ];
options.programs.gradle = {
enable = mkEnableOption "Gradle Build Tool";
home = mkOption {
type = types.str;
default = defaultHomeDirectory;
description = ''
The Gradle home directory, relative to [](#opt-home.homeDirectory).
If set, the {env}`GRADLE_USER_HOME` environment variable will be
set accordingly. Defaults to {file}`.gradle`.
'';
};
package = mkPackageOption pkgs "gradle" { example = "pkgs.gradle_7"; };
settings = mkOption {
type = types.submodule { freeformType = settingsFormat.type; };
default = { };
example = literalExpression ''
{
"org.gradle.caching" = true;
"org.gradle.parallel" = true;
"org.gradle.jvmargs" = "-XX:MaxMetaspaceSize=384m";
"org.gradle.home" = pkgs.jdk17;
};
'';
description = ''
Key value pairs to write to {file}`gradle.properties` in the Gradle
home directory.
'';
};
initScripts = mkOption {
type = with types; attrsOf initScript;
default = { };
example = literalExpression ''
{
"maven-local.gradle".text = '''
allProject {
repositories {
mavenLocal()
}
}
''';
"another.init.gradle.kts".source = ./another.init.gradle.kts;
}
'';
description = ''
Definition of init scripts to link into the Gradle home directory.
For more information about init scripts, including naming conventions
see https://docs.gradle.org/current/userguide/init_scripts.html.
'';
};
};
config = let gradleHome = "${config.home.homeDirectory}/${cfg.home}";
in mkIf cfg.enable {
home.packages = [ cfg.package ];
home.file = mkMerge ([{
"${cfg.home}/gradle.properties" = mkIf (cfg.settings != { }) {
source = settingsFormat.generate "gradle.properties" cfg.settings;
};
}]
++ mapAttrsToList (k: v: { "${cfg.home}/init.d/${k}".source = v.source; })
cfg.initScripts);
home.sessionVariables = mkIf (cfg.home != defaultHomeDirectory) {
GRADLE_USER_HOME = gradleHome;
};
programs.java.enable = true;
};
}