diff options
author | Linnnus <[email protected]> | 2025-01-29 20:24:30 +0100 |
---|---|---|
committer | Linnnus <[email protected]> | 2025-01-29 20:24:30 +0100 |
commit | 27f702a9f3e599d872111036458c60af3f3ee472 (patch) | |
tree | 1e9ae7491e41f0b29390b3e667992df1fd0617c3 /modules/nixos | |
parent | 4045192587574bc33caf91d99f3b0bdc8a832782 (diff) |
on-demand-minecraft: Add ops list
Diffstat (limited to 'modules/nixos')
-rw-r--r-- | modules/nixos/on-demand-minecraft/default.nix | 78 |
1 files changed, 69 insertions, 9 deletions
diff --git a/modules/nixos/on-demand-minecraft/default.nix b/modules/nixos/on-demand-minecraft/default.nix index 9497d3f..c84e2ed 100644 --- a/modules/nixos/on-demand-minecraft/default.nix +++ b/modules/nixos/on-demand-minecraft/default.nix @@ -8,6 +8,9 @@ }: let inherit (lib) mkIf mkOption mkEnableOption types; + # Custom type for Minecraft UUIDs which are used to uniquely identify players. + minecraftUuid = lib.types.strMatching "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}" // {description = "Minecraft UUID";}; + cfg = config.services.on-demand-minecraft; in { options.services.on-demand-minecraft = { @@ -113,15 +116,7 @@ in { `services.on-demand-minecraft.server-properties` by setting `white-list = true`. ''; - type = with types; let - minecraftUuid = - strMatching - "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}" - // { - description = "Minecraft UUID"; - }; - in - attrsOf minecraftUuid; + type = with types; attrsOf minecraftUuid; example = lib.literalExpression '' { username1 = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; @@ -131,6 +126,56 @@ in { default = {}; }; + ops = mkOption { + description = '' + List of players with operator status. + + See <https://minecraft.wiki/w/Ops.json> for a description of how ops work. + ''; + type = with types; let + opsEntry = submodule { + options = { + username = mkOption { + description = "The player's username"; + type = nonEmptyStr; + }; + + uuid = mkOption { + description = '' + The UUID associated with the player. + + You can use <https://mcuuid.net/> to get a Minecraft UUID for a username. + ''; + type = minecraftUuid; + }; + + level = mkOption { + description = '' + The permission level that this user should be given. There are 5 possible levels: + + - Level 0: Everyone + - Level 1: Moderator + - Level 2: Gamemaster + - Level 3: Administrator + - Level 4: Owner + + See <https://minecraft.wiki/w/Permission_level> for an explanation of user permission levels. + ''; + type = ints.between 0 4; + }; + + bypasses-player-limit = mkOption { + description = "If true, the operator can join the server even if the player limit has been reached."; + type = bool; + default = false; + }; + }; + }; + in + listOf opsEntry; + default = []; + }; + jvm-options = mkOption { description = "JVM options for the Minecraft server. List of command line arguments."; type = with types; listOf str; @@ -217,6 +262,20 @@ in { }) cfg.whitelist)); + # Takes a mapping of old attribute name -> new attribute name and applies + # it to the given attribute set. + renameAttrs = mappings: attrset: lib.attrsets.mapAttrs' (name: value: lib.attrsets.nameValuePair (mappings.${name} or name) value) attrset; + + ops-file = + pkgs.writeText "ops.json" + (builtins.toJSON ( + map (renameAttrs { + "bypasses-player-limit" = "bypassesPlayerlimit"; + "username" = "name"; + }) + cfg.ops + )); + start-server = pkgs.writeShellScript "minecraft-server-start.sh" '' # Switch to runtime directory. ${pkgs.busybox}/bin/mkdir -p "${cfg.data-dir}" @@ -226,6 +285,7 @@ in { # Set up/update environment for server ln -sf ${eula-file} eula.txt ln -sf ${whitelist-file} whitelist.json + ln -sf ${ops-file} ops.json cp -f ${server-properties-file} server.properties chmod u+w server.properties # Must be writable because server regenerates it. |