From a4a83078976025f2dc6aaca35b20880735f7baa3 Mon Sep 17 00:00:00 2001 From: Shamrock Lee <44064051+ShamrockLee@users.noreply.github.com> Date: Mon, 2 Aug 2021 17:14:10 +0800 Subject: [PATCH] java: add module --- .github/CODEOWNERS | 2 ++ modules/misc/news.nix | 7 ++++++ modules/modules.nix | 1 + modules/programs/java.nix | 46 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 modules/programs/java.nix diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 4818d8cf4..8c7b1c7ea 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -95,6 +95,8 @@ /modules/programs/i3status-rust.nix @workflow +/modules/programs/java.nix @ShamrockLee + /modules/programs/keychain.nix @marsam /modules/programs/lazygit.nix @kalhauge diff --git a/modules/misc/news.nix b/modules/misc/news.nix index a4f06a468..fa0a027d5 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -2157,6 +2157,13 @@ in A new module is available: 'services.notify-osd'. ''; } + + { + time = "2021-08-10T21:28:40+00:00"; + message = '' + A new module is available: 'programs.java'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 52dd9d3c9..3ab72a180 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -77,6 +77,7 @@ let ./programs/i3status.nix ./programs/info.nix ./programs/irssi.nix + ./programs/java.nix ./programs/jq.nix ./programs/kakoune.nix ./programs/keychain.nix diff --git a/modules/programs/java.nix b/modules/programs/java.nix new file mode 100644 index 000000000..5b2a01299 --- /dev/null +++ b/modules/programs/java.nix @@ -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 JAVA_HOME + variable. + ''; + }; + + package = mkOption { + type = types.package; + default = pkgs.jdk; + defaultText = "pkgs.jdk"; + description = '' + Java package to install. Typical values are + pkgs.jdk or pkgs.jre. + ''; + }; + }; + }; + + 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 + ''); + }; + }; +}