java: add module

(cherry picked from commit a4a8307897)
This commit is contained in:
Shamrock Lee 2021-08-02 17:14:10 +08:00 committed by Robert Helgesson
parent 0e58ffec58
commit 382505714d
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
4 changed files with 56 additions and 0 deletions

2
.github/CODEOWNERS vendored
View file

@ -84,6 +84,8 @@
/modules/programs/i3status-rust.nix @workflow
/modules/programs/java.nix @ShamrockLee
/modules/programs/keychain.nix @marsam
/modules/programs/lazygit.nix @kalhauge

View file

@ -2047,6 +2047,13 @@ in
configuration file.
'';
}
{
time = "2021-10-03T20:00:52+00:00";
message = ''
A new module is available: 'programs.java'.
'';
}
];
};
}

View file

@ -83,6 +83,7 @@ let
(loadModule ./programs/info.nix { })
(loadModule ./programs/irssi.nix { })
(loadModule ./programs/lieer.nix { })
(loadModule ./programs/java.nix { })
(loadModule ./programs/jq.nix { })
(loadModule ./programs/kakoune.nix { })
(loadModule ./programs/keychain.nix { })

46
modules/programs/java.nix Normal file
View file

@ -0,0 +1,46 @@
# This module provides JAVA_HOME, with a different way to install java locally.
# This module is modified from the NixOS module `programs.java`
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.programs.java;
in {
meta.maintainers = with maintainers; [ ShamrockLee ];
options = {
programs.java = {
enable = mkEnableOption "" // {
description = ''
Install the Java development kit and set the <envar>JAVA_HOME</envar>
variable.
'';
};
package = mkOption {
type = types.package;
default = pkgs.jdk;
defaultText = "pkgs.jdk";
description = ''
Java package to install. Typical values are
<literal>pkgs.jdk</literal> or <literal>pkgs.jre</literal>.
'';
};
};
};
config = mkIf cfg.enable {
home.packages = [ cfg.package ];
home.sessionVariables = {
JAVA_HOME = fileContents (pkgs.runCommandLocal "java-home" { } ''
source "${cfg.package}/nix-support/setup-hook"
echo "$JAVA_HOME" > $out
'');
};
};
}