devenv.nix 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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.typescript-language-server
  34. nodePackages."@volar/vue-language-server"
  35. nodePackages.prisma
  36. prisma-engines
  37. cargo-edit
  38. ] ++ lib.optionals pkgs.stdenv.isDarwin darwinPackages
  39. ++ lib.optionals pkgs.stdenv.isLinux linuxPackages;
  40. env = {
  41. APP_GREET = "Hoppscotch";
  42. DATABASE_URL = "postgresql://postgres:testpass@localhost:5432/hoppscotch?connect_timeout=300";
  43. DOCKER_BUILDKIT = "1";
  44. COMPOSE_DOCKER_CLI_BUILD = "1";
  45. } // lib.optionalAttrs pkgs.stdenv.isLinux {
  46. # NOTE: Setting these `PRISMA_*` environment variable fixes
  47. # "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"
  48. # See: https://github.com/prisma/prisma/discussions/3120
  49. PRISMA_QUERY_ENGINE_LIBRARY = "${pkgs.prisma-engines}/lib/libquery_engine.node";
  50. PRISMA_QUERY_ENGINE_BINARY = "${pkgs.prisma-engines}/bin/query-engine";
  51. PRISMA_SCHEMA_ENGINE_BINARY = "${pkgs.prisma-engines}/bin/schema-engine";
  52. LD_LIBRARY_PATH = lib.makeLibraryPath [
  53. pkgs.libappindicator
  54. pkgs.libayatana-appindicator
  55. ];
  56. } // lib.optionalAttrs pkgs.stdenv.isDarwin {
  57. # Place to put macOS-specific environment variables
  58. };
  59. scripts = {
  60. hello.exec = "echo hello from $APP_GREET";
  61. e.exec = "emacs";
  62. lima-setup.exec = "limactl start template://docker";
  63. lima-clean.exec = "limactl rm -f $(limactl ls -q)";
  64. colima-start.exec = "colima start --cpu 4 --memory 50";
  65. docker-prune.exec = ''
  66. echo "Cleaning up unused Docker resources..."
  67. docker system prune -f
  68. '';
  69. docker-logs.exec = "docker logs -f hoppscotch-aio";
  70. docker-status.exec = ''
  71. echo "Container Status:"
  72. docker ps -a --filter "name=hoppscotch-aio" --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
  73. '';
  74. db-reset.exec = ''
  75. echo "Resetting database..."
  76. psql -U postgres -d hoppscotch -c 'DROP SCHEMA public CASCADE; CREATE SCHEMA public;'
  77. echo "Database reset complete."
  78. '';
  79. docker-clean-all.exec = ''
  80. echo "Starting complete Docker cleanup..."
  81. echo "1/6: Stopping all running containers..."
  82. CONTAINERS=$(docker ps -q)
  83. if [ -n "$CONTAINERS" ]; then
  84. docker stop $CONTAINERS
  85. echo "✓ Containers stopped"
  86. else
  87. echo "• No running containers found"
  88. fi
  89. echo "2/6: Removing all containers..."
  90. CONTAINERS=$(docker ps -aq)
  91. if [ -n "$CONTAINERS" ]; then
  92. docker rm $CONTAINERS
  93. echo "✓ Containers removed"
  94. else
  95. echo "• No containers to remove"
  96. fi
  97. echo "3/6: Removing all images..."
  98. IMAGES=$(docker images -q)
  99. if [ -n "$IMAGES" ]; then
  100. docker rmi --force $IMAGES
  101. echo "✓ Images removed"
  102. else
  103. echo "• No images to remove"
  104. fi
  105. echo "4/6: Removing all volumes..."
  106. VOLUMES=$(docker volume ls -q)
  107. if [ -n "$VOLUMES" ]; then
  108. docker volume rm $VOLUMES
  109. echo "✓ Volumes removed"
  110. else
  111. echo "• No volumes to remove"
  112. fi
  113. echo "5/6: Removing custom networks..."
  114. NETWORKS=$(docker network ls --filter type=custom -q)
  115. if [ -n "$NETWORKS" ]; then
  116. docker network rm $NETWORKS
  117. echo "✓ Networks removed"
  118. else
  119. echo "• No custom networks to remove"
  120. fi
  121. echo "6/6: Running system prune..."
  122. docker system prune --all --force --volumes
  123. echo "✓ System pruned"
  124. echo "Done!"
  125. '';
  126. };
  127. enterShell = ''
  128. git --version
  129. echo "Hoppscotch development environment ready!"
  130. ${lib.optionalString pkgs.stdenv.isDarwin ''
  131. # Place to put macOS-specific shell initialization
  132. ''}
  133. ${lib.optionalString pkgs.stdenv.isLinux ''
  134. # Place to put Linux-specific shell initialization
  135. ''}
  136. '';
  137. enterTest = ''
  138. echo "Running tests"
  139. '';
  140. dotenv.enable = true;
  141. languages = {
  142. typescript = {
  143. enable = true;
  144. };
  145. javascript = {
  146. package = pkgs.nodejs_20;
  147. enable = true;
  148. npm.enable = true;
  149. pnpm.enable = true;
  150. };
  151. rust = {
  152. enable = true;
  153. channel = "nightly";
  154. components = [
  155. "rustc"
  156. "cargo"
  157. "clippy"
  158. "rustfmt"
  159. "rust-analyzer"
  160. "llvm-tools-preview"
  161. "rust-src"
  162. "rustc-codegen-cranelift-preview"
  163. ];
  164. };
  165. };
  166. }