Skip to content

Commit

Permalink
build: include clojure home configuration in devshell
Browse files Browse the repository at this point in the history
  • Loading branch information
ships authored and KingMob committed Apr 2, 2024
1 parent 630bff6 commit 1a7a78f
Show file tree
Hide file tree
Showing 8 changed files with 528 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
# and only means a releaser should run deps-lock and commit.
# This can be addressed inclusively with automation around releases.
- run: |
nix develop \
nix develop '.#depsLock' \
--command bash -c \
"nix run github:jlesquembre/clj-nix#deps-lock"
- run: |
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ the nix build universe has knowledge of the hash fingerprints of the new deps ve
It can be done without any setup like so:

```
nix develop --command bash -c "nix run github:jlesquembre/clj-nix#deps-lock"
nix develop '.#depsLock' --command bash -c "nix run github:jlesquembre/clj-nix#deps-lock"
```

This script can take a minute or two as it needs to build local dependencies of the `clj-nix` library,
Expand Down
504 changes: 487 additions & 17 deletions deps-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
net.cgrand/macrovich {:mvn/version "0.2.1"}
net.cgrand/xforms {:mvn/version "0.19.2"}
io.github.inferenceql/inferenceql.inference {:git/sha "c3cef474ba964a37fc2e5ff667055f5b77e12c45"}
io.github.clojure/tools.build {:git/sha "8e78bccc35116f6b6fc0bf0c125dba8b8db8da6b"}
org.babashka/sci {:mvn/version "0.3.32"}
org.clojure/clojure {:mvn/version "1.11.1"}
com.google.javascript/closure-compiler-unshaded {:mvn/version "v20230802"}
org.clojure/clojurescript {:mvn/version "1.11.132"}
org.clojure/core.match {:mvn/version "1.0.0"}
org.clojure/data.csv {:mvn/version "1.0.1"}
Expand Down
22 changes: 20 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
];
};

uber = pkgsWithCljNixOverlay.callPackage ./nix/uber {};
depsCache = pkgsWithCljNixOverlay.callPackage ./nix/depsCache {};
uber = pkgs.callPackage ./nix/uber {inherit depsCache;};

pname = "iql";
bin = pkgs.callPackage ./nix/bin { inherit uber pname; };
Expand All @@ -42,7 +43,7 @@
# packages (derived from inputs.nixpkgs automatically by
# flake-parts), but ...
ociImg = pkgs.callPackage ./nix/oci {
inherit uber pname basicToolsFn;
inherit uber pname basicToolsFn depsCache;
# ... 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
Expand All @@ -51,8 +52,25 @@
};

in {
# development shell
devShells.default = pkgs.mkShell {
buildInputs = [ pkgs.openjdk21 pkgs.clojure pkgs.babashka depsCache ] ++ (basicToolsFn pkgs);

shellHook = ''
echo "Setting up default dev shell..."
export CLJ_CONFIG="${depsCache}/.clojure"
export GITLIBS="${depsCache}/.gitlibs"
export JAVA_TOOL_OPTIONS="-Duser.home=${depsCache}"
'';
};

# a minimal shell for doing a depsLock, that doesn't require an existing deps cache
devShells.depsLock = pkgs.mkShell {
buildInputs = [ pkgs.openjdk21 pkgs.clojure pkgs.babashka ] ++ (basicToolsFn pkgs);

shellHook = ''
echo "Setting up minimal dev shell..."
'';
};

packages = {
Expand Down
9 changes: 9 additions & 0 deletions nix/depsCache/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{ stdenv,
pkgs,
mk-deps-cache,
}: mk-deps-cache {
lockfile = builtins.path {
path = ./../../deps-lock.json;
name = "inferenceql.query.deps-lock.json";
};
}
9 changes: 7 additions & 2 deletions nix/oci/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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;
Expand All @@ -17,7 +18,6 @@
contents =
(basicToolsFn crossPkgsLinux) ++ (with crossPkgsLinux; [
bashInteractive
busybox # NOTE: might be unnecessary
]);
config = {
Cmd = [ "${crossPkgsLinux.bashInteractive}/bin/bash" ];
Expand All @@ -30,9 +30,14 @@ in pkgs.dockerTools.buildImage {
tag = systemWithLinux;
fromImage = baseImg;
# architecture
copyToRoot = [ ociBin ];
copyToRoot = [ ociBin depsCache crossPkgsLinux.clojure ];
config = {
Cmd = [ "${ociBin}/bin/${pname}" ];
Env = [
"CLJ_CONFIG=${depsCache}/.clojure"
"GITLIBS=${depsCache}/.gitlibs"
"JAVA_TOOL_OPTIONS=-Duser.home=${depsCache}"
];
};
}

Expand Down
11 changes: 2 additions & 9 deletions nix/uber/default.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
{ stdenv,
pkgs,
mk-deps-cache,
}: let
depsCache = mk-deps-cache {
lockfile = builtins.path {
path = ./../../deps-lock.json;
name = "inferenceql.query.deps-lock.json";
};
};
in stdenv.mkDerivation {
depsCache,
}: stdenv.mkDerivation {
name = "inferenceql.query-uberjar";
version = "unstable";
src = builtins.path {
Expand Down

0 comments on commit 1a7a78f

Please sign in to comment.