flake.nix 26 KB

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