1 { config, lib, pkgs, ... }:
4 cfg = config.services.hardware.lcd;
5 pkg = lib.getBin pkgs.lcdproc;
7 serverCfg = pkgs.writeText "lcdd.conf" ''
9 DriverPath=${pkg}/lib/lcdproc/
11 Bind=${cfg.serverHost}
12 Port=${toString cfg.serverPort}
13 ${cfg.server.extraConfig}
16 clientCfg = pkgs.writeText "lcdproc.conf" ''
18 Server=${cfg.serverHost}
19 Port=${toString cfg.serverPort}
21 ${cfg.client.extraConfig}
26 Restart = "on-failure";
32 meta.maintainers = with maintainers; [ peterhoeg ];
34 options = with types; {
35 services.hardware.lcd = {
36 serverHost = mkOption {
38 default = "localhost";
39 description = lib.mdDoc "Host on which LCDd is listening.";
42 serverPort = mkOption {
45 description = lib.mdDoc "Port on which LCDd is listening.";
52 description = lib.mdDoc "Enable the LCD panel server (LCDd)";
55 openPorts = mkOption {
58 description = lib.mdDoc "Open the ports in the firewall";
61 usbPermissions = mkOption {
64 description = lib.mdDoc ''
65 Set group-write permissions on a USB device.
67 A USB connected LCD panel will most likely require having its
68 permissions modified for lcdd to write to it. Enabling this option
69 sets group-write permissions on the device identified by
70 {option}`services.hardware.lcd.usbVid` and
71 {option}`services.hardware.lcd.usbPid`. In order to find the
72 values, you can run the {command}`lsusb` command. Example
76 Bus 005 Device 002: ID 0403:c630 Future Technology Devices International, Ltd lcd2usb interface
79 In this case the vendor id is 0403 and the product id is c630.
86 description = lib.mdDoc "The vendor ID of the USB device to claim.";
92 description = lib.mdDoc "The product ID of the USB device to claim.";
98 description = lib.mdDoc "The group to use for settings permissions. This group must exist or you will have to create it.";
101 extraConfig = mkOption {
104 description = lib.mdDoc "Additional configuration added verbatim to the server config.";
112 description = lib.mdDoc "Enable the LCD panel client (LCDproc)";
115 extraConfig = mkOption {
118 description = lib.mdDoc "Additional configuration added verbatim to the client config.";
121 restartForever = mkOption {
124 description = lib.mdDoc "Try restarting the client forever.";
130 config = mkIf (cfg.server.enable || cfg.client.enable) {
131 networking.firewall.allowedTCPPorts = mkIf (cfg.server.enable && cfg.server.openPorts) [ cfg.serverPort ];
133 services.udev.extraRules = mkIf (cfg.server.enable && cfg.server.usbPermissions) ''
134 ACTION=="add", SUBSYSTEMS=="usb", ATTRS{idVendor}=="${cfg.server.usbVid}", ATTRS{idProduct}=="${cfg.server.usbPid}", MODE="660", GROUP="${cfg.server.usbGroup}"
138 lcdd = mkIf cfg.server.enable {
139 description = "LCDproc - server";
140 wantedBy = [ "lcd.target" ];
141 serviceConfig = serviceCfg // {
142 ExecStart = "${pkg}/bin/LCDd -f -c ${serverCfg}";
143 SupplementaryGroups = cfg.server.usbGroup;
147 lcdproc = mkIf cfg.client.enable {
148 description = "LCDproc - client";
149 after = [ "lcdd.service" ];
150 wantedBy = [ "lcd.target" ];
151 # Allow restarting for eternity
152 startLimitIntervalSec = lib.mkIf cfg.client.restartForever 0;
153 serviceConfig = serviceCfg // {
154 ExecStart = "${pkg}/bin/lcdproc -f -c ${clientCfg}";
155 # If the server is being restarted at the same time, the client will
156 # fail as it cannot connect, so space it out a bit.
162 systemd.targets.lcd = {
163 description = "LCD client/server";
164 after = [ "lcdd.service" "lcdproc.service" ];
165 wantedBy = [ "multi-user.target" ];