flake.nix 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. {
  2. description = "CDK Flake";
  3. inputs = {
  4. nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
  5. rust-overlay = {
  6. url = "github:oxalica/rust-overlay";
  7. inputs = {
  8. nixpkgs.follows = "nixpkgs";
  9. };
  10. };
  11. flake-utils.url = "github:numtide/flake-utils";
  12. pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
  13. };
  14. outputs = { self, nixpkgs, rust-overlay, flake-utils, pre-commit-hooks, ... }:
  15. flake-utils.lib.eachDefaultSystem (system:
  16. let
  17. overlays = [ (import rust-overlay) ];
  18. lib = pkgs.lib;
  19. stdenv = pkgs.stdenv;
  20. isDarwin = stdenv.isDarwin;
  21. libsDarwin = with pkgs; lib.optionals isDarwin [
  22. # Additional darwin specific inputs can be set here
  23. darwin.apple_sdk.frameworks.Security
  24. darwin.apple_sdk.frameworks.SystemConfiguration
  25. ];
  26. # Dependencies
  27. pkgs = import nixpkgs {
  28. inherit system overlays;
  29. };
  30. # Toolchains
  31. # latest stable
  32. stable_toolchain = pkgs.rust-bin.stable."1.82.0".default.override {
  33. targets = [ "wasm32-unknown-unknown" ]; # wasm
  34. extensions = [ "rustfmt" "clippy" "rust-analyzer" ];
  35. };
  36. # MSRV stable
  37. msrv_toolchain = pkgs.rust-bin.stable."1.63.0".default.override {
  38. targets = [ "wasm32-unknown-unknown" ]; # wasm
  39. };
  40. # DB MSRV stable
  41. db_msrv_toolchain = pkgs.rust-bin.stable."1.66.0".default.override {
  42. targets = [ "wasm32-unknown-unknown" ]; # wasm
  43. };
  44. # Nightly for creating lock files
  45. nightly_toolchain = pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default.override {
  46. extensions = [ "rustfmt" "clippy" "rust-analyzer" ];
  47. });
  48. # Common inputs
  49. envVars = { };
  50. buildInputs = with pkgs; [
  51. # Add additional build inputs here
  52. git
  53. pkg-config
  54. curl
  55. just
  56. protobuf
  57. nixpkgs-fmt
  58. typos
  59. lnd
  60. clightning
  61. bitcoind
  62. sqlx-cli
  63. # Needed for github ci
  64. libz
  65. ] ++ libsDarwin;
  66. # WASM deps
  67. WASMInputs = with pkgs; [
  68. ];
  69. nativeBuildInputs = with pkgs; [
  70. #Add additional build inputs here
  71. ] ++ lib.optionals isDarwin [
  72. # Additional darwin specific native inputs can be set here
  73. ];
  74. in
  75. {
  76. checks = {
  77. # Pre-commit checks
  78. pre-commit-check =
  79. let
  80. # this is a hack based on https://github.com/cachix/pre-commit-hooks.nix/issues/126
  81. # we want to use our own rust stuff from oxalica's overlay
  82. _rust = pkgs.rust-bin.stable.latest.default;
  83. rust = pkgs.buildEnv {
  84. name = _rust.name;
  85. inherit (_rust) meta;
  86. buildInputs = [ pkgs.makeWrapper ];
  87. paths = [ _rust ];
  88. pathsToLink = [ "/" "/bin" ];
  89. postBuild = ''
  90. for i in $out/bin/*; do
  91. wrapProgram "$i" --prefix PATH : "$out/bin"
  92. done
  93. '';
  94. };
  95. in
  96. pre-commit-hooks.lib.${system}.run {
  97. src = ./.;
  98. hooks = {
  99. rustfmt = {
  100. enable = true;
  101. entry = lib.mkForce "${rust}/bin/cargo-fmt fmt --all -- --config format_code_in_doc_comments=true --check --color always";
  102. };
  103. nixpkgs-fmt.enable = true;
  104. typos.enable = true;
  105. commitizen.enable = true; # conventional commits
  106. };
  107. };
  108. };
  109. devShells =
  110. let
  111. # pre-commit-checks
  112. _shellHook = (self.checks.${system}.pre-commit-check.shellHook or "");
  113. # devShells
  114. msrv = pkgs.mkShell ({
  115. shellHook = "
  116. ${_shellHook}
  117. cargo update -p half --precise 2.2.1
  118. cargo update -p tokio --precise 1.38.1
  119. cargo update -p tokio-util --precise 0.7.11
  120. cargo update -p tokio-stream --precise 0.1.15
  121. cargo update -p reqwest --precise 0.12.4
  122. cargo update -p serde_with --precise 3.1.0
  123. cargo update -p regex --precise 1.9.6
  124. cargo update -p backtrace --precise 0.3.58
  125. # For wasm32-unknown-unknown target
  126. cargo update -p bumpalo --precise 3.12.0
  127. cargo update -p moka --precise 0.11.1
  128. cargo update -p triomphe --precise 0.1.11
  129. cargo update -p url --precise 2.5.2
  130. ";
  131. buildInputs = buildInputs ++ WASMInputs ++ [ msrv_toolchain ];
  132. inherit nativeBuildInputs;
  133. } // envVars);
  134. stable = pkgs.mkShell ({
  135. shellHook = ''${_shellHook}'';
  136. buildInputs = buildInputs ++ WASMInputs ++ [ stable_toolchain ];
  137. inherit nativeBuildInputs;
  138. } // envVars);
  139. db_shell = pkgs.mkShell ({
  140. shellHook = ''
  141. ${_shellHook}
  142. cargo update -p half --precise 2.2.1
  143. cargo update -p home --precise 0.5.5
  144. cargo update -p tokio --precise 1.38.1
  145. cargo update -p tokio-stream --precise 0.1.15
  146. cargo update -p serde_with --precise 3.1.0
  147. cargo update -p reqwest --precise 0.12.4
  148. cargo update -p url --precise 2.5.2
  149. cargo update -p allocator-api2 --precise 0.2.18
  150. '';
  151. buildInputs = buildInputs ++ WASMInputs ++ [ db_msrv_toolchain ];
  152. inherit nativeBuildInputs;
  153. } // envVars);
  154. nightly = pkgs.mkShell ({
  155. shellHook = ''
  156. ${_shellHook}
  157. # Needed for github ci
  158. export LD_LIBRARY_PATH=${pkgs.lib.makeLibraryPath [
  159. pkgs.zlib
  160. ]}:$LD_LIBRARY_PATH
  161. '';
  162. buildInputs = buildInputs ++ [ nightly_toolchain ];
  163. inherit nativeBuildInputs;
  164. } // envVars);
  165. in
  166. {
  167. inherit msrv stable nightly db_shell;
  168. default = stable;
  169. };
  170. }
  171. );
  172. }