flake.nix 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. {
  2. description = "CDK Flake";
  3. inputs = {
  4. nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
  5. rust-overlay = {
  6. url = "github:oxalica/rust-overlay";
  7. inputs = {
  8. nixpkgs.follows = "nixpkgs";
  9. };
  10. };
  11. fenix = {
  12. url = "github:nix-community/fenix";
  13. inputs.nixpkgs.follows = "nixpkgs";
  14. inputs.rust-analyzer-src.follows = "";
  15. };
  16. flake-utils.url = "github:numtide/flake-utils";
  17. crane = {
  18. url = "github:ipetkov/crane";
  19. };
  20. };
  21. outputs =
  22. { self
  23. , nixpkgs
  24. , rust-overlay
  25. , flake-utils
  26. , crane
  27. , ...
  28. }@inputs:
  29. flake-utils.lib.eachDefaultSystem (
  30. system:
  31. let
  32. overlays = [ (import rust-overlay) ];
  33. lib = pkgs.lib;
  34. stdenv = pkgs.stdenv;
  35. isDarwin = stdenv.isDarwin;
  36. libsDarwin =
  37. with pkgs;
  38. lib.optionals isDarwin [
  39. # Additional darwin specific inputs can be set here
  40. # Note: Security and SystemConfiguration frameworks are provided by the default SDK
  41. ];
  42. # Dependencies
  43. pkgs = import nixpkgs {
  44. inherit system overlays;
  45. };
  46. # Toolchains
  47. # latest stable
  48. stable_toolchain = pkgs.rust-bin.stable."1.92.0".default.override {
  49. targets = [ "wasm32-unknown-unknown" ]; # wasm
  50. extensions = [
  51. "rustfmt"
  52. "clippy"
  53. "rust-analyzer"
  54. ];
  55. };
  56. # MSRV stable
  57. msrv_toolchain = pkgs.rust-bin.stable."1.85.0".default.override {
  58. targets = [ "wasm32-unknown-unknown" ]; # wasm
  59. extensions = [
  60. "rustfmt"
  61. "clippy"
  62. "rust-analyzer"
  63. ];
  64. };
  65. # Nightly used for formatting
  66. nightly_toolchain = pkgs.rust-bin.selectLatestNightlyWith (
  67. toolchain:
  68. toolchain.default.override {
  69. extensions = [
  70. "rustfmt"
  71. "clippy"
  72. "rust-analyzer"
  73. "rust-src"
  74. ];
  75. targets = [ "wasm32-unknown-unknown" ]; # wasm
  76. }
  77. );
  78. # ========================================
  79. # Crane setup for cached builds
  80. # ========================================
  81. craneLib = (crane.mkLib pkgs).overrideToolchain stable_toolchain;
  82. craneLibMsrv = (crane.mkLib pkgs).overrideToolchain msrv_toolchain;
  83. # Source for crane builds - uses lib.fileset for efficient filtering
  84. # This is much faster than nix-gitignore when large directories (like target/) exist
  85. # because it uses a whitelist approach rather than scanning everything first
  86. src = lib.fileset.toSource {
  87. root = ./.;
  88. fileset = lib.fileset.intersection
  89. (lib.fileset.fromSource (lib.sources.cleanSource ./.))
  90. (lib.fileset.unions [
  91. ./Cargo.toml
  92. ./Cargo.lock
  93. ./Cargo.lock.msrv
  94. ./README.md
  95. ./.cargo
  96. ./crates
  97. ./fuzz
  98. ]);
  99. };
  100. # Source for MSRV builds - uses Cargo.lock.msrv with MSRV-compatible deps
  101. srcMsrv = pkgs.runCommand "cdk-source-msrv" { } ''
  102. cp -r ${src} $out
  103. chmod -R +w $out
  104. cp $out/Cargo.lock.msrv $out/Cargo.lock
  105. '';
  106. # Common args for all Crane builds
  107. commonCraneArgs = {
  108. inherit src;
  109. pname = "cdk";
  110. version = "0.14.0";
  111. nativeBuildInputs = with pkgs; [
  112. pkg-config
  113. protobuf
  114. ];
  115. buildInputs = with pkgs; [
  116. openssl
  117. sqlite
  118. zlib
  119. ] ++ libsDarwin;
  120. # Environment variables
  121. PROTOC = "${pkgs.protobuf}/bin/protoc";
  122. PROTOC_INCLUDE = "${pkgs.protobuf}/include";
  123. };
  124. # Common args for MSRV builds - uses srcMsrv with pinned deps
  125. commonCraneArgsMsrv = commonCraneArgs // {
  126. src = srcMsrv;
  127. };
  128. # Build ALL dependencies once - this is what gets cached by Cachix
  129. # Note: We exclude swagger feature as it tries to download assets during build
  130. workspaceDeps = craneLib.buildDepsOnly (commonCraneArgs // {
  131. pname = "cdk-deps";
  132. # Build deps for workspace - swagger excluded (downloads during build)
  133. cargoExtraArgs = "--workspace";
  134. });
  135. # MSRV dependencies (separate cache due to different toolchain)
  136. workspaceDepsMsrv = craneLibMsrv.buildDepsOnly (commonCraneArgsMsrv // {
  137. pname = "cdk-deps-msrv";
  138. cargoExtraArgs = "--workspace";
  139. });
  140. # Helper function to create clippy checks
  141. mkClippy = name: cargoArgs: craneLib.cargoClippy (commonCraneArgs // {
  142. pname = "cdk-clippy-${name}";
  143. cargoArtifacts = workspaceDeps;
  144. cargoClippyExtraArgs = "${cargoArgs} -- -D warnings";
  145. });
  146. # Helper function to create example checks (compile only, no network access in sandbox)
  147. mkExample = name: craneLib.mkCargoDerivation (commonCraneArgs // {
  148. pname = "cdk-example-${name}";
  149. cargoArtifacts = workspaceDeps;
  150. buildPhaseCargoCommand = "cargo build --example ${name}";
  151. # Examples are compiled but not run (no network in Nix sandbox)
  152. installPhaseCommand = "mkdir -p $out";
  153. });
  154. # Helper function to create example packages (outputs binary for running outside sandbox)
  155. mkExamplePackage = name: craneLib.mkCargoDerivation (commonCraneArgs // {
  156. pname = "cdk-example-${name}";
  157. cargoArtifacts = workspaceDeps;
  158. buildPhaseCargoCommand = "cargo build --release --example ${name}";
  159. installPhaseCommand = ''
  160. mkdir -p $out/bin
  161. cp target/release/examples/${name} $out/bin/
  162. '';
  163. });
  164. # Helper function to create MSRV build checks
  165. mkMsrvBuild = name: cargoArgs: craneLibMsrv.cargoBuild (commonCraneArgsMsrv // {
  166. pname = "cdk-msrv-${name}";
  167. cargoArtifacts = workspaceDepsMsrv;
  168. cargoExtraArgs = cargoArgs;
  169. });
  170. # Helper function to create WASM build checks
  171. # WASM builds don't need native libs like openssl
  172. mkWasmBuild = name: cargoArgs: craneLib.cargoBuild ({
  173. inherit src;
  174. pname = "cdk-wasm-${name}";
  175. version = "0.14.0";
  176. cargoArtifacts = workspaceDeps;
  177. cargoExtraArgs = "${cargoArgs} --target wasm32-unknown-unknown";
  178. # WASM doesn't need native build inputs
  179. nativeBuildInputs = with pkgs; [ pkg-config ];
  180. buildInputs = [ ];
  181. # Disable tests for WASM (can't run in sandbox)
  182. doCheck = false;
  183. });
  184. # Doc tests check
  185. docTests = craneLib.cargoTest (commonCraneArgs // {
  186. pname = "cdk-doc-tests";
  187. cargoArtifacts = workspaceDeps;
  188. cargoTestExtraArgs = "--doc";
  189. });
  190. # Strict docs check - build docs with warnings as errors
  191. # Uses mkCargoDerivation for custom RUSTDOCFLAGS
  192. strictDocs = craneLib.mkCargoDerivation (commonCraneArgs // {
  193. pname = "cdk-strict-docs";
  194. cargoArtifacts = workspaceDeps;
  195. buildPhaseCargoCommand = ''
  196. export RUSTDOCFLAGS="-D warnings"
  197. cargo doc --no-deps \
  198. -p cashu \
  199. -p cdk-common \
  200. -p cdk-sql-common \
  201. -p cdk \
  202. -p cdk-redb \
  203. -p cdk-sqlite \
  204. -p cdk-axum \
  205. -p cdk-cln \
  206. -p cdk-lnd \
  207. -p cdk-lnbits \
  208. -p cdk-fake-wallet \
  209. -p cdk-mint-rpc \
  210. -p cdk-payment-processor \
  211. -p cdk-signatory \
  212. -p cdk-cli \
  213. -p cdk-mintd
  214. '';
  215. installPhaseCommand = "mkdir -p $out";
  216. });
  217. # FFI Python tests
  218. ffiTests = craneLib.mkCargoDerivation (commonCraneArgs // {
  219. pname = "cdk-ffi-tests";
  220. cargoArtifacts = workspaceDeps;
  221. nativeBuildInputs = commonCraneArgs.nativeBuildInputs ++ [
  222. pkgs.python311
  223. ];
  224. buildPhaseCargoCommand = ''
  225. # Build the FFI library
  226. cargo build --release --package cdk-ffi --features postgres
  227. # Generate Python bindings
  228. cargo run --bin uniffi-bindgen generate \
  229. --library target/release/libcdk_ffi.so \
  230. --language python \
  231. --out-dir target/bindings/python
  232. # Copy library to bindings directory
  233. cp target/release/libcdk_ffi.so target/bindings/python/
  234. # Run Python tests
  235. python3 crates/cdk-ffi/tests/test_transactions.py
  236. '';
  237. installPhaseCommand = "mkdir -p $out";
  238. });
  239. # ========================================
  240. # Example definitions - single source of truth
  241. # ========================================
  242. exampleChecks = [
  243. "mint-token"
  244. "melt-token"
  245. "p2pk"
  246. "proof-selection"
  247. "wallet"
  248. ];
  249. # ========================================
  250. # Clippy check definitions - single source of truth
  251. # ========================================
  252. clippyChecks = {
  253. # Core crate: cashu
  254. "cashu" = "-p cashu";
  255. "cashu-no-default" = "-p cashu --no-default-features";
  256. "cashu-wallet" = "-p cashu --no-default-features --features wallet";
  257. "cashu-mint" = "-p cashu --no-default-features --features mint";
  258. "cashu-auth" = "-p cashu --no-default-features --features auth";
  259. # Core crate: cdk-common
  260. "cdk-common" = "-p cdk-common";
  261. "cdk-common-no-default" = "-p cdk-common --no-default-features";
  262. "cdk-common-wallet" = "-p cdk-common --no-default-features --features wallet";
  263. "cdk-common-mint" = "-p cdk-common --no-default-features --features mint";
  264. "cdk-common-auth" = "-p cdk-common --no-default-features --features auth";
  265. # Core crate: cdk
  266. "cdk" = "-p cdk";
  267. "cdk-no-default" = "-p cdk --no-default-features";
  268. "cdk-wallet" = "-p cdk --no-default-features --features wallet";
  269. "cdk-mint" = "-p cdk --no-default-features --features mint";
  270. "cdk-auth" = "-p cdk --no-default-features --features auth";
  271. # SQL crates
  272. "cdk-sql-common" = "-p cdk-sql-common";
  273. "cdk-sql-common-wallet" = "-p cdk-sql-common --no-default-features --features wallet";
  274. "cdk-sql-common-mint" = "-p cdk-sql-common --no-default-features --features mint";
  275. # Database crates
  276. "cdk-redb" = "-p cdk-redb";
  277. "cdk-sqlite" = "-p cdk-sqlite";
  278. "cdk-sqlite-sqlcipher" = "-p cdk-sqlite --features sqlcipher";
  279. # HTTP/API layer
  280. # Note: swagger feature excluded - downloads assets during build, incompatible with Nix sandbox
  281. "cdk-axum" = "-p cdk-axum";
  282. "cdk-axum-no-default" = "-p cdk-axum --no-default-features";
  283. "cdk-axum-redis" = "-p cdk-axum --no-default-features --features redis";
  284. # Lightning backends
  285. "cdk-cln" = "-p cdk-cln";
  286. "cdk-lnd" = "-p cdk-lnd";
  287. "cdk-lnbits" = "-p cdk-lnbits";
  288. "cdk-fake-wallet" = "-p cdk-fake-wallet";
  289. "cdk-payment-processor" = "-p cdk-payment-processor";
  290. "cdk-ldk-node" = "-p cdk-ldk-node";
  291. # Other crates
  292. "cdk-signatory" = "-p cdk-signatory";
  293. "cdk-mint-rpc" = "-p cdk-mint-rpc";
  294. "cdk-prometheus" = "-p cdk-prometheus";
  295. "cdk-ffi" = "-p cdk-ffi";
  296. # Binaries: cdk-cli
  297. "bin-cdk-cli" = "--bin cdk-cli";
  298. "bin-cdk-cli-sqlcipher" = "--bin cdk-cli --features sqlcipher";
  299. "bin-cdk-cli-redb" = "--bin cdk-cli --features redb";
  300. # Binaries: cdk-mintd
  301. "bin-cdk-mintd" = "--bin cdk-mintd";
  302. "bin-cdk-mintd-redis" = "--bin cdk-mintd --features redis";
  303. "bin-cdk-mintd-sqlcipher" = "--bin cdk-mintd --features sqlcipher";
  304. "bin-cdk-mintd-lnd-sqlite" = "--bin cdk-mintd --no-default-features --features lnd,sqlite";
  305. "bin-cdk-mintd-cln-postgres" = "--bin cdk-mintd --no-default-features --features cln,postgres";
  306. "bin-cdk-mintd-lnbits-sqlite" = "--bin cdk-mintd --no-default-features --features lnbits,sqlite";
  307. "bin-cdk-mintd-fakewallet-sqlite" = "--bin cdk-mintd --no-default-features --features fakewallet,sqlite";
  308. "bin-cdk-mintd-grpc-processor-sqlite" = "--bin cdk-mintd --no-default-features --features grpc-processor,sqlite";
  309. "bin-cdk-mintd-management-rpc-lnd-sqlite" = "--bin cdk-mintd --no-default-features --features management-rpc,lnd,sqlite";
  310. "bin-cdk-mintd-cln-sqlite" = "--bin cdk-mintd --no-default-features --features cln,sqlite";
  311. "bin-cdk-mintd-lnd-postgres" = "--bin cdk-mintd --no-default-features --features lnd,postgres";
  312. "bin-cdk-mintd-lnbits-postgres" = "--bin cdk-mintd --no-default-features --features lnbits,postgres";
  313. "bin-cdk-mintd-fakewallet-postgres" = "--bin cdk-mintd --no-default-features --features fakewallet,postgres";
  314. "bin-cdk-mintd-grpc-processor-postgres" = "--bin cdk-mintd --no-default-features --features grpc-processor,postgres";
  315. "bin-cdk-mintd-management-rpc-cln-postgres" = "--bin cdk-mintd --no-default-features --features management-rpc,cln,postgres";
  316. "bin-cdk-mintd-auth-sqlite-fakewallet" = "--bin cdk-mintd --no-default-features --features auth,sqlite,fakewallet";
  317. "bin-cdk-mintd-auth-postgres-lnd" = "--bin cdk-mintd --no-default-features --features auth,postgres,lnd";
  318. # Binaries: cdk-mint-cli
  319. "bin-cdk-mint-cli" = "--bin cdk-mint-cli";
  320. };
  321. # ========================================
  322. # MSRV build check definitions
  323. # ========================================
  324. msrvChecks = {
  325. # Core library with all features (except swagger which breaks MSRV)
  326. "cdk-all-features" = "-p cdk --features \"mint,wallet,auth\"";
  327. # Mintd with all backends, databases, and features (no swagger)
  328. "cdk-mintd-all" = "-p cdk-mintd --no-default-features --features \"cln,lnd,lnbits,fakewallet,ldk-node,grpc-processor,sqlite,postgres,auth,redis,management-rpc\"";
  329. # CLI - default features (excludes redb which breaks MSRV)
  330. "cdk-cli" = "-p cdk-cli";
  331. # Minimal builds to ensure no-default-features works
  332. "cdk-wallet-only" = "-p cdk --no-default-features --features wallet";
  333. };
  334. # ========================================
  335. # WASM build check definitions
  336. # ========================================
  337. wasmChecks = {
  338. "cdk" = "-p cdk";
  339. "cdk-no-default" = "-p cdk --no-default-features";
  340. "cdk-wallet" = "-p cdk --no-default-features --features wallet";
  341. };
  342. # Common inputs
  343. envVars = {
  344. # rust analyzer needs NIX_PATH for some reason.
  345. NIX_PATH = "nixpkgs=${inputs.nixpkgs}";
  346. };
  347. # Override clightning to include mako dependency and fix compilation bug
  348. clightningWithMako = pkgs.clightning.overrideAttrs (oldAttrs: {
  349. nativeBuildInputs = (oldAttrs.nativeBuildInputs or [ ]) ++ [
  350. pkgs.python311Packages.mako
  351. ];
  352. # Disable -Werror to work around multiple compilation bugs in 25.09.2 on macOS
  353. # See: https://github.com/ElementsProject/lightning/issues/7961
  354. env = (oldAttrs.env or { }) // {
  355. NIX_CFLAGS_COMPILE = toString ((oldAttrs.env.NIX_CFLAGS_COMPILE or "") + " -Wno-error");
  356. };
  357. });
  358. buildInputs =
  359. with pkgs;
  360. [
  361. # Add additional build inputs here
  362. git
  363. pkg-config
  364. curl
  365. just
  366. protobuf
  367. nixpkgs-fmt
  368. typos
  369. lnd
  370. clightningWithMako
  371. bitcoind
  372. sqlx-cli
  373. mprocs
  374. cargo-outdated
  375. cargo-mutants
  376. cargo-fuzz
  377. # Needed for github ci
  378. libz
  379. ]
  380. ++ libsDarwin;
  381. # PostgreSQL configuration
  382. postgresConf = {
  383. pgUser = "cdk_user";
  384. pgPassword = "cdk_password";
  385. pgDatabase = "cdk_mint";
  386. pgPort = "5432";
  387. };
  388. # Script to start PostgreSQL
  389. startPostgres = pkgs.writeShellScriptBin "start-postgres" ''
  390. set -e
  391. PGDATA="$PWD/.pg_data"
  392. PGPORT="${postgresConf.pgPort}"
  393. PGUSER="${postgresConf.pgUser}"
  394. PGPASSWORD="${postgresConf.pgPassword}"
  395. PGDATABASE="${postgresConf.pgDatabase}"
  396. # Stop any existing instance first
  397. if [ -d "$PGDATA" ] && ${pkgs.postgresql_16}/bin/pg_ctl -D "$PGDATA" status > /dev/null 2>&1; then
  398. echo "Stopping existing PostgreSQL instance..."
  399. ${pkgs.postgresql_16}/bin/pg_ctl -D "$PGDATA" stop > /dev/null 2>&1
  400. fi
  401. if [ ! -d "$PGDATA" ]; then
  402. echo "Initializing PostgreSQL database..."
  403. ${pkgs.postgresql_16}/bin/initdb -D "$PGDATA" --auth=trust --no-locale --encoding=UTF8
  404. # Configure PostgreSQL
  405. echo "listen_addresses = 'localhost'" >> "$PGDATA/postgresql.conf"
  406. echo "port = $PGPORT" >> "$PGDATA/postgresql.conf"
  407. echo "unix_socket_directories = '$PGDATA'" >> "$PGDATA/postgresql.conf"
  408. # Start temporarily to create user and database
  409. ${pkgs.postgresql_16}/bin/pg_ctl -D "$PGDATA" -l "$PGDATA/logfile" start
  410. sleep 2
  411. # Create user and database
  412. ${pkgs.postgresql_16}/bin/createuser -h localhost -p $PGPORT -s "$PGUSER" || true
  413. ${pkgs.postgresql_16}/bin/psql -h localhost -p $PGPORT -c "ALTER USER $PGUSER WITH PASSWORD '$PGPASSWORD';" postgres
  414. ${pkgs.postgresql_16}/bin/createdb -h localhost -p $PGPORT -O "$PGUSER" "$PGDATABASE" || true
  415. ${pkgs.postgresql_16}/bin/pg_ctl -D "$PGDATA" stop
  416. echo "PostgreSQL initialized."
  417. fi
  418. echo "Starting PostgreSQL on port $PGPORT..."
  419. ${pkgs.postgresql_16}/bin/pg_ctl -D "$PGDATA" -l "$PGDATA/logfile" start
  420. echo "PostgreSQL started. Connection URL: postgresql://$PGUSER:$PGPASSWORD@localhost:$PGPORT/$PGDATABASE"
  421. '';
  422. # Script to stop PostgreSQL
  423. stopPostgres = pkgs.writeShellScriptBin "stop-postgres" ''
  424. PGDATA="$PWD/.pg_data"
  425. if [ -d "$PGDATA" ]; then
  426. echo "Stopping PostgreSQL..."
  427. ${pkgs.postgresql_16}/bin/pg_ctl -D "$PGDATA" stop || echo "PostgreSQL was not running."
  428. else
  429. echo "No PostgreSQL data directory found."
  430. fi
  431. '';
  432. # Script to check PostgreSQL status
  433. pgStatus = pkgs.writeShellScriptBin "pg-status" ''
  434. PGDATA="$PWD/.pg_data"
  435. if [ -d "$PGDATA" ]; then
  436. ${pkgs.postgresql_16}/bin/pg_ctl -D "$PGDATA" status
  437. else
  438. echo "No PostgreSQL data directory found. Run 'start-postgres' first."
  439. fi
  440. '';
  441. # Script to connect to PostgreSQL
  442. pgConnect = pkgs.writeShellScriptBin "pg-connect" ''
  443. ${pkgs.postgresql_16}/bin/psql "postgresql://${postgresConf.pgUser}:${postgresConf.pgPassword}@localhost:${postgresConf.pgPort}/${postgresConf.pgDatabase}"
  444. '';
  445. # Common arguments can be set here to avoid repeating them later
  446. nativeBuildInputs = [
  447. #Add additional build inputs here
  448. ]
  449. ++ lib.optionals isDarwin [
  450. # Additional darwin specific native inputs can be set here
  451. ];
  452. in
  453. {
  454. # Expose deps for explicit cache warming
  455. packages = {
  456. deps = workspaceDeps;
  457. deps-msrv = workspaceDepsMsrv;
  458. }
  459. # Example packages (binaries that can be run outside sandbox with network access)
  460. // (builtins.listToAttrs (map (name: { name = "example-${name}"; value = mkExamplePackage name; }) exampleChecks));
  461. checks =
  462. # Generate clippy checks from clippyChecks attrset
  463. (builtins.mapAttrs (name: args: mkClippy name args) clippyChecks)
  464. # Generate MSRV build checks (prefixed with msrv-)
  465. // (builtins.listToAttrs (map (name: { name = "msrv-${name}"; value = mkMsrvBuild name msrvChecks.${name}; }) (builtins.attrNames msrvChecks)))
  466. # Generate WASM build checks (prefixed with wasm-)
  467. // (builtins.listToAttrs (map (name: { name = "wasm-${name}"; value = mkWasmBuild name wasmChecks.${name}; }) (builtins.attrNames wasmChecks)))
  468. # Generate example checks from exampleChecks list
  469. // (builtins.listToAttrs (map (name: { name = "example-${name}"; value = mkExample name; }) exampleChecks))
  470. // {
  471. # Doc tests
  472. doc-tests = docTests;
  473. # Strict docs check
  474. strict-docs = strictDocs;
  475. # FFI Python tests
  476. ffi-tests = ffiTests;
  477. };
  478. devShells =
  479. let
  480. # devShells
  481. msrv = pkgs.mkShell (
  482. {
  483. shellHook = "
  484. cargo update
  485. cargo update home --precise 0.5.11
  486. cargo update typed-index-collections --precise 3.3.0
  487. ";
  488. buildInputs = buildInputs ++ [ msrv_toolchain ];
  489. inherit nativeBuildInputs;
  490. }
  491. // envVars
  492. );
  493. stable = pkgs.mkShell (
  494. {
  495. shellHook = ''
  496. # Needed for github ci
  497. export LD_LIBRARY_PATH=${
  498. pkgs.lib.makeLibraryPath [
  499. pkgs.zlib
  500. ]
  501. }:$LD_LIBRARY_PATH
  502. # PostgreSQL environment variables
  503. export CDK_MINTD_DATABASE_URL="postgresql://${postgresConf.pgUser}:${postgresConf.pgPassword}@localhost:${postgresConf.pgPort}/${postgresConf.pgDatabase}"
  504. echo ""
  505. echo "PostgreSQL commands available:"
  506. echo " start-postgres - Initialize and start PostgreSQL"
  507. echo " stop-postgres - Stop PostgreSQL (run before exiting)"
  508. echo " pg-status - Check PostgreSQL status"
  509. echo " pg-connect - Connect to PostgreSQL with psql"
  510. echo ""
  511. '';
  512. buildInputs = buildInputs ++ [
  513. stable_toolchain
  514. pkgs.postgresql_16
  515. startPostgres
  516. stopPostgres
  517. pgStatus
  518. pgConnect
  519. ];
  520. inherit nativeBuildInputs;
  521. }
  522. // envVars
  523. );
  524. nightly = pkgs.mkShell (
  525. {
  526. shellHook = ''
  527. # Needed for github ci
  528. export LD_LIBRARY_PATH=${
  529. pkgs.lib.makeLibraryPath [
  530. pkgs.zlib
  531. ]
  532. }:$LD_LIBRARY_PATH
  533. # PostgreSQL environment variables
  534. export CDK_MINTD_DATABASE_URL="postgresql://${postgresConf.pgUser}:${postgresConf.pgPassword}@localhost:${postgresConf.pgPort}/${postgresConf.pgDatabase}"
  535. echo ""
  536. echo "PostgreSQL commands available:"
  537. echo " start-postgres - Initialize and start PostgreSQL"
  538. echo " stop-postgres - Stop PostgreSQL (run before exiting)"
  539. echo " pg-status - Check PostgreSQL status"
  540. echo " pg-connect - Connect to PostgreSQL with psql"
  541. echo ""
  542. '';
  543. buildInputs = buildInputs ++ [
  544. nightly_toolchain
  545. pkgs.postgresql_16
  546. startPostgres
  547. stopPostgres
  548. pgStatus
  549. pgConnect
  550. ];
  551. inherit nativeBuildInputs;
  552. }
  553. // envVars
  554. );
  555. # Shell with Docker for integration tests
  556. integration = pkgs.mkShell (
  557. {
  558. shellHook = ''
  559. # Ensure Docker is available
  560. if ! command -v docker &> /dev/null; then
  561. echo "Docker is not installed or not in PATH"
  562. echo "Please install Docker to run integration tests"
  563. exit 1
  564. fi
  565. echo "Docker is available at $(which docker)"
  566. echo "Docker version: $(docker --version)"
  567. '';
  568. buildInputs = buildInputs ++ [
  569. stable_toolchain
  570. pkgs.docker-client
  571. pkgs.python311
  572. ];
  573. inherit nativeBuildInputs;
  574. }
  575. // envVars
  576. );
  577. # Shell for FFI development (Python bindings)
  578. ffi = pkgs.mkShell (
  579. {
  580. shellHook = ''
  581. echo "FFI development shell"
  582. echo " just ffi-test - Run Python FFI tests"
  583. echo " just ffi-dev-python - Launch Python REPL with CDK FFI"
  584. '';
  585. buildInputs = buildInputs ++ [
  586. stable_toolchain
  587. pkgs.python311
  588. ];
  589. inherit nativeBuildInputs;
  590. }
  591. // envVars
  592. );
  593. in
  594. {
  595. inherit
  596. msrv
  597. stable
  598. nightly
  599. integration
  600. ffi
  601. ;
  602. default = stable;
  603. };
  604. }
  605. );
  606. }