1 { config, lib, pkgs, ... }:
5 nncpCfgFile = "/run/nncp.hjson";
6 programCfg = config.programs.nncp;
7 settingsFormat = pkgs.formats.json { };
8 jsonCfgFile = settingsFormat.generate "nncp.json" programCfg.settings;
9 pkg = programCfg.package;
11 options.programs.nncp = {
14 mkEnableOption (lib.mdDoc "NNCP (Node to Node copy) utilities and configuration");
19 description = lib.mdDoc ''
20 The group under which NNCP files shall be owned.
21 Any member of this group may access the secret keys
29 defaultText = literalExpression "pkgs.nncp";
30 description = lib.mdDoc "The NNCP package to use system-wide.";
34 type = with types; listOf str;
35 example = [ "/run/keys/nncp.hjson" ];
36 description = lib.mdDoc ''
37 A list of paths to NNCP configuration files that should not be
38 in the Nix store. These files are layered on top of the values at
39 [](#opt-programs.nncp.settings).
44 type = settingsFormat.type;
45 description = lib.mdDoc ''
46 NNCP configuration, see
47 <http://www.nncpgo.org/Configuration.html>.
48 At runtime these settings will be overlayed by the contents of
49 [](#opt-programs.nncp.secrets) into the file
50 `${nncpCfgFile}`. Node keypairs go in
51 `secrets`, do not specify them in
52 `settings` as they will be leaked into
60 config = mkIf programCfg.enable {
63 systemPackages = [ pkg ];
64 etc."nncp.hjson".source = nncpCfgFile;
67 programs.nncp.settings = {
68 spool = mkDefault "/var/spool/nncp";
69 log = mkDefault "/var/spool/nncp/log";
72 systemd.tmpfiles.rules = [
73 "d ${programCfg.settings.spool} 0770 root ${programCfg.group}"
74 "f ${programCfg.settings.log} 0770 root ${programCfg.group}"
77 systemd.services.nncp-config = {
79 description = "Generate NNCP configuration";
80 wantedBy = [ "basic.target" ];
81 serviceConfig.Type = "oneshot";
84 nncpCfgDir=$(mktemp --directory nncp.XXX)
85 for f in ${jsonCfgFile} ${toString config.programs.nncp.secrets}; do
86 tmpdir=$(mktemp --directory nncp.XXX)
87 nncp-cfgdir -cfg $f -dump $tmpdir
88 find $tmpdir -size 1c -delete
89 cp -a $tmpdir/* $nncpCfgDir/
92 nncp-cfgdir -load $nncpCfgDir > ${nncpCfgFile}
94 chgrp ${programCfg.group} ${nncpCfgFile}
95 chmod g+r ${nncpCfgFile}
100 meta.maintainers = with lib.maintainers; [ ehmry ];