From 238b3a6fae966727370f524247792c37c0a1ebec Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 19 Dec 2024 13:58:57 +0100 Subject: [PATCH] Added flashing logic --- MMDVMHost/module.nix | 42 +++++++++++++++++++++++++++++++++++++----- flake.nix | 5 ++++- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/MMDVMHost/module.nix b/MMDVMHost/module.nix index 3190dbd..4a8f14d 100644 --- a/MMDVMHost/module.nix +++ b/MMDVMHost/module.nix @@ -1,4 +1,4 @@ -{ lib, config, pkgs, mmdvm_host, ... }: +{ lib, config, pkgs, mmdvm_host, mmdvm_firmware, ... }: with lib; let # Shorter name to access final settings a @@ -10,14 +10,36 @@ in options.services.mmdvm_host = { enable = mkEnableOption "MMDVMHost service"; - package = mkOption { + + host_package = mkOption { default = mmdvm_host.x86_64-linux.default; type = types.package; }; + + firmware_package = mkOption { + default = mmdvm_firmware.x86_64-linux.default; + type = types.package; + }; + user = mkOption { type = types.str; default = "afg"; }; + + group = mkOption { + type = types.str; + default = "afg"; + }; + + config-file = mkOption { + type = types.str; + }; + + usb-tty = mkOption { + type = types.str; + default = "/dev/ttyUSB0"; + }; + }; @@ -25,7 +47,8 @@ in # List packages installed in system profile. To search, run: # $ nix search wget environment.systemPackages = [ - cfg.package + pkgs.stm32flash + cfg.host_package ]; systemd.services.mmdvm_host = { @@ -36,13 +59,22 @@ in serviceConfig = { Type = "exec"; User = cfg.user; + Group = cfg.group; Restart = "always"; RestartSec = "3s"; - StartLimitIntervalSec = "0"; RuntimeDirectory = "MMDVMHost"; }; script = '' - exec ${cfg.package}/bin/MMDVMHost + if [ ! -e /var/lib/mmdvm/firmware-version ]; then + mkdir -p /var/lib/mmdvm + touch /var/lib/mmdvm/firmware-version + fi + if [ "${cfg.firmware_package}" != "$(cat /var/lib/mmdvm/firmware-version)" ]; then + ${pkgs.stm32flash}/bin/stm32flash -w ${cfg.firmware_package}/bin/mmdvm_f4.bin -i ',-dtr,-rts,dtr,,:-dtr,rts,dtr' ${cfg.usb-tty} + echo "{cfg.firmware_package}" > /var/lib/mmdvm/firmware-version + fi + + exec ${cfg.package}/bin/MMDVMHost ${cfg.config-file} ''; }; }; diff --git a/flake.nix b/flake.nix index dc7ec58..2eebced 100644 --- a/flake.nix +++ b/flake.nix @@ -21,7 +21,10 @@ nixosModules.MMDVMHost = { config, pkgs, ... }: { imports = [ ./MMDVMHost/module.nix ]; - _module.args.mmdvm_host = self.packages.x86_64-linux.MMDVMHost; + _module.args = { + mmdvm_host = self.packages.x86_64-linux.MMDVMHost; + mmdvm_firmware = self.packages.x86_64-linux.MMDVMFirmware; + }; }; }; }