1 { config, lib, pkgs, ... }:
6 cfg = config.services.lirc;
14 enable = mkEnableOption (lib.mdDoc "LIRC daemon");
22 description = lib.mdDoc "LIRC default options described in man:lircd(8) ({file}`lirc_options.conf`)";
26 type = types.listOf types.lines;
27 description = lib.mdDoc "Configurations for lircd to load, see man:lircd.conf(5) for details ({file}`lircd.conf`)";
30 extraArguments = mkOption {
31 type = types.listOf types.str;
33 description = lib.mdDoc "Extra arguments to lircd.";
40 config = mkIf cfg.enable {
42 # Note: LIRC executables raises a warning, if lirc_options.conf do not exists
43 environment.etc."lirc/lirc_options.conf".text = cfg.options;
45 passthru.lirc.socket = "/run/lirc/lircd";
47 environment.systemPackages = [ pkgs.lirc ];
49 systemd.sockets.lircd = {
50 description = "LIRC daemon socket";
51 wantedBy = [ "sockets.target" ];
53 ListenStream = config.passthru.lirc.socket;
59 systemd.services.lircd = let
60 configFile = pkgs.writeText "lircd.conf" (builtins.concatStringsSep "\n" cfg.configs);
62 description = "LIRC daemon service";
63 after = [ "network.target" ];
65 unitConfig.Documentation = [ "man:lircd(8)" ];
68 RuntimeDirectory = ["lirc" "lirc/lock"];
70 # Service runtime directory and socket share same folder.
71 # Following hacks are necessary to get everything right:
73 # 1. prevent socket deletion during stop and restart
74 RuntimeDirectoryPreserve = true;
76 # 2. fix runtime folder owner-ship, happens when socket activation
78 PermissionsStartOnly = true;
80 "${pkgs.coreutils}/bin/chown lirc /run/lirc/"
84 ${pkgs.lirc}/bin/lircd --nodaemon \
85 ${escapeShellArgs cfg.extraArguments} \
93 uid = config.ids.uids.lirc;
95 description = "LIRC user for lircd";
98 users.groups.lirc.gid = config.ids.gids.lirc;