flake.nix 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. };
  35. # MSRV stable
  36. msrv_toolchain = pkgs.rust-bin.stable."1.63.0".default.override {
  37. targets = [ "wasm32-unknown-unknown" ]; # wasm
  38. };
  39. # DB MSRV stable
  40. db_msrv_toolchain = pkgs.rust-bin.stable."1.66.0".default.override {
  41. targets = [ "wasm32-unknown-unknown" ]; # wasm
  42. };
  43. # Nighly for creating lock files
  44. nightly_toolchain = pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default);
  45. # Common inputs
  46. envVars = { };
  47. buildInputs = with pkgs; [
  48. # Add additional build inputs here
  49. git
  50. pkg-config
  51. curl
  52. just
  53. protobuf
  54. nixpkgs-fmt
  55. rust-analyzer
  56. typos
  57. lnd
  58. clightning
  59. bitcoind
  60. sqlx-cli
  61. ] ++ libsDarwin;
  62. # WASM deps
  63. WASMInputs = with pkgs; [
  64. ];
  65. nativeBuildInputs = with pkgs; [
  66. #Add additional build inputs here
  67. ] ++ lib.optionals isDarwin [
  68. # Additional darwin specific native inputs can be set here
  69. ];
  70. in
  71. {
  72. checks = {
  73. # Pre-commit checks
  74. pre-commit-check =
  75. let
  76. # this is a hack based on https://github.com/cachix/pre-commit-hooks.nix/issues/126
  77. # we want to use our own rust stuff from oxalica's overlay
  78. _rust = pkgs.rust-bin.stable.latest.default;
  79. rust = pkgs.buildEnv {
  80. name = _rust.name;
  81. inherit (_rust) meta;
  82. buildInputs = [ pkgs.makeWrapper ];
  83. paths = [ _rust ];
  84. pathsToLink = [ "/" "/bin" ];
  85. postBuild = ''
  86. for i in $out/bin/*; do
  87. wrapProgram "$i" --prefix PATH : "$out/bin"
  88. done
  89. '';
  90. };
  91. in
  92. pre-commit-hooks.lib.${system}.run {
  93. src = ./.;
  94. hooks = {
  95. rustfmt = {
  96. enable = true;
  97. entry = lib.mkForce "${rust}/bin/cargo-fmt fmt --all -- --config format_code_in_doc_comments=true --check --color always";
  98. };
  99. nixpkgs-fmt.enable = true;
  100. typos.enable = true;
  101. commitizen.enable = true; # conventional commits
  102. };
  103. };
  104. };
  105. devShells =
  106. let
  107. # pre-commit-checks
  108. _shellHook = (self.checks.${system}.pre-commit-check.shellHook or "");
  109. # devShells
  110. msrv = pkgs.mkShell ({
  111. shellHook = "
  112. ${_shellHook}
  113. cargo update -p half --precise 2.2.1
  114. cargo update -p tokio --precise 1.38.1
  115. cargo update -p tokio-util --precise 0.7.11
  116. cargo update -p tokio-stream --precise 0.1.15
  117. cargo update -p reqwest --precise 0.12.4
  118. cargo update -p serde_with --precise 3.1.0
  119. cargo update -p regex --precise 1.9.6
  120. cargo update -p backtrace --precise 0.3.58
  121. # For wasm32-unknown-unknown target
  122. cargo update -p bumpalo --precise 3.12.0
  123. cargo update -p moka --precise 0.11.1
  124. cargo update -p triomphe --precise 0.1.11
  125. cargo update -p url --precise 2.5.2
  126. ";
  127. buildInputs = buildInputs ++ WASMInputs ++ [ msrv_toolchain ];
  128. inherit nativeBuildInputs;
  129. } // envVars);
  130. stable = pkgs.mkShell ({
  131. shellHook = "${_shellHook}";
  132. buildInputs = buildInputs ++ WASMInputs ++ [ stable_toolchain ];
  133. inherit nativeBuildInputs;
  134. } // envVars);
  135. db_shell = pkgs.mkShell ({
  136. shellHook = "
  137. ${_shellHook}
  138. cargo update -p half --precise 2.2.1
  139. cargo update -p home --precise 0.5.5
  140. cargo update -p tokio --precise 1.38.1
  141. cargo update -p tokio-stream --precise 0.1.15
  142. cargo update -p serde_with --precise 3.1.0
  143. cargo update -p reqwest --precise 0.12.4
  144. cargo update -p url --precise 2.5.2
  145. cargo update -p allocator-api2 --precise 0.2.18
  146. ";
  147. buildInputs = buildInputs ++ WASMInputs ++ [ db_msrv_toolchain ];
  148. inherit nativeBuildInputs;
  149. } // envVars);
  150. nightly = pkgs.mkShell ({
  151. shellHook = "${_shellHook}";
  152. buildInputs = buildInputs ++ [ nightly_toolchain ];
  153. inherit nativeBuildInputs;
  154. } // envVars);
  155. in
  156. {
  157. inherit msrv stable nightly db_shell;
  158. default = stable;
  159. };
  160. }
  161. );
  162. }