Skip to content

Commit

Permalink
Add option to build a custom, slimmer, JRE for datomic
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramblurr committed Oct 31, 2024
1 parent 18ea03e commit 2e54be5
Show file tree
Hide file tree
Showing 9 changed files with 227 additions and 78 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- nix pkg: Exposed more packages: `datomic-shell`, `datomic-run`, `datomic-repl`, `datomic-peer-server`
- nixos module: You can now configure: logging, extra classpath entries, and extra java options.
- nix pkg: Added datomic-pro-peer package which is the datomic peer library with all of its dependencies
- nix pkg: Added option to build slimmed down JRE for datomic-pro

### Changed

- nix pkg: Updated datomic-pro to version 1.0.7260
- nix pkg: Switched to Nix's JDK 21 headless package (now that it is sufficiently headless
- nix pkg: Switched to Nix's JDK 21 headless package (which is supported by Datomic)
- oci image: Use the slimmed down JRE and a custom babashka build to reduce size of the image

### Fixed

Expand Down
112 changes: 111 additions & 1 deletion flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
#clj-nix.url = "github:jlesquembre/clj-nix";
clj-nix.url = "github:jlesquembre/clj-nix";
};

outputs =
{
self,
nixpkgs,
flake-utils,
clj-nix,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlays."${system}" ];
overlays = [
clj-nix.overlays.default
self.overlays."${system}"
];
};

jdk-minimal = pkgs.jdk21_headless;
in
{
overlays = final: prev: {
Expand Down Expand Up @@ -70,6 +72,7 @@
buildInputs = [
pkgs.skopeo
pkgs.babashka
pkgs.dive
pkgs.gnumake
];
};
Expand Down
2 changes: 0 additions & 2 deletions nixos-modules/datomic-console.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ in
services.datomic-console = {
enable = lib.mkEnableOption "Datomic Console";
package = lib.mkPackageOption pkgs "datomic-pro" { };
javaPackage = lib.mkPackageOption pkgs "jdk21_headless" { };
port = lib.mkOption {
type = lib.types.port;
description = "The port the console will bind to";
Expand Down Expand Up @@ -151,7 +150,6 @@ in
db_uri="$(<"$CREDENTIALS_DIRECTORY/datomic-console-db-uri")"
${cfg.package}/bin/datomic-console -p ${toString cfg.port} "${cfg.alias}" "$db_uri"
'';
path = [ cfg.javaPackage ];
environment =
{
DATOMIC_JAVA_OPTS = toString extraJavaOptions;
Expand Down
72 changes: 41 additions & 31 deletions pkgs/datomic-generate-properties.nix
Original file line number Diff line number Diff line change
@@ -1,39 +1,49 @@
{
hostname,
lib,
mkBabashka,
stdenv,
fetchzip,
babashka,
dockerTools,
datomic-pro,
hostname,
substituteAll,
...
}:

stdenv.mkDerivation (finalAttrs: {
pname = "datomic-generate-properties";
version = "0.1";
stdenv.mkDerivation (
finalAttrs:
let
bb = mkBabashka {
bbLean = true;
wrap = false;
withFeatures = [ "transit" ];
};
in
{
pname = "datomic-generate-properties";
version = "0.1";

src = ./generate-properties.clj;
src = substituteAll {
babashkaBin = "${bb}/bin/bb";
src = ./generate-properties.clj;
};

dontUnpack = true;
propagatedBuildInputs = [
babashka
hostname
];
installPhase = ''
runHook preInstall
ls -al $src
mkdir -p $out/bin
cp -r $src $out/bin/datomic-generate-properties
chmod +x $out/bin/datomic-generate-properties
find $out
runHook postInstall
'';
meta = {
description = "Generates a java properties file for Datomic Pro based off of environment variables and sane defaults.";
homepage = "";
changelog = "";
license = lib.licenses.asl20;
mainProgram = "datomic-generate-properties";
};
})
dontUnpack = true;
propagatedBuildInputs = [
hostname
];
installPhase = ''
runHook preInstall
ls -al $src
mkdir -p $out/bin
cp -r $src $out/bin/datomic-generate-properties
chmod +x $out/bin/datomic-generate-properties
find $out
runHook postInstall
'';
meta = {
description = "Generates a java properties file for Datomic Pro based off of environment variables and sane defaults.";
homepage = "";
changelog = "";
license = lib.licenses.asl20;
mainProgram = "datomic-generate-properties";
};
}
)
30 changes: 14 additions & 16 deletions pkgs/datomic-pro-container-image.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
{
babashka,
cacert,
coreutils,
datomic-generate-properties,
datomic-pro,
dockerTools,
fetchzip,
hostname,
imageTag,
jre_minimal,
lib,
mysql_jdbc,
runCommand,
Expand All @@ -20,17 +17,21 @@
}:

let
jre = jre_minimal;
datomicBuild = datomic-pro.override {
withCustomJre = true;
extraJavaPkgs = [
sqlite-jdbc
mysql_jdbc
];
};
entrypointSmall = writeShellScriptBin "datomic-entrypoint" ''
#! ${runtimeShell}
${datomicBuild}/bin/datomic-transactor "$DATOMIC_TRANSACTOR_PROPERTIES_PATH"
'';
entrypoint = writeShellScriptBin "datomic-entrypoint" ''
#! ${runtimeShell}
set -e
export PATH=${hostname}/bin:${jre}/bin:${coreutils}/bin:${babashka}:$PATH
export PATH=${hostname}/bin:${coreutils}/bin:$PATH
if [ "$(id -u)" = "0" ]; then
echo "WARNING: Running Datomic as root is not recommended. Please run as a non-root user."
echo " This can be ignored if you are using rootless mode."
Expand Down Expand Up @@ -71,24 +72,21 @@ dockerTools.buildLayeredImage {
contents = [
dockerTools.usrBinEnv
dockerTools.binSh
babashka
cacert
coreutils
datomic-generate-properties
datomicBuild
entrypoint
env-shim
jre
mysql_jdbc
sqlite-jdbc
#cacert
#datomic-generate-properties
#datomicBuild
#entrypoint
#env-shim
#mysql_jdbc
#sqlite-jdbc
];
extraCommands = ''
mkdir -p tmp
chmod 1777 tmp
'';

config = {
Entrypoint = [ "${entrypoint}/bin/datomic-entrypoint" ];
Entrypoint = [ "${entrypointSmall}/bin/datomic-entrypoint" ];
Env = [
"DATOMIC_TRANSACTOR_PROPERTIES_PATH=/config/transactor.properties"
"LC_ALL=C.UTF-8"
Expand Down
4 changes: 0 additions & 4 deletions pkgs/datomic-pro-peer.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
maven,
fetchzip,
stdenv,
jre,
jdk,
...
}:

Expand All @@ -29,8 +27,6 @@ stdenv.mkDerivation (
maven
];

JAVA_HOME = jdk;

buildPhase = ''
runHook preBuild
mvn de.qaware.maven:go-offline-maven-plugin:1.2.8:resolve-dependencies -Dmaven.repo.local=$out/.m2
Expand Down
Loading

0 comments on commit 2e54be5

Please sign in to comment.