2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.hardware.lcd;
|
|
|
|
pkg = lib.getBin pkgs.lcdproc;
|
|
|
|
|
|
|
|
serverCfg = pkgs.writeText "lcdd.conf" ''
|
|
|
|
[server]
|
|
|
|
DriverPath=${pkg}/lib/lcdproc/
|
|
|
|
ReportToSyslog=false
|
|
|
|
Bind=${cfg.serverHost}
|
|
|
|
Port=${toString cfg.serverPort}
|
|
|
|
${cfg.server.extraConfig}
|
|
|
|
'';
|
|
|
|
|
|
|
|
clientCfg = pkgs.writeText "lcdproc.conf" ''
|
|
|
|
[lcdproc]
|
|
|
|
Server=${cfg.serverHost}
|
|
|
|
Port=${toString cfg.serverPort}
|
|
|
|
ReportToSyslog=false
|
|
|
|
${cfg.client.extraConfig}
|
|
|
|
'';
|
|
|
|
|
|
|
|
serviceCfg = {
|
|
|
|
DynamicUser = true;
|
|
|
|
Restart = "on-failure";
|
|
|
|
Slice = "lcd.slice";
|
|
|
|
};
|
|
|
|
|
|
|
|
in with lib; {
|
|
|
|
|
|
|
|
meta.maintainers = with maintainers; [ peterhoeg ];
|
|
|
|
|
|
|
|
options = with types; {
|
|
|
|
services.hardware.lcd = {
|
|
|
|
serverHost = mkOption {
|
|
|
|
type = str;
|
|
|
|
default = "localhost";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Host on which LCDd is listening.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
serverPort = mkOption {
|
|
|
|
type = int;
|
|
|
|
default = 13666;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Port on which LCDd is listening.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
server = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = bool;
|
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Enable the LCD panel server (LCDd)";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
openPorts = mkOption {
|
|
|
|
type = bool;
|
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Open the ports in the firewall";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
usbPermissions = mkOption {
|
|
|
|
type = bool;
|
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Set group-write permissions on a USB device.
|
2022-08-12 12:06:08 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
A USB connected LCD panel will most likely require having its
|
|
|
|
permissions modified for lcdd to write to it. Enabling this option
|
|
|
|
sets group-write permissions on the device identified by
|
2022-09-09 14:08:57 +00:00
|
|
|
{option}`services.hardware.lcd.usbVid` and
|
|
|
|
{option}`services.hardware.lcd.usbPid`. In order to find the
|
|
|
|
values, you can run the {command}`lsusb` command. Example
|
2020-04-24 23:36:52 +00:00
|
|
|
output:
|
2022-08-12 12:06:08 +00:00
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
```
|
2020-04-24 23:36:52 +00:00
|
|
|
Bus 005 Device 002: ID 0403:c630 Future Technology Devices International, Ltd lcd2usb interface
|
2022-09-09 14:08:57 +00:00
|
|
|
```
|
2022-08-12 12:06:08 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
In this case the vendor id is 0403 and the product id is c630.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
usbVid = mkOption {
|
|
|
|
type = str;
|
|
|
|
default = "";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "The vendor ID of the USB device to claim.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
usbPid = mkOption {
|
|
|
|
type = str;
|
|
|
|
default = "";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "The product ID of the USB device to claim.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
usbGroup = mkOption {
|
|
|
|
type = str;
|
|
|
|
default = "dialout";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "The group to use for settings permissions. This group must exist or you will have to create it.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = lines;
|
|
|
|
default = "";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Additional configuration added verbatim to the server config.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
client = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = bool;
|
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Enable the LCD panel client (LCDproc)";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = lines;
|
|
|
|
default = "";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Additional configuration added verbatim to the client config.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
restartForever = mkOption {
|
|
|
|
type = bool;
|
|
|
|
default = true;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Try restarting the client forever.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf (cfg.server.enable || cfg.client.enable) {
|
|
|
|
networking.firewall.allowedTCPPorts = mkIf (cfg.server.enable && cfg.server.openPorts) [ cfg.serverPort ];
|
|
|
|
|
|
|
|
services.udev.extraRules = mkIf (cfg.server.enable && cfg.server.usbPermissions) ''
|
|
|
|
ACTION=="add", SUBSYSTEMS=="usb", ATTRS{idVendor}=="${cfg.server.usbVid}", ATTRS{idProduct}=="${cfg.server.usbPid}", MODE="660", GROUP="${cfg.server.usbGroup}"
|
|
|
|
'';
|
|
|
|
|
|
|
|
systemd.services = {
|
|
|
|
lcdd = mkIf cfg.server.enable {
|
|
|
|
description = "LCDproc - server";
|
|
|
|
wantedBy = [ "lcd.target" ];
|
|
|
|
serviceConfig = serviceCfg // {
|
|
|
|
ExecStart = "${pkg}/bin/LCDd -f -c ${serverCfg}";
|
|
|
|
SupplementaryGroups = cfg.server.usbGroup;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
lcdproc = mkIf cfg.client.enable {
|
|
|
|
description = "LCDproc - client";
|
|
|
|
after = [ "lcdd.service" ];
|
|
|
|
wantedBy = [ "lcd.target" ];
|
2020-11-03 02:18:15 +00:00
|
|
|
# Allow restarting for eternity
|
|
|
|
startLimitIntervalSec = lib.mkIf cfg.client.restartForever 0;
|
2020-04-24 23:36:52 +00:00
|
|
|
serviceConfig = serviceCfg // {
|
|
|
|
ExecStart = "${pkg}/bin/lcdproc -f -c ${clientCfg}";
|
|
|
|
# If the server is being restarted at the same time, the client will
|
|
|
|
# fail as it cannot connect, so space it out a bit.
|
|
|
|
RestartSec = "5";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.targets.lcd = {
|
|
|
|
description = "LCD client/server";
|
|
|
|
after = [ "lcdd.service" "lcdproc.service" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|