1 { config, pkgs, lib, ... }:
3 cfg = config.services.nncp;
4 settingsFormat = pkgs.formats.json { };
7 options.services.nncp = {
9 enable = lib.mkEnableOption "NNCP Daemon";
11 type = lib.types.port;
15 enable = lib.mkEnableOption "NNCP Caller";
17 configFile = lib.mkOption {
18 type = lib.types.path;
19 default = settingsFormat.generate "nncp.hjson" cfg.settings;
21 dataDir = lib.mkOption {
22 type = lib.types.path;
23 default = "/var/lib/nncp";
29 group = lib.mkOption {
33 settings = lib.mkOption {
37 systemd.tmpfiles.rules = lib.mkIf (cfg.daemon.enable || cfg.caller.enable) [
38 "d '${cfg.dataDir}' 0770 ${cfg.user} ${cfg.group}"
39 "Z '${cfg.dataDir}' 0770 ${cfg.user} ${cfg.group}"
40 "d '/var/spool/nncp' 0770 ${cfg.user} ${cfg.group}"
41 "Z '/var/spool/nncp' 0770 ${cfg.user} ${cfg.group}"
43 systemd.paths."nncp-watcher" = lib.mkIf (cfg.daemon.enable || cfg.caller.enable) {
44 wantedBy = [ "multi-user.target" ];
46 PathModified = "/run/keys/nncp";
47 Unit = "nncp-reloader.service";
50 systemd.services."nncp-reloader" = lib.mkIf (cfg.daemon.enable || cfg.caller.enable) {
51 after = [ "networking.target" ];
53 exec ${pkgs.nncp}/bin/nncp-cfgdir -cfg ${cfg.configFile} -dump ${cfg.dataDir}
54 exec systemd-tmpfiles --create
58 WorkingDirectory = "${cfg.dataDir}";
61 systemd.services.nncp-daemon = lib.mkIf cfg.daemon.enable {
62 # wantedBy = [ "multi-user.target" ];
63 after = [ "nncp-reloader.service" ];
64 description = "Node to Node Copy Protocol Daemon";
69 ExecStart = ''${pkgs.nncp}/bin/nncp-daemon -autotoss -noprogress -bind "0.0.0.0:${toString cfg.daemon.port}" -cfg ${cfg.dataDir}'';
73 StateDirectory = "nncp";
74 WorkingDirectory = "${cfg.dataDir}";
77 systemd.services.nncp-caller = lib.mkIf cfg.caller.enable {
78 # wantedBy = [ "multi-user.target" ];
79 after = [ "nncp-reloader.service" ];
80 description = "Node to Node Copy Protocol Caller";
85 ExecStart = ''${pkgs.nncp}/bin/nncp-caller -autotoss -noprogress -cfg ${cfg.dataDir}'';
89 StateDirectory = "nncp";
90 WorkingDirectory = "${cfg.dataDir}";
93 users.users = lib.mkIf (cfg.user == "nncp") {
95 description = "NNCP daemon user";
101 users.groups = lib.mkIf (cfg.group == "nncp") { nncp = { }; };