mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
fix: 🐛 Fix more errors in NixOS module definition
This commit is contained in:
parent
d46befbd1d
commit
2d4465617b
131
nix/module.nix
131
nix/module.nix
|
|
@ -54,6 +54,7 @@ in {
|
||||||
freeformType = configFormat.type;
|
freeformType = configFormat.type;
|
||||||
options = {};
|
options = {};
|
||||||
};
|
};
|
||||||
|
default = {};
|
||||||
description = "Overrides for the node's configuration file.";
|
description = "Overrides for the node's configuration file.";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -67,6 +68,7 @@ in {
|
||||||
freeformType = configFormat.type;
|
freeformType = configFormat.type;
|
||||||
options = {};
|
options = {};
|
||||||
};
|
};
|
||||||
|
default = {};
|
||||||
description = "Overrides for the node's configuration file.";
|
description = "Overrides for the node's configuration file.";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -97,70 +99,91 @@ in {
|
||||||
];
|
];
|
||||||
|
|
||||||
systemd.services =
|
systemd.services =
|
||||||
builtins.mapAttrs (nodeName: node: let
|
lib.mapAttrs' (nodeName: node: let
|
||||||
config = cfg.config // node.configOverrides;
|
|
||||||
configFile = builtins.toFile (configFormat.generate "config-${nodeName}" config);
|
|
||||||
in {
|
|
||||||
after = ["network-online.target"];
|
|
||||||
wantedBy = ["multi-user.target"];
|
|
||||||
requires = ["network-online.target"];
|
|
||||||
|
|
||||||
serviceConfig = {
|
|
||||||
Type = "simple";
|
|
||||||
Restart = "always";
|
|
||||||
|
|
||||||
User = cfg.user;
|
|
||||||
Group = cfg.group;
|
|
||||||
|
|
||||||
StateDirectory = "${name}";
|
|
||||||
StateDirectoryMode = "0700";
|
|
||||||
RuntimeDirectory = "${name}";
|
|
||||||
RuntimeDirectoryMode = "0700";
|
|
||||||
|
|
||||||
# Set the working directory to the data directory
|
|
||||||
WorkingDirectory = cfg.dataDir;
|
|
||||||
|
|
||||||
StandardOutput = "journal";
|
|
||||||
StandardError = "journal";
|
|
||||||
SyslogIdentifier = "${name}";
|
|
||||||
|
|
||||||
Environment = [
|
|
||||||
"CONFIG_FILE=${configFile}"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
path = [pkgs.versia-server];
|
|
||||||
}) (cfg.nodes.api ++ cfg.nodes.worker)
|
|
||||||
// builtins.mapAttrs (nodeName: node: let
|
|
||||||
type = "api";
|
type = "api";
|
||||||
exe = lib.getExe pkgs.versia-server;
|
exe = lib.getExe pkgs.versia-server;
|
||||||
in {
|
config = lib.recursiveUpdate cfg.config node.configOverrides;
|
||||||
name = "${name}-${type}-${nodeName}";
|
configFile = configFormat.generate "config-${nodeName}.toml" config;
|
||||||
description = "Versia Server ${node.name} (${type})";
|
in
|
||||||
|
lib.nameValuePair "${name}-${type}-${nodeName}" {
|
||||||
|
description = "Versia Server ${nodeName} (${type})";
|
||||||
|
|
||||||
serviceConfig.ExecStart = "${exe}";
|
requires = ["versia-server-root.target"];
|
||||||
}) (cfg.nodes.api)
|
partOf = ["versia-server-root.target"];
|
||||||
// builtins.mapAttrs (nodeName: node: let
|
|
||||||
|
serviceConfig = {
|
||||||
|
ExecStart = "${exe}";
|
||||||
|
Type = "simple";
|
||||||
|
Restart = "always";
|
||||||
|
|
||||||
|
User = cfg.user;
|
||||||
|
Group = cfg.group;
|
||||||
|
|
||||||
|
StateDirectory = "${name}";
|
||||||
|
StateDirectoryMode = "0700";
|
||||||
|
RuntimeDirectory = "${name}";
|
||||||
|
RuntimeDirectoryMode = "0700";
|
||||||
|
|
||||||
|
# Set the working directory to the data directory
|
||||||
|
WorkingDirectory = cfg.dataDir;
|
||||||
|
|
||||||
|
StandardOutput = "journal";
|
||||||
|
StandardError = "journal";
|
||||||
|
SyslogIdentifier = "${name}";
|
||||||
|
|
||||||
|
Environment = [
|
||||||
|
"CONFIG_FILE=${configFile}"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
}) (cfg.nodes.api)
|
||||||
|
// lib.mapAttrs' (nodeName: node: let
|
||||||
type = "worker";
|
type = "worker";
|
||||||
exe = lib.getExe pkgs.versia-server-worker;
|
exe = lib.getExe pkgs.versia-server-worker;
|
||||||
in {
|
config = lib.recursiveUpdate cfg.config node.configOverrides;
|
||||||
name = "${name}-${type}-${nodeName}";
|
configFile = configFormat.generate "config-${nodeName}.toml" config;
|
||||||
description = "Versia Server ${node.name} (${type})";
|
in
|
||||||
|
lib.nameValuePair "${name}-${type}-${nodeName}" {
|
||||||
|
description = "Versia Server ${nodeName} (${type})";
|
||||||
|
|
||||||
serviceConfig.ExecStart = "${exe}";
|
requires = ["versia-server-root.target"];
|
||||||
}) (cfg.nodes.worker);
|
partOf = ["versia-server-root.target"];
|
||||||
|
|
||||||
systemd.tmpfiles.rules = [
|
serviceConfig = {
|
||||||
{
|
ExecStart = "${exe}";
|
||||||
# Create the data directory with the correct permissions
|
Type = "simple";
|
||||||
line = "d ${cfg.dataDir} - - - - ${cfg.user} ${cfg.group}";
|
Restart = "always";
|
||||||
}
|
|
||||||
];
|
User = cfg.user;
|
||||||
|
Group = cfg.group;
|
||||||
|
|
||||||
|
StateDirectory = "${name}";
|
||||||
|
StateDirectoryMode = "0700";
|
||||||
|
RuntimeDirectory = "${name}";
|
||||||
|
RuntimeDirectoryMode = "0700";
|
||||||
|
|
||||||
|
# Set the working directory to the data directory
|
||||||
|
WorkingDirectory = cfg.dataDir;
|
||||||
|
|
||||||
|
StandardOutput = "journal";
|
||||||
|
StandardError = "journal";
|
||||||
|
SyslogIdentifier = "${name}";
|
||||||
|
|
||||||
|
Environment = [
|
||||||
|
"CONFIG_FILE=${configFile}"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
}) (cfg.nodes.worker);
|
||||||
|
|
||||||
|
systemd.targets.versia-server-root = {
|
||||||
|
description = "Versia Server root target, starts and stop all the child nodes.";
|
||||||
|
wantedBy = ["multi-user.target"];
|
||||||
|
};
|
||||||
|
|
||||||
|
systemd.tmpfiles.rules = ["d ${cfg.dataDir} - - - - ${cfg.user} ${cfg.group}"];
|
||||||
|
|
||||||
users = {
|
users = {
|
||||||
groups = {
|
groups = {
|
||||||
"${cfg.group}" = {
|
"${cfg.group}" = {};
|
||||||
description = "Group for the Versia Server";
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
users = {
|
users = {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue