1 { config, lib, pkgs, ... }:
5 nncpCfgFile = "/run/nncp.hjson";
6 programCfg = config.programs.nncp;
7 callerCfg = config.services.nncp.caller;
8 daemonCfg = config.services.nncp.daemon;
9 settingsFormat = pkgs.formats.json { };
10 jsonCfgFile = settingsFormat.generate "nncp.json" programCfg.settings;
11 pkg = programCfg.package;
17 enable = mkEnableOption ''
18 cron'ed NNCP TCP daemon caller.
19 The daemon will take configuration from
20 [](#opt-programs.nncp.settings)
22 extraArgs = mkOption {
23 type = with types; listOf str;
24 description = "Extra command-line arguments to pass to caller.";
26 example = [ "-autotoss" ];
31 enable = mkEnableOption ''
32 NNCP TCP synronization daemon.
33 The daemon will take configuration from
34 [](#opt-programs.nncp.settings)
37 enable = mkEnableOption "socket activation for nncp-daemon";
38 listenStreams = mkOption {
39 type = with types; listOf str;
41 TCP sockets to bind to.
42 See [](#opt-systemd.sockets._name_.listenStreams).
47 extraArgs = mkOption {
48 type = with types; listOf str;
49 description = "Extra command-line arguments to pass to daemon.";
51 example = [ "-autotoss" ];
58 config = mkIf (programCfg.enable or callerCfg.enable or daemonCfg.enable) {
61 assertion = with builtins;
64 let neigh = config.programs.nncp.settings.neigh or { };
65 in lib.lists.any (x: hasAttr "calls" x && x.calls != [ ])
67 in !callerCfg.enable || callerCongfigured;
68 message = "NNCP caller enabled but call configuration is missing";
71 systemd.services."nncp-caller" = {
72 inherit (callerCfg) enable;
73 description = "Croned NNCP TCP daemon caller.";
74 documentation = [ "http://www.nncpgo.org/nncp_002dcaller.html" ];
75 after = [ "network.target" ];
76 wantedBy = [ "multi-user.target" ];
79 ${pkg}/bin/nncp-caller -noprogress -cfg "${nncpCfgFile}" ${
80 lib.strings.escapeShellArgs callerCfg.extraArgs
87 systemd.services."nncp-daemon" = mkIf daemonCfg.enable {
88 enable = !daemonCfg.socketActivation.enable;
89 description = "NNCP TCP syncronization daemon.";
90 documentation = [ "http://www.nncpgo.org/nncp_002ddaemon.html" ];
91 after = [ "network.target" ];
92 wantedBy = [ "multi-user.target" ];
95 ${pkg}/bin/nncp-daemon -noprogress -cfg "${nncpCfgFile}" ${
96 lib.strings.escapeShellArgs daemonCfg.extraArgs
98 Restart = "on-failure";
104 systemd.services."nncp-daemon@" = mkIf daemonCfg.socketActivation.enable {
105 description = "NNCP TCP syncronization daemon.";
106 documentation = [ "http://www.nncpgo.org/nncp_002ddaemon.html" ];
107 after = [ "network.target" ];
110 ${pkg}/bin/nncp-daemon -noprogress -ucspi -cfg "${nncpCfgFile}" ${
111 lib.strings.escapeShellArgs daemonCfg.extraArgs
115 StandardInput = "socket";
116 StandardOutput = "inherit";
117 StandardError = "journal";
121 systemd.sockets.nncp-daemon = mkIf daemonCfg.socketActivation.enable {
122 inherit (daemonCfg.socketActivation) listenStreams;
123 description = "socket for NNCP TCP syncronization.";
124 conflicts = [ "nncp-daemon.service" ];
125 wantedBy = [ "sockets.target" ];
126 socketConfig.Accept = true;