···
1
+
{ config, lib, pkgs, ... }:
6
+
cfg = config.services.minetest-server;
7
+
flag = val: name: if val != null then "--${name} ${val} " else "";
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")
18
+
services.minetest-server = {
22
+
description = "If enabled, starts a Minetest Server.";
26
+
type = types.nullOr types.str;
29
+
Id of the game to use. To list available games run
30
+
`minetestserver --gameid list`.
32
+
If only one game exists, this option can be null.
37
+
type = types.nullOr types.path;
40
+
Name of the world to use. To list available worlds run
41
+
`minetestserver --world list`.
43
+
If only one world exists, this option can be null.
47
+
configPath = mkOption {
48
+
type = types.nullOr types.path;
51
+
Path to the config to use.
53
+
If set to null, the config of the running user will be used:
54
+
`~/.minetest/minetest.conf`.
58
+
logPath = mkOption {
59
+
type = types.nullOr types.path;
62
+
Path to logfile for logging.
64
+
If set to null, logging will be output to stdout which means
65
+
all output will be catched by systemd.
70
+
type = types.nullOr types.int;
73
+
Port number to bind to.
75
+
If set to null, the default 30000 will be used.
81
+
config = mkIf cfg.enable {
82
+
users.extraUsers.minetest = {
83
+
description = "Minetest Server Service user";
84
+
home = "/var/lib/minetest";
86
+
uid = config.ids.uids.minetest;
89
+
systemd.services.minetest-server = {
90
+
description = "Minetest Server Service";
91
+
wantedBy = [ "multi-user.target" ];
92
+
after = [ "network.target" ];
94
+
serviceConfig.Restart = "always";
95
+
serviceConfig.User = "minetest";
98
+
cd /var/lib/minetest
100
+
exec ${pkgs.minetest}/bin/minetestserver ${concatStrings flags}