Skip to content

Track .envrc + make postgres scripted test work on NixOS#5

Merged
NovaMage merged 4 commits into
mainfrom
4-track-envrc-for-devshell
May 11, 2026
Merged

Track .envrc + make postgres scripted test work on NixOS#5
NovaMage merged 4 commits into
mainfrom
4-track-envrc-for-devshell

Conversation

@emsosams
Copy link
Copy Markdown
Collaborator

@emsosams emsosams commented May 6, 2026

Summary

  • Track .envrc (with use flake) so contributors with direnv + nix-direnv get the devshell auto-loaded on cd, rather than authoring the file themselves or running nix develop manually.
  • Fix nomad/clean-and-migrate-postgres scripted test on NixOS. zonky's bundled generic-Linux Postgres binaries fail to load there ("NixOS cannot run dynamically linked executables intended for generic linux environments"). The devshell now exports NOMAD_PG_TARBALL pointing at an XZ tar of pkgs.postgresql (bin, lib, share); the test feeds that through a custom PgBinaryResolver and overrides unix_socket_directories to $TMPDIR (nix postgres defaults to /run/postgresql, which doesn't exist in the sandbox).
  • CI on Ubuntu is unaffected: env var unset → EmbeddedPostgres.start() runs as before.

Closes #4.

Test plan

  • sbt clean scripted doc passes locally on NixOS (22/22 scripted tests + doc).
  • CI passes on Ubuntu (no env var set, default zonky path).

🤖 Generated with Claude Code

emsosams and others added 2 commits May 6, 2026 14:35
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>
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>
@emsosams emsosams requested a review from NovaMage as a code owner May 6, 2026 18:36
Copilot AI review requested due to automatic review settings May 6, 2026 18:36
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Tracks a repo-level .envrc to auto-load the Nix flake devshell via direnv, and adjusts the clean-and-migrate-postgres sbt scripted test to optionally use a Nix-provided Postgres tarball on NixOS (avoiding zonky’s bundled generic Linux binaries).

Changes:

  • Add tracked .envrc (use flake) and stop ignoring it in .gitignore.
  • Extend flake.nix devshell to build/export NOMAD_PG_TARBALL containing a tar.xz of pkgs.postgresql in the layout expected by zonky.
  • Update the scripted test Main.scala to use NOMAD_PG_TARBALL when set and override unix_socket_directories to the JVM temp dir.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

File Description
sbt-plugin/src/sbt-test/nomad/clean-and-migrate-postgres/src/main/scala/Main.scala Adds env-var-controlled Postgres binary override + socket dir override for NixOS compatibility.
flake.nix Builds a Postgres tarball and exports NOMAD_PG_TARBALL in the devshell.
.gitignore Stops ignoring .envrc so it can be tracked.
.envrc Enables direnv+nix-direnv to auto-load the flake devshell.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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>
Copy link
Copy Markdown
Member

NovaMage commented May 10, 2026

Jhin🤖 says: Review finding:

This PR makes the repo flake-driven for everyone by tracking .envrc with use flake, but flake.nix still only declares Linux dev shells (x86_64-linux and aarch64-linux). Since we also have macOS contributors, this is incomplete for main: any Darwin developer using the shared direnv/flake workflow will hit a repo entrypoint that the flake does not currently satisfy.

I validated the NixOS-specific Postgres scripted test change itself and it looks sound; the blocker is portability of the newly shared flake setup. I would either add Darwin outputs in this PR or avoid making .envrc repo-owned until that support is in place.

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).
Copy link
Copy Markdown
Member

Sylas🤖 says: Valid finding — confirmed with @NovaMage that macOS contributors do use this repo via nix-darwin. Fixed in b7f09fe by adding x86_64-darwin and aarch64-darwin to supportedSystems in flake.nix.

The NOMAD_PG_TARBALL override path is platform-agnostic (zonky's setPgBinaryResolver plus unix_socket_directories pointed at the JVM temp dir), so the same Nix-built tarball mechanism works on Darwin too — harmless there since zonky's bundled macOS binaries would also load natively. Verified the Darwin attrs evaluate cleanly from this Linux host (nix eval .#devShells.{x86_64,aarch64}-darwin.default.shellHook --impure --raw).

@NovaMage NovaMage merged commit 60d39d6 into main May 11, 2026
1 check passed
@NovaMage NovaMage deleted the 4-track-envrc-for-devshell branch May 11, 2026 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Track .envrc so devshell auto-loads on cd

3 participants