An easy-to-host PDS on the ATProtocol, MacOS. Grandma-approved.

feat(MM-65): add nix build output for relay binary using crane #3

merged opened by malpercio.dev targeting main from malpercio/mm-65-nix-flake-relay-build-output

Summary#

  • Adds nix build .#relay (and nix build via default) to flake.nix
  • Uses crane's two-phase build (buildDepsOnlybuildPackage) for cached dependency derivations
  • Passes sqlite + pkg-config so rusqlite links correctly; LIBSQLITE3_SYS_USE_PKG_CONFIG=1 mirrors the devenv setup
  • Pins crane via flake.lock

Test plan#

  • nix build .#relay --accept-flake-config completes without error
  • ./result/bin/relay runs without crashing (prints relay starting)
  • nix build --accept-flake-config (default) also resolves to the relay binary
  • Dev shell still works: nix develop --impure --accept-flake-config

Closes MM-65

Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:web:malpercio.dev/sh.tangled.repo.pull/3mgjgjj65hz22
+49 -1
Interdiff #0 #1
.envrc

This file has not been changed.

CLAUDE.md

This file has not been changed.

docs/design-plans/2026-03-07-MM-64.md

This file has not been changed.

docs/implementation-plans/2026-03-07-MM-64/phase_01.md

This file has not been changed.

docs/implementation-plans/2026-03-07-MM-64/phase_02.md

This file has not been changed.

docs/implementation-plans/2026-03-07-MM-64/test-requirements.md

This file has not been changed.

docs/v01-issue-plan.md

This file has not been changed.

+16
flake.lock
··· 33 "type": "github" 34 } 35 }, 36 "devenv": { 37 "inputs": { 38 "cachix": "cachix", ··· 298 }, 299 "root": { 300 "inputs": { 301 "devenv": "devenv", 302 "nixpkgs": "nixpkgs_2", 303 "rust-overlay": "rust-overlay",
··· 33 "type": "github" 34 } 35 }, 36 + "crane": { 37 + "locked": { 38 + "lastModified": 1772560058, 39 + "narHash": "sha256-NuVKdMBJldwUXgghYpzIWJdfeB7ccsu1CC7B+NfSoZ8=", 40 + "owner": "ipetkov", 41 + "repo": "crane", 42 + "rev": "db590d9286ed5ce22017541e36132eab4e8b3045", 43 + "type": "github" 44 + }, 45 + "original": { 46 + "owner": "ipetkov", 47 + "repo": "crane", 48 + "type": "github" 49 + } 50 + }, 51 "devenv": { 52 "inputs": { 53 "cachix": "cachix", ··· 313 }, 314 "root": { 315 "inputs": { 316 + "crane": "crane", 317 "devenv": "devenv", 318 "nixpkgs": "nixpkgs_2", 319 "rust-overlay": "rust-overlay",
+33 -1
flake.nix
··· 13 systems.url = "github:nix-systems/default"; 14 rust-overlay.url = "github:oxalica/rust-overlay"; 15 rust-overlay.inputs = { nixpkgs.follows = "nixpkgs"; }; 16 }; 17 18 - outputs = { self, nixpkgs, devenv, systems, rust-overlay, ... } @ inputs: 19 let 20 forEachSystem = f: nixpkgs.lib.genAttrs (import systems) f; 21 in { 22 devShells = forEachSystem (system: 23 let 24 pkgs = nixpkgs.legacyPackages.${system};
··· 13 systems.url = "github:nix-systems/default"; 14 rust-overlay.url = "github:oxalica/rust-overlay"; 15 rust-overlay.inputs = { nixpkgs.follows = "nixpkgs"; }; 16 + crane.url = "github:ipetkov/crane"; 17 }; 18 19 + outputs = { self, nixpkgs, devenv, systems, rust-overlay, crane, ... } @ inputs: 20 let 21 forEachSystem = f: nixpkgs.lib.genAttrs (import systems) f; 22 in { 23 + packages = forEachSystem (system: 24 + let 25 + pkgs = import nixpkgs { 26 + inherit system; 27 + overlays = [ (import rust-overlay) ]; 28 + }; 29 + rustToolchain = pkgs.rust-bin.stable.latest.default; 30 + craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain; 31 + 32 + commonArgs = { 33 + src = craneLib.cleanCargoSource ./.; 34 + pname = "relay"; 35 + strictDeps = true; 36 + nativeBuildInputs = [ pkgs.pkg-config ]; 37 + buildInputs = [ pkgs.sqlite ]; 38 + LIBSQLITE3_SYS_USE_PKG_CONFIG = "1"; 39 + }; 40 + 41 + # Build deps separately so they're cached when only source changes. 42 + cargoArtifacts = craneLib.buildDepsOnly commonArgs; 43 + 44 + relay = craneLib.buildPackage (commonArgs // { 45 + inherit cargoArtifacts; 46 + cargoExtraArgs = "--package relay"; 47 + }); 48 + in { 49 + inherit relay; 50 + default = relay; 51 + } 52 + ); 53 + 54 devShells = forEachSystem (system: 55 let 56 pkgs = nixpkgs.legacyPackages.${system};

History

3 rounds 0 comments
sign up or login to add to the discussion
3 commits
expand
fix(envrc): pass --impure to fix direnv shell activation; add docs
feat(MM-65): add nix build output for relay binary using crane
fix(MM-65): address PR review — toolchain parity and CLAUDE.md
expand 0 comments
pull request successfully merged
2 commits
expand
fix(envrc): pass --impure to fix direnv shell activation; add docs
feat(MM-65): add nix build output for relay binary using crane
expand 0 comments
1 commit
expand
fix(envrc): pass --impure to fix direnv shell activation; add docs
expand 0 comments