syncthing: alias config.services.syncthing
This commit is contained in:
parent
43141c67fd
commit
f76f819cd7
|
@ -2,28 +2,29 @@
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
cfg = config.krebs.syncthing;
|
kcfg = config.krebs.syncthing;
|
||||||
|
scfg = config.services.syncthing;
|
||||||
|
|
||||||
devices = mapAttrsToList (name: peer: {
|
devices = mapAttrsToList (name: peer: {
|
||||||
name = name;
|
name = name;
|
||||||
deviceID = peer.id;
|
deviceID = peer.id;
|
||||||
addresses = peer.addresses;
|
addresses = peer.addresses;
|
||||||
}) cfg.peers;
|
}) kcfg.peers;
|
||||||
|
|
||||||
folders = mapAttrsToList ( _: folder: {
|
folders = mapAttrsToList ( _: folder: {
|
||||||
inherit (folder) path id type;
|
inherit (folder) path id type;
|
||||||
devices = map (peer: { deviceId = cfg.peers.${peer}.id; }) folder.peers;
|
devices = map (peer: { deviceId = kcfg.peers.${peer}.id; }) folder.peers;
|
||||||
rescanIntervalS = folder.rescanInterval;
|
rescanIntervalS = folder.rescanInterval;
|
||||||
fsWatcherEnabled = folder.watch;
|
fsWatcherEnabled = folder.watch;
|
||||||
fsWatcherDelayS = folder.watchDelay;
|
fsWatcherDelayS = folder.watchDelay;
|
||||||
ignoreDelete = folder.ignoreDelete;
|
ignoreDelete = folder.ignoreDelete;
|
||||||
ignorePerms = folder.ignorePerms;
|
ignorePerms = folder.ignorePerms;
|
||||||
}) cfg.folders;
|
}) kcfg.folders;
|
||||||
|
|
||||||
getApiKey = pkgs.writeDash "getAPIKey" ''
|
getApiKey = pkgs.writeDash "getAPIKey" ''
|
||||||
${pkgs.libxml2}/bin/xmllint \
|
${pkgs.libxml2}/bin/xmllint \
|
||||||
--xpath 'string(configuration/gui/apikey)'\
|
--xpath 'string(configuration/gui/apikey)'\
|
||||||
${config.services.syncthing.dataDir}/config.xml
|
${scfg.dataDir}/config.xml
|
||||||
'';
|
'';
|
||||||
|
|
||||||
updateConfig = pkgs.writeDash "merge-syncthing-config" ''
|
updateConfig = pkgs.writeDash "merge-syncthing-config" ''
|
||||||
|
@ -136,19 +137,19 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = (mkIf cfg.enable) {
|
config = mkIf kcfg.enable {
|
||||||
|
|
||||||
systemd.services.syncthing = mkIf (cfg.cert != null || cfg.key != null) {
|
systemd.services.syncthing = mkIf (kcfg.cert != null || kcfg.key != null) {
|
||||||
preStart = ''
|
preStart = ''
|
||||||
${optionalString (cfg.cert != null) ''
|
${optionalString (kcfg.cert != null) ''
|
||||||
cp ${toString cfg.cert} ${config.services.syncthing.dataDir}/cert.pem
|
cp ${toString kcfg.cert} ${scfg.dataDir}/cert.pem
|
||||||
chown ${config.services.syncthing.user}:${config.services.syncthing.group} ${config.services.syncthing.dataDir}/cert.pem
|
chown ${scfg.user}:${scfg.group} ${scfg.dataDir}/cert.pem
|
||||||
chmod 400 ${config.services.syncthing.dataDir}/cert.pem
|
chmod 400 ${scfg.dataDir}/cert.pem
|
||||||
''}
|
''}
|
||||||
${optionalString (cfg.key != null) ''
|
${optionalString (kcfg.key != null) ''
|
||||||
cp ${toString cfg.key} ${config.services.syncthing.dataDir}/key.pem
|
cp ${toString kcfg.key} ${scfg.dataDir}/key.pem
|
||||||
chown ${config.services.syncthing.user}:${config.services.syncthing.group} ${config.services.syncthing.dataDir}/key.pem
|
chown ${scfg.user}:${scfg.group} ${scfg.dataDir}/key.pem
|
||||||
chmod 400 ${config.services.syncthing.dataDir}/key.pem
|
chmod 400 ${scfg.dataDir}/key.pem
|
||||||
''}
|
''}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
@ -158,7 +159,7 @@ in
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
User = config.services.syncthing.user;
|
User = scfg.user;
|
||||||
RemainAfterExit = true;
|
RemainAfterExit = true;
|
||||||
Type = "oneshot";
|
Type = "oneshot";
|
||||||
ExecStart = updateConfig;
|
ExecStart = updateConfig;
|
||||||
|
|
Loading…
Reference in a new issue