devenv.nix 5.0 KB

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