nixos/services.crossfire-server: remove with lib;
This commit is contained in:
@@ -1,21 +1,18 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.services.crossfire-server;
|
||||
serverPort = 13327;
|
||||
in {
|
||||
options.services.crossfire-server = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
enable = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
If enabled, the Crossfire game server will be started at boot.
|
||||
'';
|
||||
};
|
||||
|
||||
package = mkPackageOption pkgs "crossfire-server" {
|
||||
package = lib.mkPackageOption pkgs "crossfire-server" {
|
||||
extraDescription = ''
|
||||
::: {.note}
|
||||
This will also be used for map/arch data, if you don't change {option}`dataDir`
|
||||
@@ -23,10 +20,10 @@ in {
|
||||
'';
|
||||
};
|
||||
|
||||
dataDir = mkOption {
|
||||
type = types.str;
|
||||
dataDir = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "${cfg.package}/share/crossfire";
|
||||
defaultText = literalExpression ''"''${config.services.crossfire.package}/share/crossfire"'';
|
||||
defaultText = lib.literalExpression ''"''${config.services.crossfire.package}/share/crossfire"'';
|
||||
description = ''
|
||||
Where to load readonly data from -- maps, archetypes, treasure tables,
|
||||
and the like. If you plan to edit the data on the live server (rather
|
||||
@@ -36,8 +33,8 @@ in {
|
||||
'';
|
||||
};
|
||||
|
||||
stateDir = mkOption {
|
||||
type = types.str;
|
||||
stateDir = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "/var/lib/crossfire";
|
||||
description = ''
|
||||
Where to store runtime data (save files, persistent items, etc).
|
||||
@@ -49,16 +46,16 @@ in {
|
||||
'';
|
||||
};
|
||||
|
||||
openFirewall = mkOption {
|
||||
type = types.bool;
|
||||
openFirewall = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Whether to open ports in the firewall for the server.
|
||||
'';
|
||||
};
|
||||
|
||||
configFiles = mkOption {
|
||||
type = types.attrsOf types.str;
|
||||
configFiles = lib.mkOption {
|
||||
type = lib.types.attrsOf lib.types.str;
|
||||
description = ''
|
||||
Text to append to the corresponding configuration files. Note that the
|
||||
files given in the example are *not* the complete set of files available
|
||||
@@ -70,7 +67,7 @@ in {
|
||||
overwrite the example files that come with the server, rather than being
|
||||
appended to them as the other configuration files are.
|
||||
'';
|
||||
example = literalExpression ''
|
||||
example = lib.literalExpression ''
|
||||
{
|
||||
dm_file = '''
|
||||
admin:secret_password:localhost
|
||||
@@ -101,7 +98,7 @@ in {
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
config = lib.mkIf cfg.enable {
|
||||
users.users.crossfire = {
|
||||
description = "Crossfire server daemon user";
|
||||
home = cfg.stateDir;
|
||||
@@ -120,8 +117,8 @@ in {
|
||||
(name: value: lib.attrsets.nameValuePair "crossfire/${name}" {
|
||||
mode = "0644";
|
||||
text =
|
||||
(optionalString (!elem name ["motd" "news" "rules"])
|
||||
(fileContents "${cfg.package}/etc/crossfire/${name}"))
|
||||
(lib.optionalString (!lib.elem name ["motd" "news" "rules"])
|
||||
(lib.fileContents "${cfg.package}/etc/crossfire/${name}"))
|
||||
+ "\n${value}";
|
||||
}) ({
|
||||
ban_file = "";
|
||||
@@ -129,9 +126,9 @@ in {
|
||||
exp_table = "";
|
||||
forbid = "";
|
||||
metaserver2 = "";
|
||||
motd = fileContents "${cfg.package}/etc/crossfire/motd";
|
||||
news = fileContents "${cfg.package}/etc/crossfire/news";
|
||||
rules = fileContents "${cfg.package}/etc/crossfire/rules";
|
||||
motd = lib.fileContents "${cfg.package}/etc/crossfire/motd";
|
||||
news = lib.fileContents "${cfg.package}/etc/crossfire/news";
|
||||
rules = lib.fileContents "${cfg.package}/etc/crossfire/rules";
|
||||
settings = "";
|
||||
stat_bonus = "";
|
||||
} // cfg.configFiles);
|
||||
@@ -141,7 +138,7 @@ in {
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
after = [ "network.target" ];
|
||||
|
||||
serviceConfig = mkMerge [
|
||||
serviceConfig = lib.mkMerge [
|
||||
{
|
||||
ExecStart = "${cfg.package}/bin/crossfire-server -conf /etc/crossfire -local '${cfg.stateDir}' -data '${cfg.dataDir}'";
|
||||
Restart = "always";
|
||||
@@ -149,7 +146,7 @@ in {
|
||||
Group = "crossfire";
|
||||
WorkingDirectory = cfg.stateDir;
|
||||
}
|
||||
(mkIf (cfg.stateDir == "/var/lib/crossfire") {
|
||||
(lib.mkIf (cfg.stateDir == "/var/lib/crossfire") {
|
||||
StateDirectory = "crossfire";
|
||||
})
|
||||
];
|
||||
@@ -170,7 +167,7 @@ in {
|
||||
'';
|
||||
};
|
||||
|
||||
networking.firewall = mkIf cfg.openFirewall {
|
||||
networking.firewall = lib.mkIf cfg.openFirewall {
|
||||
allowedTCPPorts = [ serverPort ];
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user