Added flashing logic
This commit is contained in:
parent
1f965038fc
commit
238b3a6fae
|
@ -1,4 +1,4 @@
|
||||||
{ lib, config, pkgs, mmdvm_host, ... }:
|
{ lib, config, pkgs, mmdvm_host, mmdvm_firmware, ... }:
|
||||||
with lib;
|
with lib;
|
||||||
let
|
let
|
||||||
# Shorter name to access final settings a
|
# Shorter name to access final settings a
|
||||||
|
@ -10,14 +10,36 @@ in
|
||||||
|
|
||||||
options.services.mmdvm_host = {
|
options.services.mmdvm_host = {
|
||||||
enable = mkEnableOption "MMDVMHost service";
|
enable = mkEnableOption "MMDVMHost service";
|
||||||
package = mkOption {
|
|
||||||
|
host_package = mkOption {
|
||||||
default = mmdvm_host.x86_64-linux.default;
|
default = mmdvm_host.x86_64-linux.default;
|
||||||
type = types.package;
|
type = types.package;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
firmware_package = mkOption {
|
||||||
|
default = mmdvm_firmware.x86_64-linux.default;
|
||||||
|
type = types.package;
|
||||||
|
};
|
||||||
|
|
||||||
user = mkOption {
|
user = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
default = "afg";
|
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:
|
# List packages installed in system profile. To search, run:
|
||||||
# $ nix search wget
|
# $ nix search wget
|
||||||
environment.systemPackages = [
|
environment.systemPackages = [
|
||||||
cfg.package
|
pkgs.stm32flash
|
||||||
|
cfg.host_package
|
||||||
];
|
];
|
||||||
|
|
||||||
systemd.services.mmdvm_host = {
|
systemd.services.mmdvm_host = {
|
||||||
|
@ -36,13 +59,22 @@ in
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "exec";
|
Type = "exec";
|
||||||
User = cfg.user;
|
User = cfg.user;
|
||||||
|
Group = cfg.group;
|
||||||
Restart = "always";
|
Restart = "always";
|
||||||
RestartSec = "3s";
|
RestartSec = "3s";
|
||||||
StartLimitIntervalSec = "0";
|
|
||||||
RuntimeDirectory = "MMDVMHost";
|
RuntimeDirectory = "MMDVMHost";
|
||||||
};
|
};
|
||||||
script = ''
|
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}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,7 +21,10 @@
|
||||||
|
|
||||||
nixosModules.MMDVMHost = { config, pkgs, ... }: {
|
nixosModules.MMDVMHost = { config, pkgs, ... }: {
|
||||||
imports = [ ./MMDVMHost/module.nix ];
|
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;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue