Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add allowedSymlinks option #117

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions modules/minecraft-servers.nix
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ let
then formatExtensions.${head extension} or error
else error;

txtList =
{ }:
{
type = with lib.types; listOf str;
generate = name: value: pkgs.writeText name (lib.concatStringsSep "\n" value);
};

formatExtensions = with pkgs.formats; {
"yml" = yaml { };
"yaml" = yaml { };
Expand All @@ -50,6 +57,7 @@ let
"properties" = keyValue { };
"toml" = toml { };
"ini" = ini { };
"txt" = txtList { };
};

configType = types.submodule {
Expand Down Expand Up @@ -449,6 +457,24 @@ in
'';
};

allowedSymlinks = mkOption {
default = ["/nix/store"];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than setting this as a default, it should instead be added as part of config. Otherwise, it leads to the unintuitive behavior of adding to allowedSymlinks removing /nix/store from the list. Removing /nix/store should require lib.mkForce.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're totally right. I'll get that fixed

type = with types; listOf str;
example = literalExpression ''
[
"/mnt/worlds"
]
'';
description = ''
Minecraft 1.20+ disallows symlinks inside world directories, unless
its destinations are allow-listed. /nix/store is allowed by default,
but you may add more destinations through this option. See
<link xlink:href="https://help.minecraft.net/hc/en-us/articles/16165590199181"/>
for more information.
'';

};

package = mkOption {
description = "The Minecraft server package to use.";
type = types.package;
Expand Down Expand Up @@ -598,6 +624,7 @@ in
"whitelist.json".value = mapAttrsToList (n: v: { name = n; uuid = v; }) conf.whitelist;
"ops.json".value = mapAttrsToList (n: v: { name = n; uuid = v.uuid; level = v.level; bypassesPlayerLimit = v.bypassesPlayerLimit; }) conf.operators;
"server.properties".value = conf.serverProperties;
"allowed_symlinks.txt".value = conf.allowedSymlinks;
} // conf.files);

msConfig = managementSystemConfig name conf;
Expand Down
1 change: 1 addition & 0 deletions tests/simple.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ nixosTest {
server.wait_for_unit(f"minecraft-server-{name}.service")
server.wait_for_open_port(25565)
server.wait_until_succeeds(grep_logs("Done ([0-9.]\+s)! For help, type \"help\""), timeout=30)
server.succeed(f"test -e /srv/minecraft/{name}/allowed_symlinks.txt")
'';
}