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