6 Commits

Author SHA1 Message Date
Tilman Baumann
18996cdd78 Adding webviewer nixos option and improving tests
Use with
services.meshcore-bot = {
  enable = true;
  webviewer.enable = true;
 }
2026-01-08 19:17:18 +01:00
agessaman
d9f2820b4f fix: Clean up critical error logging in NixOS test for meshcore-bot
- Refactored the critical error handling logic to strip whitespace from error messages before checking their length, ensuring accurate logging of critical issues during testing.
2026-01-07 20:28:29 -08:00
agessaman
40a135340a feat: Improve log file checks in NixOS test for meshcore-bot 2026-01-07 20:19:42 -08:00
agessaman
ce9a1020c6 feat: Enhance NixOS test for meshcore-bot service
- Added comprehensive checks for service logs, state, and database file existence to improve diagnostics during testing.
- Implemented verification for service directory permissions and ownership.
- Enhanced TCP connection attempt verification with detailed logging for potential failures.
- Ensured robust handling of database file checks, including validation of SQLite database integrity.
2026-01-07 20:16:09 -08:00
agessaman
1acbee0b5b feat: Enhance bot signal handling and update dependencies
- Refactored bot's main execution flow to use asyncio.run() with improved signal handling for graceful shutdown on Unix systems.
- Added new dependencies in pyproject.toml: urllib3, paho-mqtt, cryptography, and pynacl for enhanced functionality.
- Updated Nix flake to include flake-parts for better modularization and added translation path for NixOS module compatibility.
- Improved argument parsing in web viewer to maintain clarity and consistency.
2026-01-07 20:06:43 -08:00
Tilman Baumann
a6c56ecd3c Add Nix flake with NixOS module and modernize Python packaging
This commit adds comprehensive Nix/NixOS support and modernizes the
Python packaging structure to enable declarative system-wide deployments.

Added complete Nix flake infrastructure in nix/:
- packages.nix: Package definition with all dependencies
- nixos-module.nix: NixOS module for declarative service configuration
- nixos-test.nix: Comprehensive NixOS VM tests (basic + web viewer)
- shell.nix: Development shell with all build tools

The NixOS module (services.meshcore-bot) provides:
- Automatic user/group creation (meshcore-bot:meshcore-bot)
- Serial port access (dialout group membership)
- Systemd service with security hardening
- Automatic directory management via StateDirectory/LogsDirectory
- INI config generation from Nix attribute sets
- Sensible defaults for system paths

Example NixOS configuration:
  services.meshcore-bot = {
    enable = true;
    settings = {
      Connection.connection_type = "serial";
      Connection.serial_port = "/dev/ttyUSB0";
      Bot.bot_name = "MyBot";
    };
  };

Migrated from requirements.txt to pyproject.toml:
- Defined proper package metadata and dependencies
- Created entry points: meshcore-bot, meshcore-viewer
- Enables standard 'pip install -e .' workflow
- Maintains compatibility with existing setups

Changes to existing code are minimal and only where necessary:

1. **Added --config parameter** (meshcore_bot.py, app.py)
   - Wrapped main logic in main() function for entry point
   - Added argparse to accept --config parameter
   - Required for NixOS to pass generated config from /nix/store
   - Backwards compatible: defaults to 'config.ini' in current directory
   - No changes to core bot logic

2. **Fixed web viewer subprocess spawning** (modules/web_viewer/integration.py)
   - Changed from sys.executable to 'meshcore-viewer' entry point
   - Ensures Nix wrapper script sets up correct PYTHONPATH
   - Resolves Flask module import issues in Nix environment
   - No functional change for traditional installations

Note: The dev branch's resolve_path() utility already handles both
relative and absolute paths correctly, making it compatible with
NixOS system paths (/var/lib, /var/log) without additional changes.

All NixOS VM tests passing:
- nixos-module-basic: Service startup, file creation, TCP connection
- nixos-module-webviewer: Flask available, port listening, HTTP responses

No breaking changes to existing workflows. The bot continues to work
exactly as before when run with traditional Python methods.
2026-01-07 14:01:39 +01:00