Skip to content

Commit

Permalink
fix: Correctly install deps into sppl container
Browse files Browse the repository at this point in the history
- Python site packages
- JDK modules
  • Loading branch information
ships committed May 10, 2024
1 parent c3b96cc commit 985adce
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/nix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@ jobs:
-L \
-o ./imgTarball \
'.#ociImg'
- run: |
nix build \
-L \
-o ./imgTarball \
'.#ociImgSppl'
2 changes: 1 addition & 1 deletion build.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
(def uber-file (format "target/%s-%s-standalone.jar" (name lib) version))

;; delay to defer side effects (artifact downloads)
(def basis (delay (build/create-basis {:project "deps.edn"})))
(def basis (delay (build/create-basis {:aliases [ :query-sppl ]})))

;; clean build artifacts (excludes test artifacts)
(defn clean [_]
Expand Down
2 changes: 2 additions & 0 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
:jvm-opts ["-Djdk.attach.allowAttachSelf"]}

:query-sppl { :extra-deps { io.github.OpenGen/GenSQL.gpm.sppl {:git/sha "718de40878766bb8d08acc2b429a76ed662a1352"}}
:jvm-opts ["--add-modules" "jdk.incubator.foreign,jdk.incubator.vector"
"--enable-native-access=ALL-UNNAMED"]
:main-opts ["-m" "gensql.query.main"]
}

Expand Down
15 changes: 9 additions & 6 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
};
};

outputs = inputs@{ flake-parts, systems , ... }:
outputs = inputs@{ flake-parts, systems , opengen, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = import systems;

Expand All @@ -28,7 +28,10 @@

pname = "gensql";
bin = pkgs.callPackage ./nix/bin { inherit uber pname; };
binGpmSppl = pkgs.callPackage ./nix/bin/with_extra_deps.nix { inherit pname; uber = uberGpmSppl; extraDeps = [ inputs.opengen.packages.${system}.sppl ]; };
binGpmSppl = pkgs.callPackage ./nix/bin/gpm-sppl.nix {
inherit pname opengen;
uber = uberGpmSppl;
};

basicToolsFn = pkgs: with pkgs; [
coreutils
Expand All @@ -46,16 +49,16 @@
# packages (derived from inputs.nixpkgs automatically by
# flake-parts), but ...
ociImg = pkgs.callPackage ./nix/oci {
inherit uber pname basicToolsFn depsCache;
inherit uber pname basicToolsFn depsCache opengen;
# ... we still must pass in the original nixpkgs because
# we need access to a different system's set of packages
# when compiling for linux while remaining agnostic of
# the workstation platform we are running this on.
nixpkgs = inputs.nixpkgs;
};

ociImgSppl = pkgs.callPackage ./nix/oci {
inherit pname basicToolsFn depsCache;
ociImgSppl = pkgs.callPackage ./nix/oci/gpm-sppl.nix {
inherit pname opengen basicToolsFn depsCache;
uber = uberGpmSppl;
# ... we still must pass in the original nixpkgs because
# we need access to a different system's set of packages
Expand Down Expand Up @@ -97,7 +100,7 @@
};

devShells.sppl = pkgs.mkShell {
buildInputs = [ pkgs.openjdk21 pkgs.clojure pkgs.babashka depsCache inputs.opengen.sppl ] ++ (basicToolsFn pkgs);
buildInputs = [ pkgs.openjdk21 pkgs.clojure pkgs.babashka depsCache inputs.opengen.packages.${system}.sppl ] ++ (basicToolsFn pkgs);

shellHook = mutableCacheHook;
};
Expand Down
16 changes: 13 additions & 3 deletions nix/bin/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{ pkgs,
system,
uber,
pname,
...
}: import ./with_extra_deps.nix { inherit pkgs uber pname; extraDeps = []; }
pname
}: pkgs.stdenv.mkDerivation {
name = "gensql.query";
inherit pname;
src = ./.;
nativeBuildInputs = [ pkgs.makeWrapper ];
buildInputs = [ pkgs.openjdk17 ];
installPhase = ''
makeWrapper ${pkgs.openjdk17}/bin/java $out/bin/${pname} \
--add-flags "-jar ${uber}"
'';
}
9 changes: 7 additions & 2 deletions nix/bin/with_extra_deps.nix → nix/bin/gpm-sppl.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
{ pkgs,
system,
uber,
extraDeps,
opengen,
pname
}: pkgs.stdenv.mkDerivation {
name = "gensql.query";
inherit pname;
src = ./.;
nativeBuildInputs = [ pkgs.makeWrapper ];
buildInputs = [ pkgs.openjdk17 ] ++ extraDeps;
buildInputs = [ pkgs.openjdk17 ];
propagatedBuildInputs = with opengen; [
opengen.packages.${system}.sppl
opengen.packages.${system}.sppl.runtimePython
];
installPhase = ''
makeWrapper ${pkgs.openjdk17}/bin/java $out/bin/${pname} \
--add-flags "-jar ${uber}"
Expand Down
16 changes: 4 additions & 12 deletions nix/oci/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{ pkgs,
nixpkgs,
opengen,
system,
uber,
pname,
Expand All @@ -13,24 +14,15 @@

# TODO: This can be factored out into an gensql/nix
# shared package.
baseImg = pkgs.dockerTools.buildLayeredImage {
name = "gensql.base";
contents =
(basicToolsFn crossPkgsLinux) ++ (with crossPkgsLinux; [
bashInteractive
]);
config = {
Cmd = [ "${crossPkgsLinux.bashInteractive}/bin/bash" ];
};
};
baseImg = opengen.packages.${system}.ociImgBase

ociBin = crossPkgsLinux.callPackage ./../bin {inherit uber pname;};
in pkgs.dockerTools.buildImage {
in pkgs.dockerTools.buildLayeredImage {
name = "probcomp/gensql.query";
tag = systemWithLinux;
fromImage = baseImg;
# architecture
copyToRoot = [ ociBin depsCache crossPkgsLinux.clojure ];
contents = [ ociBin depsCache crossPkgsLinux.clojure ] ++ extraDeps;
config = {
Cmd = [ "${ociBin}/bin/${pname}" ];
Env = [
Expand Down
48 changes: 48 additions & 0 deletions nix/oci/gpm-sppl.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{ pkgs,
nixpkgs,
system,
opengen,
uber,
pname,
basicToolsFn,
depsCache,
}: let
# in OCI context, whatever our host platform we want to build same arch but linux
systemWithLinux = builtins.replaceStrings [ "darwin" ] [ "linux" ] system;

crossPkgsLinux = nixpkgs.legacyPackages.${systemWithLinux};

# TODO: This can be factored out into an gensql/nix
# shared package.
baseImg = opengen.packages.${system}.ociImgBase;

sppl = opengen.packages.${systemWithLinux}.sppl;
python = opengen.packages.${systemWithLinux}.sppl.runtimePython;

ociBin = crossPkgsLinux.callPackage ./../bin/gpm-sppl.nix {
inherit
uber
opengen
pname
;
};
in pkgs.dockerTools.buildLayeredImage {
name = "probcomp/gensql.query";
tag = systemWithLinux;
fromImage = baseImg;
# architecture
contents = [ ociBin depsCache crossPkgsLinux.clojure sppl python];
config = {
Cmd = [ "${ociBin}/bin/${pname}" ];
Env = [
"CLJ_CONFIG=${depsCache}/.clojure"
"GITLIBS=${depsCache}/.gitlibs"
"JAVA_TOOL_OPTIONS=-Duser.home=${depsCache}"
"JDK_JAVA_OPTIONS=--add-modules jdk.incubator.foreign,jdk.incubator.vector --enable-native-access=ALL-UNNAMED"
"PYTHONPATH=${python.sitePackages}"
];
};
}



0 comments on commit 985adce

Please sign in to comment.