flake.nix 26 KB

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