devenv.nix 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. { pkgs, lib, config, inputs, ... }:
  2. let
  3. rosettaPkgs =
  4. if pkgs.stdenv.isDarwin && pkgs.stdenv.isAarch64
  5. then pkgs.pkgsx86_64Darwin
  6. else pkgs;
  7. darwinPackages = with pkgs; [
  8. darwin.apple_sdk.frameworks.Security
  9. darwin.apple_sdk.frameworks.CoreServices
  10. darwin.apple_sdk.frameworks.CoreFoundation
  11. darwin.apple_sdk.frameworks.Foundation
  12. darwin.apple_sdk.frameworks.AppKit
  13. darwin.apple_sdk.frameworks.WebKit
  14. ];
  15. linuxPackages = with pkgs; [
  16. libsoup_3
  17. webkitgtk_4_1
  18. librsvg
  19. libappindicator
  20. libayatana-appindicator
  21. ];
  22. in {
  23. packages = with pkgs; [
  24. git
  25. lima
  26. colima
  27. docker
  28. jq
  29. # NOTE: In case there's `Cannot find module: ... bcrypt ...` error, try `npm rebuild bcrypt`
  30. # See: https://github.com/kelektiv/node.bcrypt.js/issues/800
  31. # See: https://github.com/kelektiv/node.bcrypt.js/issues/1055
  32. nodejs_20
  33. nodePackages.node-gyp
  34. nodePackages.typescript-language-server
  35. nodePackages."@volar/vue-language-server"
  36. nodePackages.prisma
  37. prisma-engines
  38. cargo-edit
  39. ] ++ lib.optionals pkgs.stdenv.isDarwin darwinPackages
  40. ++ lib.optionals pkgs.stdenv.isLinux linuxPackages;
  41. env = {
  42. APP_GREET = "Hoppscotch";
  43. DATABASE_URL = "postgresql://postgres:testpass@localhost:5432/hoppscotch?connect_timeout=300";
  44. DOCKER_BUILDKIT = "1";
  45. COMPOSE_DOCKER_CLI_BUILD = "1";
  46. } // lib.optionalAttrs pkgs.stdenv.isLinux {
  47. # NOTE: Setting these `PRISMA_*` environment variable fixes
  48. # "Error: Failed to fetch sha256 checksum at https://binaries.prisma.sh/all_commits/<hash>/linux-nixos/libquery_engine.so.node.gz.sha256 - 404 Not Found"
  49. # See: https://github.com/prisma/prisma/discussions/3120
  50. PRISMA_QUERY_ENGINE_LIBRARY = "${pkgs.prisma-engines}/lib/libquery_engine.node";
  51. PRISMA_QUERY_ENGINE_BINARY = "${pkgs.prisma-engines}/bin/query-engine";
  52. PRISMA_SCHEMA_ENGINE_BINARY = "${pkgs.prisma-engines}/bin/schema-engine";
  53. LD_LIBRARY_PATH = lib.makeLibraryPath [
  54. pkgs.libappindicator
  55. pkgs.libayatana-appindicator
  56. ];
  57. } // lib.optionalAttrs pkgs.stdenv.isDarwin {
  58. # Place to put macOS-specific environment variables
  59. };
  60. scripts = {
  61. hello.exec = "echo hello from $APP_GREET";
  62. e.exec = "emacs";
  63. lima-setup.exec = "limactl start template://docker";
  64. lima-clean.exec = "limactl rm -f $(limactl ls -q)";
  65. colima-start.exec = "colima start --cpu 4 --memory 50";
  66. docker-prune.exec = ''
  67. echo "Cleaning up unused Docker resources..."
  68. docker system prune -f
  69. '';
  70. docker-logs.exec = "docker logs -f hoppscotch-aio";
  71. docker-status.exec = ''
  72. echo "Container Status:"
  73. docker ps -a --filter "name=hoppscotch-aio" --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
  74. '';
  75. db-reset.exec = ''
  76. echo "Resetting database..."
  77. psql -U postgres -d hoppscotch -c 'DROP SCHEMA public CASCADE; CREATE SCHEMA public;'
  78. echo "Database reset complete."
  79. '';
  80. docker-clean-all.exec = ''
  81. echo "Starting complete Docker cleanup..."
  82. echo "1/6: Stopping all running containers..."
  83. CONTAINERS=$(docker ps -q)
  84. if [ -n "$CONTAINERS" ]; then
  85. docker stop $CONTAINERS
  86. echo "✓ Containers stopped"
  87. else
  88. echo "• No running containers found"
  89. fi
  90. echo "2/6: Removing all containers..."
  91. CONTAINERS=$(docker ps -aq)
  92. if [ -n "$CONTAINERS" ]; then
  93. docker rm $CONTAINERS
  94. echo "✓ Containers removed"
  95. else
  96. echo "• No containers to remove"
  97. fi
  98. echo "3/6: Removing all images..."
  99. IMAGES=$(docker images -q)
  100. if [ -n "$IMAGES" ]; then
  101. docker rmi --force $IMAGES
  102. echo "✓ Images removed"
  103. else
  104. echo "• No images to remove"
  105. fi
  106. echo "4/6: Removing all volumes..."
  107. VOLUMES=$(docker volume ls -q)
  108. if [ -n "$VOLUMES" ]; then
  109. docker volume rm $VOLUMES
  110. echo "✓ Volumes removed"
  111. else
  112. echo "• No volumes to remove"
  113. fi
  114. echo "5/6: Removing custom networks..."
  115. NETWORKS=$(docker network ls --filter type=custom -q)
  116. if [ -n "$NETWORKS" ]; then
  117. docker network rm $NETWORKS
  118. echo "✓ Networks removed"
  119. else
  120. echo "• No custom networks to remove"
  121. fi
  122. echo "6/6: Running system prune..."
  123. docker system prune --all --force --volumes
  124. echo "✓ System pruned"
  125. echo "Done!"
  126. '';
  127. };
  128. enterShell = ''
  129. git --version
  130. echo "Hoppscotch development environment ready!"
  131. ${lib.optionalString pkgs.stdenv.isDarwin ''
  132. # Place to put macOS-specific shell initialization
  133. ''}
  134. ${lib.optionalString pkgs.stdenv.isLinux ''
  135. # Place to put Linux-specific shell initialization
  136. ''}
  137. '';
  138. enterTest = ''
  139. echo "Running tests"
  140. '';
  141. dotenv.enable = true;
  142. languages = {
  143. typescript = {
  144. enable = true;
  145. };
  146. javascript = {
  147. package = pkgs.nodejs_20;
  148. enable = true;
  149. pnpm = {
  150. # NOTE: This follows pnpm version from `prod.Dockerfile`
  151. package = pkgs.pnpm_9; # This will use pnpm version 9.x
  152. enable = true;
  153. };
  154. npm.enable = true;
  155. };
  156. rust = {
  157. enable = true;
  158. channel = "nightly";
  159. components = [
  160. "rustc"
  161. "cargo"
  162. "clippy"
  163. "rustfmt"
  164. "rust-analyzer"
  165. "llvm-tools-preview"
  166. "rust-src"
  167. "rustc-codegen-cranelift-preview"
  168. ];
  169. };
  170. };
  171. }