flake.nix 26 KB

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