1 { config, lib, pkgs, ... }:
3 cfg = config.services.lirc;
11 enable = lib.mkEnableOption "the LIRC daemon, to receive and send infrared signals";
13 options = lib.mkOption {
14 type = lib.types.lines;
19 description = "LIRC default options described in man:lircd(8) ({file}`lirc_options.conf`)";
22 configs = lib.mkOption {
23 type = lib.types.listOf lib.types.lines;
24 description = "Configurations for lircd to load, see man:lircd.conf(5) for details ({file}`lircd.conf`)";
27 extraArguments = lib.mkOption {
28 type = lib.types.listOf lib.types.str;
30 description = "Extra arguments to lircd.";
37 config = lib.mkIf cfg.enable {
39 # Note: LIRC executables raises a warning, if lirc_options.conf do not exists
40 environment.etc."lirc/lirc_options.conf".text = cfg.options;
42 passthru.lirc.socket = "/run/lirc/lircd";
44 environment.systemPackages = [ pkgs.lirc ];
46 systemd.sockets.lircd = {
47 description = "LIRC daemon socket";
48 wantedBy = [ "sockets.target" ];
50 ListenStream = config.passthru.lirc.socket;
56 systemd.services.lircd = let
57 configFile = pkgs.writeText "lircd.conf" (builtins.concatStringsSep "\n" cfg.configs);
59 description = "LIRC daemon service";
60 after = [ "network.target" ];
62 unitConfig.Documentation = [ "man:lircd(8)" ];
65 RuntimeDirectory = ["lirc" "lirc/lock"];
67 # Service runtime directory and socket share same folder.
68 # Following hacks are necessary to get everything right:
70 # 1. prevent socket deletion during stop and restart
71 RuntimeDirectoryPreserve = true;
73 # 2. fix runtime folder owner-ship, happens when socket activation
75 PermissionsStartOnly = true;
77 "${pkgs.coreutils}/bin/chown lirc /run/lirc/"
81 ${pkgs.lirc}/bin/lircd --nodaemon \
82 ${lib.escapeShellArgs cfg.extraArguments} \
90 uid = config.ids.uids.lirc;
92 description = "LIRC user for lircd";
95 users.groups.lirc.gid = config.ids.gids.lirc;