flake.nix 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  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 darwin 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. "cashu-auth" = "-p cashu --no-default-features --features auth";
  277. # Core crate: cdk-common
  278. "cdk-common" = "-p cdk-common";
  279. "cdk-common-no-default" = "-p cdk-common --no-default-features";
  280. "cdk-common-wallet" = "-p cdk-common --no-default-features --features wallet";
  281. "cdk-common-mint" = "-p cdk-common --no-default-features --features mint";
  282. "cdk-common-auth" = "-p cdk-common --no-default-features --features auth";
  283. # Core crate: cdk
  284. "cdk" = "-p cdk";
  285. "cdk-no-default" = "-p cdk --no-default-features";
  286. "cdk-wallet" = "-p cdk --no-default-features --features wallet";
  287. "cdk-mint" = "-p cdk --no-default-features --features mint";
  288. "cdk-auth" = "-p cdk --no-default-features --features auth";
  289. # SQL crates
  290. "cdk-sql-common" = "-p cdk-sql-common";
  291. "cdk-sql-common-wallet" = "-p cdk-sql-common --no-default-features --features wallet";
  292. "cdk-sql-common-mint" = "-p cdk-sql-common --no-default-features --features mint";
  293. # Database crates
  294. "cdk-redb" = "-p cdk-redb";
  295. "cdk-sqlite" = "-p cdk-sqlite";
  296. "cdk-sqlite-sqlcipher" = "-p cdk-sqlite --features sqlcipher";
  297. # HTTP/API layer
  298. # Note: swagger feature excluded - downloads assets during build, incompatible with Nix sandbox
  299. "cdk-axum" = "-p cdk-axum";
  300. "cdk-axum-no-default" = "-p cdk-axum --no-default-features";
  301. "cdk-axum-redis" = "-p cdk-axum --no-default-features --features redis";
  302. # Lightning backends
  303. "cdk-cln" = "-p cdk-cln";
  304. "cdk-lnd" = "-p cdk-lnd";
  305. "cdk-lnbits" = "-p cdk-lnbits";
  306. "cdk-fake-wallet" = "-p cdk-fake-wallet";
  307. "cdk-payment-processor" = "-p cdk-payment-processor";
  308. "cdk-ldk-node" = "-p cdk-ldk-node";
  309. # Other crates
  310. "cdk-signatory" = "-p cdk-signatory";
  311. "cdk-mint-rpc" = "-p cdk-mint-rpc";
  312. "cdk-prometheus" = "-p cdk-prometheus";
  313. "cdk-ffi" = "-p cdk-ffi";
  314. "cdk-npubcash" = "-p cdk-npubcash";
  315. # Binaries: cdk-cli
  316. "cdk-cli" = "-p cdk-cli";
  317. "cdk-cli-sqlcipher" = "-p cdk-cli --features sqlcipher";
  318. "cdk-cli-redb" = "-p cdk-cli --features redb";
  319. # Binaries: cdk-mintd
  320. "cdk-mintd" = "-p cdk-mintd";
  321. "cdk-mintd-redis" = "-p cdk-mintd --features redis";
  322. "cdk-mintd-sqlcipher" = "-p cdk-mintd --features sqlcipher";
  323. "cdk-mintd-lnd-sqlite" = "-p cdk-mintd --no-default-features --features lnd,sqlite";
  324. "cdk-mintd-cln-postgres" = "-p cdk-mintd --no-default-features --features cln,postgres";
  325. "cdk-mintd-lnbits-sqlite" = "-p cdk-mintd --no-default-features --features lnbits,sqlite";
  326. "cdk-mintd-fakewallet-sqlite" = "-p cdk-mintd --no-default-features --features fakewallet,sqlite";
  327. "cdk-mintd-grpc-processor-sqlite" = "-p cdk-mintd --no-default-features --features grpc-processor,sqlite";
  328. "cdk-mintd-management-rpc-lnd-sqlite" = "-p cdk-mintd --no-default-features --features management-rpc,lnd,sqlite";
  329. "cdk-mintd-cln-sqlite" = "-p cdk-mintd --no-default-features --features cln,sqlite";
  330. "cdk-mintd-lnd-postgres" = "-p cdk-mintd --no-default-features --features lnd,postgres";
  331. "cdk-mintd-lnbits-postgres" = "-p cdk-mintd --no-default-features --features lnbits,postgres";
  332. "cdk-mintd-fakewallet-postgres" = "-p cdk-mintd --no-default-features --features fakewallet,postgres";
  333. "cdk-mintd-grpc-processor-postgres" = "-p cdk-mintd --no-default-features --features grpc-processor,postgres";
  334. "cdk-mintd-management-rpc-cln-postgres" = "-p cdk-mintd --no-default-features --features management-rpc,cln,postgres";
  335. "cdk-mintd-auth-sqlite-fakewallet" = "-p cdk-mintd --no-default-features --features auth,sqlite,fakewallet";
  336. "cdk-mintd-auth-postgres-lnd" = "-p cdk-mintd --no-default-features --features auth,postgres,lnd";
  337. # Binaries: cdk-mint-cli (binary name, package is cdk-mint-rpc)
  338. "cdk-mint-cli" = "-p cdk-mint-rpc";
  339. };
  340. # ========================================
  341. # MSRV build check definitions
  342. # ========================================
  343. msrvChecks = {
  344. # Core library with all features (except swagger which breaks MSRV)
  345. "cdk-all-features" = "-p cdk --features \"mint,wallet,auth\"";
  346. # Mintd with all backends, databases, and features (no swagger)
  347. "cdk-mintd-all" = "-p cdk-mintd --no-default-features --features \"cln,lnd,lnbits,fakewallet,ldk-node,grpc-processor,sqlite,postgres,auth,redis,management-rpc\"";
  348. # CLI - default features (excludes redb which breaks MSRV)
  349. "cdk-cli" = "-p cdk-cli";
  350. # Minimal builds to ensure no-default-features works
  351. "cdk-wallet-only" = "-p cdk --no-default-features --features wallet";
  352. };
  353. # ========================================
  354. # WASM build check definitions
  355. # ========================================
  356. wasmChecks = {
  357. "cdk" = "-p cdk";
  358. "cdk-no-default" = "-p cdk --no-default-features";
  359. "cdk-wallet" = "-p cdk --no-default-features --features wallet";
  360. };
  361. # Common inputs
  362. envVars = {
  363. # rust analyzer needs NIX_PATH for some reason.
  364. NIX_PATH = "nixpkgs=${inputs.nixpkgs}";
  365. };
  366. # Override clightning to include mako dependency and fix compilation bug
  367. clightningWithMako = pkgs.clightning.overrideAttrs (oldAttrs: {
  368. nativeBuildInputs = (oldAttrs.nativeBuildInputs or [ ]) ++ [
  369. pkgs.python311Packages.mako
  370. ];
  371. # Disable -Werror to work around multiple compilation bugs in 25.09.2 on macOS
  372. # See: https://github.com/ElementsProject/lightning/issues/7961
  373. env = (oldAttrs.env or { }) // {
  374. NIX_CFLAGS_COMPILE = toString ((oldAttrs.env.NIX_CFLAGS_COMPILE or "") + " -Wno-error");
  375. };
  376. });
  377. buildInputs =
  378. with pkgs;
  379. [
  380. # Add additional build inputs here
  381. git
  382. pkg-config
  383. curl
  384. just
  385. protobuf
  386. nixpkgs-fmt
  387. typos
  388. lnd
  389. clightningWithMako
  390. bitcoind
  391. sqlx-cli
  392. mprocs
  393. cargo-outdated
  394. cargo-mutants
  395. cargo-fuzz
  396. # Needed for github ci
  397. libz
  398. ]
  399. ++ libsDarwin;
  400. # PostgreSQL configuration
  401. postgresConf = {
  402. pgUser = "cdk_user";
  403. pgPassword = "cdk_password";
  404. pgDatabase = "cdk_mint";
  405. pgPort = "5432";
  406. };
  407. # Script to start PostgreSQL
  408. startPostgres = pkgs.writeShellScriptBin "start-postgres" ''
  409. set -e
  410. PGDATA="$PWD/.pg_data"
  411. PGPORT="${postgresConf.pgPort}"
  412. PGUSER="${postgresConf.pgUser}"
  413. PGPASSWORD="${postgresConf.pgPassword}"
  414. PGDATABASE="${postgresConf.pgDatabase}"
  415. # Stop any existing instance first
  416. if [ -d "$PGDATA" ] && ${pkgs.postgresql_16}/bin/pg_ctl -D "$PGDATA" status > /dev/null 2>&1; then
  417. echo "Stopping existing PostgreSQL instance..."
  418. ${pkgs.postgresql_16}/bin/pg_ctl -D "$PGDATA" stop > /dev/null 2>&1
  419. fi
  420. if [ ! -d "$PGDATA" ]; then
  421. echo "Initializing PostgreSQL database..."
  422. ${pkgs.postgresql_16}/bin/initdb -D "$PGDATA" --auth=trust --no-locale --encoding=UTF8
  423. # Configure PostgreSQL
  424. echo "listen_addresses = 'localhost'" >> "$PGDATA/postgresql.conf"
  425. echo "port = $PGPORT" >> "$PGDATA/postgresql.conf"
  426. echo "unix_socket_directories = '$PGDATA'" >> "$PGDATA/postgresql.conf"
  427. # Start temporarily to create user and database
  428. ${pkgs.postgresql_16}/bin/pg_ctl -D "$PGDATA" -l "$PGDATA/logfile" start
  429. sleep 2
  430. # Create user and database
  431. ${pkgs.postgresql_16}/bin/createuser -h localhost -p $PGPORT -s "$PGUSER" || true
  432. ${pkgs.postgresql_16}/bin/psql -h localhost -p $PGPORT -c "ALTER USER $PGUSER WITH PASSWORD '$PGPASSWORD';" postgres
  433. ${pkgs.postgresql_16}/bin/createdb -h localhost -p $PGPORT -O "$PGUSER" "$PGDATABASE" || true
  434. ${pkgs.postgresql_16}/bin/pg_ctl -D "$PGDATA" stop
  435. echo "PostgreSQL initialized."
  436. fi
  437. echo "Starting PostgreSQL on port $PGPORT..."
  438. ${pkgs.postgresql_16}/bin/pg_ctl -D "$PGDATA" -l "$PGDATA/logfile" start
  439. echo "PostgreSQL started. Connection URL: postgresql://$PGUSER:$PGPASSWORD@localhost:$PGPORT/$PGDATABASE"
  440. '';
  441. # Script to stop PostgreSQL
  442. stopPostgres = pkgs.writeShellScriptBin "stop-postgres" ''
  443. PGDATA="$PWD/.pg_data"
  444. if [ -d "$PGDATA" ]; then
  445. echo "Stopping PostgreSQL..."
  446. ${pkgs.postgresql_16}/bin/pg_ctl -D "$PGDATA" stop || echo "PostgreSQL was not running."
  447. else
  448. echo "No PostgreSQL data directory found."
  449. fi
  450. '';
  451. # Script to check PostgreSQL status
  452. pgStatus = pkgs.writeShellScriptBin "pg-status" ''
  453. PGDATA="$PWD/.pg_data"
  454. if [ -d "$PGDATA" ]; then
  455. ${pkgs.postgresql_16}/bin/pg_ctl -D "$PGDATA" status
  456. else
  457. echo "No PostgreSQL data directory found. Run 'start-postgres' first."
  458. fi
  459. '';
  460. # Script to connect to PostgreSQL
  461. pgConnect = pkgs.writeShellScriptBin "pg-connect" ''
  462. ${pkgs.postgresql_16}/bin/psql "postgresql://${postgresConf.pgUser}:${postgresConf.pgPassword}@localhost:${postgresConf.pgPort}/${postgresConf.pgDatabase}"
  463. '';
  464. # Common arguments can be set here to avoid repeating them later
  465. nativeBuildInputs = [
  466. #Add additional build inputs here
  467. ]
  468. ++ lib.optionals isDarwin [
  469. # Additional darwin specific native inputs can be set here
  470. ];
  471. in
  472. {
  473. # Expose deps for explicit cache warming
  474. packages = {
  475. deps = workspaceDeps;
  476. deps-msrv = workspaceDepsMsrv;
  477. }
  478. # Example packages (binaries that can be run outside sandbox with network access)
  479. // (builtins.listToAttrs (map (name: { name = "example-${name}"; value = mkExamplePackage name; }) exampleChecks));
  480. checks =
  481. # Generate clippy + test checks from clippyAndTestChecks attrset
  482. (builtins.mapAttrs (name: args: mkClippyAndTest name args) clippyAndTestChecks)
  483. # Generate MSRV build checks (prefixed with msrv-)
  484. // (builtins.listToAttrs (map (name: { name = "msrv-${name}"; value = mkMsrvBuild name msrvChecks.${name}; }) (builtins.attrNames msrvChecks)))
  485. # Generate WASM build checks (prefixed with wasm-)
  486. // (builtins.listToAttrs (map (name: { name = "wasm-${name}"; value = mkWasmBuild name wasmChecks.${name}; }) (builtins.attrNames wasmChecks)))
  487. # Generate example checks from exampleChecks list
  488. // (builtins.listToAttrs (map (name: { name = "example-${name}"; value = mkExample name; }) exampleChecks))
  489. // {
  490. # Doc tests
  491. doc-tests = docTests;
  492. # Strict docs check
  493. strict-docs = strictDocs;
  494. # FFI Python tests
  495. ffi-tests = ffiTests;
  496. };
  497. devShells =
  498. let
  499. # devShells
  500. msrv = pkgs.mkShell (
  501. {
  502. shellHook = "
  503. cargo update
  504. cargo update home --precise 0.5.11
  505. cargo update typed-index-collections --precise 3.3.0
  506. ";
  507. buildInputs = buildInputs ++ [ msrv_toolchain ];
  508. inherit nativeBuildInputs;
  509. }
  510. // envVars
  511. );
  512. stable = pkgs.mkShell (
  513. {
  514. shellHook = ''
  515. # Needed for github ci
  516. export LD_LIBRARY_PATH=${
  517. pkgs.lib.makeLibraryPath [
  518. pkgs.zlib
  519. ]
  520. }:$LD_LIBRARY_PATH
  521. # PostgreSQL environment variables
  522. export CDK_MINTD_DATABASE_URL="postgresql://${postgresConf.pgUser}:${postgresConf.pgPassword}@localhost:${postgresConf.pgPort}/${postgresConf.pgDatabase}"
  523. echo ""
  524. echo "PostgreSQL commands available:"
  525. echo " start-postgres - Initialize and start PostgreSQL"
  526. echo " stop-postgres - Stop PostgreSQL (run before exiting)"
  527. echo " pg-status - Check PostgreSQL status"
  528. echo " pg-connect - Connect to PostgreSQL with psql"
  529. echo ""
  530. '';
  531. buildInputs = buildInputs ++ [
  532. stable_toolchain
  533. pkgs.postgresql_16
  534. startPostgres
  535. stopPostgres
  536. pgStatus
  537. pgConnect
  538. ];
  539. inherit nativeBuildInputs;
  540. }
  541. // envVars
  542. );
  543. nightly = pkgs.mkShell (
  544. {
  545. shellHook = ''
  546. # Needed for github ci
  547. export LD_LIBRARY_PATH=${
  548. pkgs.lib.makeLibraryPath [
  549. pkgs.zlib
  550. ]
  551. }:$LD_LIBRARY_PATH
  552. # PostgreSQL environment variables
  553. export CDK_MINTD_DATABASE_URL="postgresql://${postgresConf.pgUser}:${postgresConf.pgPassword}@localhost:${postgresConf.pgPort}/${postgresConf.pgDatabase}"
  554. echo ""
  555. echo "PostgreSQL commands available:"
  556. echo " start-postgres - Initialize and start PostgreSQL"
  557. echo " stop-postgres - Stop PostgreSQL (run before exiting)"
  558. echo " pg-status - Check PostgreSQL status"
  559. echo " pg-connect - Connect to PostgreSQL with psql"
  560. echo ""
  561. '';
  562. buildInputs = buildInputs ++ [
  563. nightly_toolchain
  564. pkgs.postgresql_16
  565. startPostgres
  566. stopPostgres
  567. pgStatus
  568. pgConnect
  569. ];
  570. inherit nativeBuildInputs;
  571. }
  572. // envVars
  573. );
  574. # Shell with Docker for integration tests
  575. integration = pkgs.mkShell (
  576. {
  577. shellHook = ''
  578. # Ensure Docker is available
  579. if ! command -v docker &> /dev/null; then
  580. echo "Docker is not installed or not in PATH"
  581. echo "Please install Docker to run integration tests"
  582. exit 1
  583. fi
  584. echo "Docker is available at $(which docker)"
  585. echo "Docker version: $(docker --version)"
  586. '';
  587. buildInputs = buildInputs ++ [
  588. stable_toolchain
  589. pkgs.docker-client
  590. pkgs.python311
  591. ];
  592. inherit nativeBuildInputs;
  593. }
  594. // envVars
  595. );
  596. # Shell for FFI development (Python bindings)
  597. ffi = pkgs.mkShell (
  598. {
  599. shellHook = ''
  600. echo "FFI development shell"
  601. echo " just ffi-test - Run Python FFI tests"
  602. echo " just ffi-dev-python - Launch Python REPL with CDK FFI"
  603. '';
  604. buildInputs = buildInputs ++ [
  605. stable_toolchain
  606. pkgs.python311
  607. ];
  608. inherit nativeBuildInputs;
  609. }
  610. // envVars
  611. );
  612. in
  613. {
  614. inherit
  615. msrv
  616. stable
  617. nightly
  618. integration
  619. ffi
  620. ;
  621. default = stable;
  622. };
  623. }
  624. );
  625. }