Skip to content

Commit abc2b6e

Browse files
Switch to custom jdk
* add graphviz tool
1 parent 4e283ff commit abc2b6e

File tree

6 files changed

+220
-2
lines changed

6 files changed

+220
-2
lines changed

flake.nix

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
# can't update graal right now - this is from Aug '23
77
flake-utils.url = "github:numtide/flake-utils";
88
clj-nix = {
9+
# for debugging the nix packages
10+
# url = "path:/Users/slim/slimslenderslacks/clj-nix";
911
url = "github:jlesquembre/clj-nix";
1012
inputs.nixpkgs.follows = "nixpkgs";
1113
};
@@ -60,14 +62,15 @@
6062
custom-jdk = pkgs.clj-nix.customJdk {
6163
cljDrv = clj;
6264
jdkBase = pkgs.jdk17_headless;
63-
locales = "en";
65+
# locales = "en";
6466
javaOpts = [];
67+
extraJdkModules = ["java.security.jgss" "java.security.sasl" "jdk.crypto.ec"];
6568
};
6669

6770
entrypoint = pkgs.writeShellScriptBin "entrypoint" ''
6871
export PATH=${pkgs.lib.makeBinPath [pkgs.curl]}
6972
export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt
70-
${clj}/bin/agent-graph "$@"
73+
${custom-jdk}/bin/agent-graph "$@"
7174
'';
7275

7376
default = pkgs.buildEnv {

functions/graphviz/Dockerfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
# syntax = docker/dockerfile:1.4
3+
FROM nixos/nix:2.21.1@sha256:3f6c77ee4d2c82e472e64e6cd7087241dc391421a0b42c22e6849c586d5398d9 AS builder
4+
5+
WORKDIR /tmp/build
6+
RUN mkdir /tmp/nix-store-closure
7+
8+
# ignore SC2046 because the output of nix-store -qR will never have spaces - this is safe here
9+
# hadolint ignore=SC2046
10+
RUN --mount=type=cache,target=/nix,from=nixos/nix:2.21.1,source=/nix \
11+
--mount=type=cache,target=/root/.cache \
12+
--mount=type=bind,target=/tmp/build \
13+
<<EOF
14+
nix \
15+
--extra-experimental-features "nix-command flakes" \
16+
--option filter-syscalls false \
17+
--extra-trusted-substituters "https://cache.iog.io" \
18+
--extra-trusted-public-keys "hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=" \
19+
--show-trace \
20+
--log-format raw \
21+
build . --out-link /tmp/output/result
22+
cp -R $(nix-store -qR /tmp/output/result) /tmp/nix-store-closure
23+
EOF
24+
25+
FROM babashka/babashka:latest@sha256:9e0381fc4c78ee6ff12fd8836352cf343afba289aceb77e36129d92f30a92cc7
26+
27+
WORKDIR /app
28+
29+
COPY --from=builder /tmp/nix-store-closure /nix/store
30+
COPY --from=builder /tmp/output/ /app/
31+
32+
ENTRYPOINT ["/app/result/bin/entrypoint"]
33+
CMD ["--help"]

functions/graphviz/flake.lock

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

functions/graphviz/flake.nix

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
description = "graphviz";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
6+
flake-utils.url = "github:numtide/flake-utils";
7+
};
8+
9+
outputs = { self, nixpkgs, flake-utils, ...}@inputs:
10+
11+
flake-utils.lib.eachDefaultSystem
12+
(system:
13+
let
14+
pkgs = import nixpkgs {
15+
inherit system;
16+
};
17+
18+
in rec
19+
{
20+
packages = rec {
21+
22+
# this derivation just contains the init.clj script
23+
scripts = pkgs.stdenv.mkDerivation {
24+
name = "scripts";
25+
src = ./.;
26+
installPhase = ''
27+
cp init.clj $out
28+
'';
29+
};
30+
31+
run-entrypoint = pkgs.writeShellScriptBin "entrypoint" ''
32+
export PATH=${pkgs.lib.makeBinPath [pkgs.graphviz pkgs.man]}
33+
export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt
34+
/usr/local/bin/bb ${scripts} "$@"
35+
'';
36+
37+
default = pkgs.buildEnv {
38+
name = "graphviz";
39+
paths = [ run-entrypoint ];
40+
};
41+
};
42+
});
43+
}
44+

functions/graphviz/init.clj

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
(ns init
2+
(:require
3+
[babashka.process]
4+
[cheshire.core]))
5+
6+
(defn output [args]
7+
(try
8+
(->
9+
(apply babashka.process/process
10+
{:out :string}
11+
args)
12+
(deref)
13+
(babashka.process/check))
14+
(catch Throwable _ nil)))
15+
16+
(defn man [t]
17+
(output ["man" t]))
18+
(defn help [t]
19+
(output [t "--help"]))
20+
(defn h [t]
21+
(output [t "-h"]))
22+
23+
(try
24+
(let [[json-string & extra-args] *command-line-args*
25+
{:keys [args]} (cheshire.core/parse-string json-string true)]
26+
(println
27+
(-> (if (= "man" (first extra-args))
28+
(let [t (second args)] (or (man t) (help t) (h t)))
29+
(-> (babashka.process/process
30+
{:out :string}
31+
args)
32+
(deref)
33+
(babashka.process/check)))
34+
(deref)
35+
(babashka.process/check)
36+
:out)))
37+
(catch Throwable t
38+
(binding [*out* *err*]
39+
(println (str "Error: " (.getMessage t)))
40+
(System/exit 1))))
41+
42+

functions/graphviz/runbook.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Background
2+
3+
The `curl` function has one parameter.
4+
5+
* `args`: the args to send to the image
6+
7+
## Usage
8+
9+
This function should be given a rw bind mount for the root of a project.
10+
11+
```sh
12+
docker run --rm \
13+
--mount type=bind,source=$PWD,target=/project \
14+
--entrypoint /app/result/bin/entrypoint \
15+
--workdir /project \
16+
vonwig/graphviz:latest '{"args": "--help"}'
17+
```
18+
19+
## Build
20+
21+
```sh
22+
docker build -t vonwig/graphviz:latest .
23+
```
24+
25+
```sh
26+
# docker:command=build
27+
28+
docker buildx build \
29+
--builder hydrobuild \
30+
--platform linux/amd64,linux/arm64 \
31+
--tag vonwig/graphviz:latest \
32+
--file Dockerfile \
33+
--push .
34+
docker pull vonwig/graphviz:latest
35+
```

0 commit comments

Comments
 (0)