2017-11-25 21:41:19 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.lirc;
|
|
|
|
in {
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
services.lirc = {
|
|
|
|
|
|
|
|
enable = mkEnableOption "LIRC daemon";
|
|
|
|
|
|
|
|
options = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
example = ''
|
|
|
|
[lircd]
|
|
|
|
nodaemon = False
|
|
|
|
'';
|
|
|
|
description = "LIRC default options descriped in man:lircd(8) (<filename>lirc_options.conf</filename>)";
|
|
|
|
};
|
|
|
|
|
|
|
|
configs = mkOption {
|
|
|
|
type = types.listOf types.lines;
|
|
|
|
description = "Configurations for lircd to load, see man:lircd.conf(5) for details (<filename>lircd.conf</filename>)";
|
|
|
|
};
|
|
|
|
|
|
|
|
extraArguments = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
description = "Extra arguments to lircd.";
|
|
|
|
};
|
|
|
|
|
2018-12-26 21:10:04 +00:00
|
|
|
socket = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
# default search path of many applications
|
|
|
|
default = "/run/lirc/lircd";
|
|
|
|
description = "Socket path";
|
|
|
|
};
|
|
|
|
|
2017-11-25 21:41:19 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
# Note: LIRC executables raises a warning, if lirc_options.conf do not exists
|
|
|
|
environment.etc."lirc/lirc_options.conf".text = cfg.options;
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.lirc ];
|
|
|
|
|
|
|
|
systemd.sockets.lircd = {
|
|
|
|
description = "LIRC daemon socket";
|
|
|
|
wantedBy = [ "sockets.target" ];
|
|
|
|
socketConfig = {
|
2018-12-26 21:10:04 +00:00
|
|
|
ListenStream = cfg.socket;
|
2017-11-25 21:41:19 +00:00
|
|
|
SocketUser = "lirc";
|
|
|
|
SocketMode = "0660";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.lircd = let
|
|
|
|
configFile = pkgs.writeText "lircd.conf" (builtins.concatStringsSep "\n" cfg.configs);
|
|
|
|
in {
|
|
|
|
description = "LIRC daemon service";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
|
|
|
|
unitConfig.Documentation = [ "man:lircd(8)" ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
RuntimeDirectory = "lirc";
|
2018-09-21 22:46:30 +01:00
|
|
|
|
2018-12-08 13:35:07 +00:00
|
|
|
# Service runtime directory and socket share same folder.
|
|
|
|
# Following hacks are necessary to get everything right:
|
|
|
|
|
|
|
|
# 1. prevent socket deletion during stop and restart
|
2018-09-21 22:46:30 +01:00
|
|
|
RuntimeDirectoryPreserve = true;
|
|
|
|
|
2018-12-08 13:35:07 +00:00
|
|
|
# 2. fix runtime folder owner-ship, happens when socket activation
|
|
|
|
# creates the folder
|
|
|
|
PermissionsStartOnly = true;
|
|
|
|
ExecStartPre = [
|
|
|
|
"${pkgs.coreutils}/bin/chown lirc /run/lirc/"
|
|
|
|
];
|
|
|
|
|
2017-11-25 21:41:19 +00:00
|
|
|
ExecStart = ''
|
|
|
|
${pkgs.lirc}/bin/lircd --nodaemon \
|
|
|
|
${escapeShellArgs cfg.extraArguments} \
|
|
|
|
${configFile}
|
|
|
|
'';
|
|
|
|
User = "lirc";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
users.users.lirc = {
|
|
|
|
uid = config.ids.uids.lirc;
|
|
|
|
group = "lirc";
|
|
|
|
description = "LIRC user for lircd";
|
|
|
|
};
|
|
|
|
|
|
|
|
users.groups.lirc.gid = config.ids.gids.lirc;
|
|
|
|
};
|
|
|
|
}
|