2022-03-30 09:31:56 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
nncpCfgFile = "/run/nncp.hjson";
|
|
|
|
programCfg = config.programs.nncp;
|
|
|
|
settingsFormat = pkgs.formats.json { };
|
|
|
|
jsonCfgFile = settingsFormat.generate "nncp.json" programCfg.settings;
|
|
|
|
pkg = programCfg.package;
|
|
|
|
in {
|
|
|
|
options.programs.nncp = {
|
|
|
|
|
|
|
|
enable =
|
2024-05-15 15:35:15 +00:00
|
|
|
lib.mkEnableOption "NNCP (Node to Node copy) utilities and configuration";
|
2022-03-30 09:31:56 +00:00
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
group = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2022-03-30 09:31:56 +00:00
|
|
|
default = "uucp";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-03-30 09:31:56 +00:00
|
|
|
The group under which NNCP files shall be owned.
|
|
|
|
Any member of this group may access the secret keys
|
|
|
|
of this NNCP node.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
package = lib.mkPackageOption pkgs "nncp" { };
|
2022-03-30 09:31:56 +00:00
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
secrets = lib.mkOption {
|
|
|
|
type = with lib.types; listOf str;
|
2022-03-30 09:31:56 +00:00
|
|
|
example = [ "/run/keys/nncp.hjson" ];
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-03-30 09:31:56 +00:00
|
|
|
A list of paths to NNCP configuration files that should not be
|
|
|
|
in the Nix store. These files are layered on top of the values at
|
2022-08-12 12:06:08 +00:00
|
|
|
[](#opt-programs.nncp.settings).
|
2022-03-30 09:31:56 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
settings = lib.mkOption {
|
2022-03-30 09:31:56 +00:00
|
|
|
type = settingsFormat.type;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-03-30 09:31:56 +00:00
|
|
|
NNCP configuration, see
|
2022-08-12 12:06:08 +00:00
|
|
|
<http://www.nncpgo.org/Configuration.html>.
|
2022-03-30 09:31:56 +00:00
|
|
|
At runtime these settings will be overlayed by the contents of
|
2022-08-12 12:06:08 +00:00
|
|
|
[](#opt-programs.nncp.secrets) into the file
|
|
|
|
`${nncpCfgFile}`. Node keypairs go in
|
|
|
|
`secrets`, do not specify them in
|
|
|
|
`settings` as they will be leaked into
|
|
|
|
`/nix/store`!
|
2022-03-30 09:31:56 +00:00
|
|
|
'';
|
|
|
|
default = { };
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
config = lib.mkIf programCfg.enable {
|
2022-03-30 09:31:56 +00:00
|
|
|
|
|
|
|
environment = {
|
|
|
|
systemPackages = [ pkg ];
|
|
|
|
etc."nncp.hjson".source = nncpCfgFile;
|
|
|
|
};
|
|
|
|
|
|
|
|
programs.nncp.settings = {
|
2024-05-15 15:35:15 +00:00
|
|
|
spool = lib.mkDefault "/var/spool/nncp";
|
|
|
|
log = lib.mkDefault "/var/spool/nncp/log";
|
2022-03-30 09:31:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d ${programCfg.settings.spool} 0770 root ${programCfg.group}"
|
|
|
|
"f ${programCfg.settings.log} 0770 root ${programCfg.group}"
|
|
|
|
];
|
|
|
|
|
|
|
|
systemd.services.nncp-config = {
|
|
|
|
path = [ pkg ];
|
|
|
|
description = "Generate NNCP configuration";
|
|
|
|
wantedBy = [ "basic.target" ];
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
script = ''
|
2024-10-09 16:51:18 +00:00
|
|
|
umask 127
|
|
|
|
rm -f ${nncpCfgFile}
|
|
|
|
for f in ${jsonCfgFile} ${builtins.toString config.programs.nncp.secrets}
|
|
|
|
do
|
|
|
|
${lib.getExe pkgs.hjson-go} -c <"$f"
|
|
|
|
done |${lib.getExe pkgs.jq} --slurp add >${nncpCfgFile}
|
2022-03-30 09:31:56 +00:00
|
|
|
chgrp ${programCfg.group} ${nncpCfgFile}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
meta.maintainers = with lib.maintainers; [ ehmry ];
|
|
|
|
}
|