···
6
+
CONTAINS_NEWLINE_RE = ".*\n.*";
7
+
# The following values are reserved as complete option values:
8
+
# { - start of a group.
9
+
# """ - start of a multi-line string.
10
+
RESERVED_VALUE_RE = "[[:space:]]*(\"\"\"|\\{)[[:space:]]*";
11
+
NEEDS_MULTILINE_RE = "${CONTAINS_NEWLINE_RE}|${RESERVED_VALUE_RE}";
13
+
# There is no way to encode """ on its own line in a Minetest config.
14
+
UNESCAPABLE_RE = ".*\n\"\"\"\n.*";
16
+
toConfMultiline = name: value:
17
+
assert lib.assertMsg
18
+
((builtins.match UNESCAPABLE_RE value) == null)
19
+
''""" can't be on its own line in a minetest config.'';
20
+
"${name} = \"\"\"\n${value}\n\"\"\"\n";
26
+
bool = "${name} = ${toString value}\n";
27
+
int = "${name} = ${toString value}\n";
29
+
set = "${name} = {\n${toConf value}}\n";
31
+
if (builtins.match NEEDS_MULTILINE_RE value) != null
32
+
then toConfMultiline name value
33
+
else "${name} = ${value}\n";
34
+
}.${builtins.typeOf value})
cfg = config.services.minetest-server;
7
-
flag = val: name: optionalString (val != null) "--${name} ${toString val} ";
38
+
flag = val: name: lib.optionals (val != null) ["--${name}" "${toString val}"];
9
-
(flag cfg.gameId "gameid")
10
-
(flag cfg.world "world")
11
-
(flag cfg.configPath "config")
12
-
(flag cfg.logPath "logfile")
13
-
(flag cfg.port "port")
44
+
if cfg.configPath != null
45
+
then ["--config" cfg.configPath]
46
+
else ["--config" (builtins.toFile "minetest.conf" (toConf cfg.config))])
47
+
++ (flag cfg.gameId "gameid")
48
+
++ (flag cfg.world "world")
49
+
++ (flag cfg.logPath "logfile")
50
+
++ (flag cfg.port "port")
···
96
+
type = types.attrsOf types.anything;
98
+
description = lib.mdDoc ''
99
+
Settings to add to the minetest config file.
101
+
This option is ignored if `configPath` is set.
type = types.nullOr types.path;
···
If set to null, the default 30000 will be used.
126
+
extraArgs = mkOption {
127
+
type = types.listOf types.str;
129
+
description = lib.mdDoc ''
130
+
Additional command line flags to pass to the minetest executable.
···
103
-
exec ${pkgs.minetest}/bin/minetest --server ${concatStrings flags}
158
+
exec ${pkgs.minetest}/bin/minetest ${lib.escapeShellArgs flags}