modules/ipfs-cluster: manage service config

This commit is contained in:
Max Headroom 2022-10-22 01:09:25 +02:00
parent d86429d59e
commit e5d56e7073

View file

@ -9,6 +9,8 @@ let
(optionalString (cfg.initPeers != [ ]) "--peers") (optionalString (cfg.initPeers != [ ]) "--peers")
(lib.strings.concatStringsSep "," cfg.initPeers) (lib.strings.concatStringsSep "," cfg.initPeers)
]; ];
serviceJson = builtins.toFile "ipfs-cluster-service.json" (builtins.toJSON cfg.settings);
in { in {
###### interface ###### interface
@ -75,6 +77,12 @@ in {
A secret in the correct format can also be generated by: openssl rand -hex 32 A secret in the correct format can also be generated by: openssl rand -hex 32
''; '';
}; };
settings = mkOption {
type = types.attrs;
default = {};
description = "Configuration to be merged into service.json";
};
}; };
}; };
@ -115,7 +123,15 @@ in {
wants = [ "ipfs-cluster-init.service" ]; wants = [ "ipfs-cluster-init.service" ];
after = [ "ipfs-cluster-init.service" ]; after = [ "ipfs-cluster-init.service" ];
preStart = ''
${pkgs.jq}/bin/jq --slurp '.[0] * .[1]' '${cfg.dataDir}/service.json' ${serviceJson} \
| install -D -m 600 -o '${cfg.user}' -g '${cfg.group}' /dev/stdin '${cfg.dataDir}/.service.json.new'
mv '${cfg.dataDir}/.service.json.new' '${cfg.dataDir}/service.json'
'';
serviceConfig = { serviceConfig = {
Type = "notify";
RuntimeDirectory = "ipfs-cluster";
ExecStart = ExecStart =
[ "" "${cfg.package}/bin/ipfs-cluster-service daemon" ]; [ "" "${cfg.package}/bin/ipfs-cluster-service daemon" ];
User = cfg.user; User = cfg.user;