nixos: improve config loading for syndicate-server
Use an intermediary configuration file to allow configuration reloading.
This commit is contained in:
parent
b7bf10234d
commit
327de24ea7
|
@ -46,51 +46,62 @@ with lib;
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
|
|
||||||
systemd.services = lib.attrsets.mapAttrs' (name: cfg: {
|
systemd.services = let
|
||||||
name = "syndicate-${name}";
|
serverCfgs =
|
||||||
value = let
|
lib.attrsets.filterAttrs (_: cfg: cfg.enable) config.services.syndicate;
|
||||||
flags = lib.strings.concatMapStrings (c: " --config ${c}") cfg.config;
|
in builtins.listToAttrs (lib.lists.flatten (lib.attrsets.mapAttrsToList
|
||||||
serviceConfig = {
|
(name: cfg:
|
||||||
ExecStart =
|
let
|
||||||
"${cfg.package}/bin/syndicate-server --no-banner ${flags}";
|
configFileName = ".syndicate-nixos-config.pr";
|
||||||
User = cfg.user;
|
configFile = pkgs.writeText configFileName
|
||||||
};
|
(lib.strings.concatMapStrings (dir: ''
|
||||||
in if builtins.match "tty[0-9]" name != null then {
|
<require-service <config-watcher "${dir}" $.>>
|
||||||
enable = true;
|
'') cfg.config);
|
||||||
description = "Syndicate dataspace server";
|
in [{
|
||||||
after = [
|
name = "syndicate-${name}";
|
||||||
"systemd-user-sessions.service"
|
value = let
|
||||||
"systemd-logind.service"
|
serviceConfig = let
|
||||||
"getty@${name}.service"
|
linkConfig =
|
||||||
];
|
"${pkgs.coreutils}/bin/ln -sf ${configFile} ${configFileName}";
|
||||||
before = [ "graphical.target" ];
|
in {
|
||||||
wants = [ "dbus.socket" "systemd-logind.service" ];
|
ExecStartPre = linkConfig;
|
||||||
wantedBy = [ "graphical.target" ];
|
ExecStart =
|
||||||
conflicts = [ "getty@${name}.service" ];
|
"${cfg.package}/bin/syndicate-server --no-banner --config ${configFileName}";
|
||||||
|
ExecReload = linkConfig;
|
||||||
restartIfChanged = false;
|
User = cfg.user;
|
||||||
unitConfig.ConditionPathExists = "/dev/${name}";
|
};
|
||||||
|
in {
|
||||||
serviceConfig = serviceConfig // {
|
description = "Syndicate dataspace server";
|
||||||
PAMName = "login";
|
restartIfChanged = false;
|
||||||
StandardError = "journal";
|
reloadTriggers = [ configFile ];
|
||||||
StandardInput = "tty-fail";
|
wantedBy = [ "multi-user.target" ];
|
||||||
StandardOutput = "journal";
|
} // (if builtins.match "tty[0-9]" name == null then {
|
||||||
TTYPath = "/dev/${name}";
|
inherit serviceConfig;
|
||||||
TTYReset = "yes";
|
} else {
|
||||||
TTYVHangup = "yes";
|
after = [
|
||||||
TTYVTDisallocate = "yes";
|
"systemd-user-sessions.service"
|
||||||
UtmpIdentifier = "%n";
|
"systemd-logind.service"
|
||||||
UtmpMode = "user";
|
"getty@${name}.service"
|
||||||
WorkingDirectory = "~";
|
];
|
||||||
};
|
wants = [ "dbus.socket" "systemd-logind.service" ];
|
||||||
} else {
|
conflicts = [ "getty@${name}.service" ];
|
||||||
description = "Syndicate dataspace server";
|
unitConfig.ConditionPathExists = "/dev/${name}";
|
||||||
wantedBy = [ "multi-user.target" ];
|
serviceConfig = serviceConfig // {
|
||||||
inherit serviceConfig;
|
PAMName = "login";
|
||||||
};
|
StandardError = "journal";
|
||||||
})
|
StandardInput = "tty-fail";
|
||||||
(lib.attrsets.filterAttrs (_: cfg: cfg.enable) config.services.syndicate);
|
StandardOutput = "journal";
|
||||||
|
TTYPath = "/dev/${name}";
|
||||||
|
TTYReset = "yes";
|
||||||
|
TTYVHangup = "yes";
|
||||||
|
TTYVTDisallocate = "yes";
|
||||||
|
UtmpIdentifier = "%n";
|
||||||
|
UtmpMode = "user";
|
||||||
|
WorkingDirectory = "~";
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}]) (lib.attrsets.filterAttrs (_: cfg: cfg.enable)
|
||||||
|
config.services.syndicate)));
|
||||||
|
|
||||||
systemd.targets.multi-user.wants = lib.lists.flatten
|
systemd.targets.multi-user.wants = lib.lists.flatten
|
||||||
(lib.attrsets.mapAttrsToList
|
(lib.attrsets.mapAttrsToList
|
||||||
|
|
Loading…
Reference in New Issue