Skip to content

Commit

Permalink
wildfly: init 24.0.1
Browse files Browse the repository at this point in the history
Signed-off-by: Ionut Nechita <[email protected]>
  • Loading branch information
ionutnechita committed Feb 8, 2025
1 parent 3127850 commit 6f2b88d
Show file tree
Hide file tree
Showing 4 changed files with 285 additions and 0 deletions.
1 change: 1 addition & 0 deletions nixos/modules/module-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1633,6 +1633,7 @@
./services/web-servers/unit/default.nix
./services/web-servers/uwsgi.nix
./services/web-servers/varnish/default.nix
./services/web-servers/wildfly/default.nix
./services/x11/clight.nix
./services/x11/colord.nix
./services/x11/desktop-managers/default.nix
Expand Down
67 changes: 67 additions & 0 deletions nixos/modules/services/web-servers/wildfly/builder.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
set -e

mkdir -p "$out"/bin

cat > "$out"/bin/control <<EOF
export PATH="$PATH":"$su"/bin
start()
{
su "$user" -s /bin/sh -c 'cd $serverDir; \
export JBOSS_JAVA_SIZING="\
-Xms$initialHeapMem \
-Xmx$maxHeapMem \
-XX:MetaspaceSize=$initialMetaspaceSize \
-XX:MaxMetaspaceSize=$maxMetaspaceSize"; \
$serverDir/bin/$wildflyMode.sh \
-c $wildflyConfig \
-b $wildflyBind \
-bmanagement $wildflyBindManagement \
'
}
preStart()
{
su "$user" -s /bin/sh -c 'cd $serverDir; \
$serverDir/bin/add-user.sh \
-u $userAdmin \
-p $passwordAdmin \
'
}
if [ "$cleanBoot" == "1" ]; then
rm -rf "$serverDir"
fi
if [ ! -d "$serverDir" ]; then
mkdir -p "$serverDir"
cd "$serverDir"
cp -a "$wildfly"/opt/wildfly/* .
chown -R "$user":"$group" "$serverDir"
for i in \`find "$serverDir" -type d\`
do
chmod 775 -R "\$i" 2>/dev/null
done
for i in \`find "$serverDir" -type f\`
do
chmod 664 -R "\$i" 2>/dev/null
done
for i in \`find "$serverDir" -name "*.sh"\`
do
chmod 775 -R "\$i" 2>/dev/null
done
preStart
fi
start
EOF

chmod +x "$out"/bin/*
169 changes: 169 additions & 0 deletions nixos/modules/services/web-servers/wildfly/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
{
config,
lib,
pkgs,
...
}:

with lib;

let

cfg = config.services.wildfly;

wildflyService = pkgs.stdenv.mkDerivation {
name = "wildfly-server";
builder = ./builder.sh;
inherit (pkgs) wildfly su;
inherit (cfg)
enable
cleanBoot
serverDir
user
group
userAdmin
passwordAdmin
initialHeapMem
maxHeapMem
initialMetaspaceSize
maxMetaspaceSize
wildflyConfig
wildflyMode
wildflyBind
wildflyBindManagement
;
};

cleanupScript = pkgs.writeScript "wildfly-cleanup" ''
#!${pkgs.bash}/bin/bash
if [ "${toString cfg.cleanBoot}" == "1" ]; then
rm -rf ${cfg.serverDir}
fi
'';

in

{

###### interface

options = {

services.wildfly = {

enable = mkOption {
type = types.bool;
default = false;
description = "Whether to enable Wildfly.";
};

cleanBoot = mkOption {
type = types.bool;
default = false;
description = "Delete and install the server instance file location every time. No persistence.";
};

serverDir = mkOption {
description = "Location of the server instance files";
default = "/opt/wildfly";
type = types.str;
};

user = mkOption {
default = "nobody";
description = "User account under which Wildfly runs.";
type = types.str;
};

group = mkOption {
default = "nogroup";
description = "Group account under which Wildfly runs.";
type = types.str;
};

userAdmin = mkOption {
default = "admin";
description = "Admin user who does the web management of Wildfly.";
type = types.str;
};

passwordAdmin = mkOption {
default = "wildfly";
description = "Password admin user who does the web management of Wildfly.";
type = types.str;
};

initialHeapMem = mkOption {
description = "Initial Heap memory.";
default = "400M";
type = types.str;
};

maxHeapMem = mkOption {
description = "Max Heap memory.";
default = "600M";
type = types.str;
};

initialMetaspaceSize = mkOption {
description = "Initial Metaspace size.";
default = "100M";
type = types.str;
};

maxMetaspaceSize = mkOption {
description = "Max Metaspace size.";
default = "300M";
type = types.str;
};

wildflyConfig = mkOption {
description = "Wildfly default config.";
default = "standalone-full.xml";
type = types.str;
};

wildflyMode = mkOption {
description = "Wildfly default mode.";
default = "standalone";
type = types.str;
};

wildflyBind = mkOption {
description = "Wildfly bind address.";
default = "0.0.0.0";
type = types.str;
};

wildflyBindManagement = mkOption {
description = "Wildfly bind management address.";
default = "127.0.0.1";
type = types.str;
};

};

};

###### implementation

config = mkMerge [
(mkIf cfg.enable {
systemd.services.wildfly = {
description = "WildFly Application Server";
script = "${wildflyService}/bin/control";
wantedBy = [ "multi-user.target" ];
};
})

(mkIf ((!cfg.enable) && cfg.cleanBoot) {
system.activationScripts.wildflyCleanup = {
text = ''
${cleanupScript}
'';
deps = [ ];
};
})
];

}
48 changes: 48 additions & 0 deletions pkgs/by-name/wi/wildfly/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
lib,
stdenv,
fetchurl,
common-updater-scripts,
coreutils,
git,
gnused,
makeWrapper,
nix,
openjdk,
writeScript,
nixosTests,
jq,
cacert,
curl,
}:

stdenv.mkDerivation rec {
pname = "wildfly";
version = "24.0.1";

src = fetchurl {
url = "https://download.jboss.org/wildfly/${version}.Final/wildfly-${version}.Final.tar.gz";
hash = "sha256-eD88L5gHeYc6vHC8lRdRHWUGk2wbYRwCjnc+6R5U7o8=";
};

nativeBuildInputs = [ makeWrapper ];

buildCommand = ''
mkdir -p "$out/opt"
tar xf "$src" -C "$out/opt"
mv "$out/opt/${pname}-${version}.Final" "$out/opt/${pname}"
find "$out/opt/${pname}" -name \*.sh -print0 | xargs -0 sed -i -e '/#!\/bin\/sh/aJAVA_HOME=${openjdk}'
'';

meta = {
description = "WildFly Application Server";
homepage = "https://www.wildfly.org/";
sourceProvenance = with sourceTypes; [ binaryBytecode ];
license = licenses.asl20;
maintainers = with maintainers; [
ionutnechita
];
mainProgram = "wildfly";
platforms = platforms.unix;
};
}

0 comments on commit 6f2b88d

Please sign in to comment.