Skip to content

Commit 60d39d6

Browse files
emsosamsclaudeNovaMage
authored
Track .envrc + make postgres scripted test work on NixOS (#5)
* Track .envrc so devshell auto-loads on cd Track the .envrc with `use flake` so contributors with direnv + nix-direnv get the devshell automatically on cd, without having to author .envrc themselves. Closes #4 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Make postgres scripted test work on NixOS zonky's bundled generic-Linux Postgres binaries can't run on NixOS, so `sbt scripted` fails locally even though CI (Ubuntu) is fine. The flake devshell now exports NOMAD_PG_TARBALL pointing at an XZ tar of pkgs.postgresql (bin, lib, share). When set, the test feeds that through a custom PgBinaryResolver and overrides unix_socket_directories to $TMPDIR (nix postgres defaults to /run/postgresql, absent in the sandbox). Without the env var, behaviour is unchanged — CI keeps working as-is. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Fix misleading unix_socket_directories comment The comment said "point it at the data dir" but the code uses the JVM temp dir. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Add Darwin systems to flake devShell outputs Extends supportedSystems with x86_64-darwin and aarch64-darwin so macOS contributors using nix-darwin can enter the same direnv/flake devshell. The NOMAD_PG_TARBALL override path in the postgres scripted test is platform-agnostic, so the same Nix-built tarball workaround works on Darwin too (harmless there since zonky's bundled macOS binaries would also load natively). --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Co-authored-by: Ángel Felipe Blanco Guzmán <novamage@magaran.com>
1 parent 5105d32 commit 60d39d6

4 files changed

Lines changed: 27 additions & 4 deletions

File tree

.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,4 @@ metals.sbt
5151
# Claude Code
5252
.claude/
5353
MEMORY.md
54-
.envrc
5554
.direnv/

flake.nix

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,29 @@
55

66
outputs = { self, nixpkgs }:
77
let
8-
supportedSystems = [ "x86_64-linux" "aarch64-linux" ];
8+
supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
99
forEachSystem = f: builtins.listToAttrs (map (system: {
1010
name = system;
1111
value = f system;
1212
}) supportedSystems);
1313
in {
1414
devShells = forEachSystem (system:
15-
let pkgs = nixpkgs.legacyPackages.${system};
15+
let
16+
pkgs = nixpkgs.legacyPackages.${system};
17+
# Tarball of pkgs.postgresql in the layout zonky's embedded-postgres expects
18+
# (bin/, lib/, share/ at root). Used by the postgres scripted test on NixOS,
19+
# where the bundled generic-Linux binaries can't run.
20+
pgTarball = pkgs.runCommand "nomad-zonky-postgres.txz" {
21+
nativeBuildInputs = [ pkgs.gnutar pkgs.xz ];
22+
} ''
23+
tar -cJf $out -C ${pkgs.postgresql} bin lib share
24+
'';
1625
in {
1726
default = pkgs.mkShell {
1827
buildInputs = with pkgs; [ jdk21 sbt ];
1928
shellHook = ''
2029
export JAVA_HOME="${pkgs.jdk21}"
30+
export NOMAD_PG_TARBALL="${pgTarball}"
2131
'';
2232
};
2333
}

sbt-plugin/src/sbt-test/nomad/clean-and-migrate-postgres/src/main/scala/Main.scala

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,20 @@ import io.zonky.test.db.postgres.embedded.EmbeddedPostgres
33

44
object Main {
55
def main(args: Array[String]): Unit = {
6-
val pg = EmbeddedPostgres.start()
6+
// On NixOS zonky's bundled generic-Linux binaries fail to load. NOMAD_PG_TARBALL
7+
// (set by the flake devshell) overrides the binary source with a tarball of the
8+
// system postgres.
9+
val pg = sys.env.get("NOMAD_PG_TARBALL").filter(_.nonEmpty) match {
10+
case Some(path) =>
11+
// nix-store postgres defaults unix_socket_directories to /run/postgresql,
12+
// which doesn't exist in this sandbox — point it at the JVM temp dir instead.
13+
EmbeddedPostgres
14+
.builder()
15+
.setPgBinaryResolver((_, _) => new java.io.FileInputStream(path))
16+
.setServerConfig("unix_socket_directories", System.getProperty("java.io.tmpdir"))
17+
.start()
18+
case None => EmbeddedPostgres.start()
19+
}
720

821
try {
922
val ds = pg.getPostgresDatabase()

0 commit comments

Comments
 (0)