diff --git a/devenv.lock b/devenv.lock index 119e62f..6ad7695 100644 --- a/devenv.lock +++ b/devenv.lock @@ -1,5 +1,57 @@ { "nodes": { + "cachix": { + "inputs": { + "devenv": [ + "crate2nix" + ], + "flake-compat": [ + "crate2nix" + ], + "git-hooks": "git-hooks", + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1767714506, + "narHash": "sha256-WaTs0t1CxhgxbIuvQ97OFhDTVUGd1HA+KzLZUZBhe0s=", + "owner": "cachix", + "repo": "cachix", + "rev": "894c649f0daaa38bbcfb21de64be47dfa7cd0ec9", + "type": "github" + }, + "original": { + "owner": "cachix", + "ref": "latest", + "repo": "cachix", + "type": "github" + } + }, + "crate2nix": { + "inputs": { + "cachix": "cachix", + "devshell": "devshell", + "flake-compat": "flake-compat", + "flake-parts": "flake-parts", + "nix-test-runner": "nix-test-runner", + "nixpkgs": [ + "nixpkgs" + ], + "pre-commit-hooks": "pre-commit-hooks" + }, + "locked": { + "lastModified": 1782759041, + "narHash": "sha256-2577vxyoBa8+ZRiXr3CuPtOuEtPRYsFPSZuEc/KI/80=", + "owner": "nix-community", + "repo": "crate2nix", + "rev": "5e1ecfd2d15b34ec90c2e51fdffbe8116595a767", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "crate2nix", + "type": "github" + } + }, "devenv": { "locked": { "dir": "src/modules", @@ -17,7 +69,42 @@ "type": "github" } }, + "devshell": { + "inputs": { + "nixpkgs": [ + "crate2nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1768818222, + "narHash": "sha256-460jc0+CZfyaO8+w8JNtlClB2n4ui1RbHfPTLkpwhU8=", + "owner": "numtide", + "repo": "devshell", + "rev": "255a2b1725a20d060f566e4755dbf571bbbb5f76", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", + "type": "github" + } + }, "flake-compat": { + "locked": { + "lastModified": 1733328505, + "narHash": "sha256-NeCCThCEP3eCl2l/+27kNNK7QrwZB1IJCrXfrbv5oqU=", + "rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec", + "revCount": 69, + "type": "tarball", + "url": "https://api.flakehub.com/f/pinned/edolstra/flake-compat/1.1.0/01948eb7-9cba-704f-bbf3-3fa956735b52/source.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz" + } + }, + "flake-compat_2": { "flake": false, "locked": { "lastModified": 1767039857, @@ -33,9 +120,58 @@ "type": "github" } }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": [ + "crate2nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1768135262, + "narHash": "sha256-PVvu7OqHBGWN16zSi6tEmPwwHQ4rLPU9Plvs8/1TUBY=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "80daad04eddbbf5a4d883996a73f3f542fa437ac", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, "git-hooks": { "inputs": { - "flake-compat": "flake-compat", + "flake-compat": [ + "crate2nix", + "cachix", + "flake-compat" + ], + "gitignore": "gitignore", + "nixpkgs": [ + "crate2nix", + "cachix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1765404074, + "narHash": "sha256-+ZDU2d+vzWkEJiqprvV5PR26DVFN2vgddwG5SnPZcUM=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "2d6f58930fbcd82f6f9fd59fb6d13e37684ca529", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, + "git-hooks_2": { + "inputs": { + "flake-compat": "flake-compat_2", "nixpkgs": [ "nixpkgs" ] @@ -54,22 +190,80 @@ "type": "github" } }, - "nixpkgs": { + "gitignore": { "inputs": { - "nixpkgs-src": "nixpkgs-src" + "nixpkgs": [ + "crate2nix", + "cachix", + "git-hooks", + "nixpkgs" + ] }, "locked": { - "lastModified": 1782924808, - "narHash": "sha256-tn2ahNv3ZNXyVHdPx/uw+N0xa7YSMtXUr6OEvu+s8ng=", - "owner": "cachix", - "repo": "devenv-nixpkgs", - "rev": "e2c881cb8d5f1cac6cef9d71f0d450a55691b999", + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", "type": "github" }, "original": { - "owner": "cachix", - "ref": "rolling", - "repo": "devenv-nixpkgs", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "gitignore_2": { + "inputs": { + "nixpkgs": [ + "crate2nix", + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "nix-test-runner": { + "flake": false, + "locked": { + "lastModified": 1588761593, + "narHash": "sha256-FKJykltAN/g3eIceJl4SfDnnyuH2jHImhMrXS2KvGIs=", + "owner": "stoeffel", + "repo": "nix-test-runner", + "rev": "c45d45b11ecef3eb9d834c3b6304c05c49b06ca2", + "type": "github" + }, + "original": { + "owner": "stoeffel", + "repo": "nix-test-runner", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1765186076, + "narHash": "sha256-hM20uyap1a0M9d344I692r+ik4gTMyj60cQWO+hAYP8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "addf7cf5f383a3101ecfba091b98d0a1263dc9b8", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", "type": "github" } }, @@ -90,11 +284,57 @@ "type": "github" } }, + "nixpkgs_2": { + "inputs": { + "nixpkgs-src": "nixpkgs-src" + }, + "locked": { + "lastModified": 1782924808, + "narHash": "sha256-tn2ahNv3ZNXyVHdPx/uw+N0xa7YSMtXUr6OEvu+s8ng=", + "owner": "cachix", + "repo": "devenv-nixpkgs", + "rev": "e2c881cb8d5f1cac6cef9d71f0d450a55691b999", + "type": "github" + }, + "original": { + "owner": "cachix", + "ref": "rolling", + "repo": "devenv-nixpkgs", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": [ + "crate2nix", + "flake-compat" + ], + "gitignore": "gitignore_2", + "nixpkgs": [ + "crate2nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1769069492, + "narHash": "sha256-Efs3VUPelRduf3PpfPP2ovEB4CXT7vHf8W+xc49RL/U=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "a1ef738813b15cf8ec759bdff5761b027e3e1d23", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, "root": { "inputs": { + "crate2nix": "crate2nix", "devenv": "devenv", - "git-hooks": "git-hooks", - "nixpkgs": "nixpkgs", + "git-hooks": "git-hooks_2", + "nixpkgs": "nixpkgs_2", "treefmt-nix": "treefmt-nix" } }, diff --git a/devenv.nix b/devenv.nix index 3eb4308..a63f4c5 100644 --- a/devenv.nix +++ b/devenv.nix @@ -6,6 +6,30 @@ ... }: +let + # devenv's `languages.rust.import` only builds single root-package crates + # (it hardcodes `cargoNix.rootCrate.build`). tora is a virtual workspace with + # no root package, so we drive crate2nix directly and select the `torad` member + # out of `workspaceMembers`. src = ./. gives crate2nix the whole workspace, so + # torad's path-dependency on ../proto (tora-proto) resolves. + crate2nixTools = pkgs.callPackage "${inputs.crate2nix}/tools.nix" { }; + cargoNix = + pkgs.callPackage + (crate2nixTools.generatedCargoNix { + name = "tora"; + src = ./.; + }) + { + # Build with the toolchain configured for this dev environment, + # matching what languages.rust.import does internally. + buildRustCrateForPkgs = + _: + pkgs.buildRustCrate.override { + rustc = config.languages.rust.toolchainPackage; + cargo = config.languages.rust.toolchainPackage; + }; + }; +in { languages.rust.enable = true; git-hooks.hooks = { @@ -57,13 +81,13 @@ processes.torad = { exec = '' - cargo run -p torad -- --socket "$TORAD_SOCKET" --pid-file "$TORAD_PID_FILE" + ${config.outputs.torad}/bin/torad --socket "$TORAD_SOCKET" --pid-file "$TORAD_PID_FILE" ''; # Waits for postgres's own readiness probe (pg_isready + SELECT 1), not just process start. after = [ "devenv:processes:postgres" ]; }; outputs = { - tora = config.languages.rust.import ./. { }; + torad = cargoNix.workspaceMembers.torad.build; }; } diff --git a/devenv.yaml b/devenv.yaml index ee5a179..528758b 100644 --- a/devenv.yaml +++ b/devenv.yaml @@ -1,4 +1,9 @@ inputs: + crate2nix: + url: github:nix-community/crate2nix + inputs: + nixpkgs: + follows: nixpkgs git-hooks: url: github:cachix/git-hooks.nix inputs: