Infinidoge / nix-minecraft

An attempt to better support Minecraft-related content for the Nix ecosystem
MIT License
249 stars 28 forks source link

Legacy whitelist and operators file for minecraft < 1.7.6 ? #102

Open arminius-smh opened 6 days ago

arminius-smh commented 6 days ago

Hello, since version 1.7.6 minecraft switched to uuids and transitioned from white-list.txt to whitelist.json and ops.txt to ops.json. So the whitelist and operators option of the module don't work for these versions since they only generate the uuid json version.

Since I don't think it's possible to know the minecraft version in the module, mabye something like a legacyWhitelist and legacyOperators option would be possible?

The old format is just the usernames in a list since name changes weren't possible:

user1
user2

I know that it's possible to just symlink the files with the content, but I think it would be nice to have dedicated options or some other way in the whitelist option that users know that these wont work for older versions of minecraft?

I've just come upon this issue doing servers for older modpacks, like hexxit or tekkit. I can also do a pr that can implement any solution, however I couldn't think of a good way to do this except for dedicated legacy options - or if you think this is unnecessary, that's fine too since the symlink option exist, but I just wanted to mention it here at least.

Infinidoge commented 4 days ago

The files and symlinks options are capable of generating files like this, they just don't understand the basic txt format. A simple format definition lets you define them inline again pretty easily:

let
  txtList = {}: {
    type = with lib.types; listOf str;
    generate = name: value: pkgs.writeText name (lib.concatStringsSep "\n" value);
  };
in
{ # In the config for a server
  files."whitelist.txt" = {
    format = txtList;
    value = [
      "person1"
      "person2"
      "person3"
    ];
  };
}

(Fair warning, I haven't fully tested this specifically, but it should work in theory.)

I'm mixed on dedicated legacy whitelist/ops options, mostly since they just feel a bit... cluttered. Something that could be done is have the whitelist/ops options accept both a list of strings and an attrset of strings, with it generating the respective file for each. That could be confusing to new users though. Still a bit on the fence.

That said, I definitely think something like txtList should be added to the nix-minecraft lib. A PR either documenting how to use files for this, or adding options for it, would be welcome.

Infinidoge commented 4 days ago

Thinking on it a tiny more, there should be a default txt file handling that accepts either str (listOf str) that defaults to either generate = pkgs.writeText or the generate shown above. That would be the most intuitive handling I feel.

Then you could just files."whitelist.txt".value = [ "a" "b" "c" ]; and it'll work as expected.

Plus then you could

files."something.txt".value = ''
  Hi!
  Hello!
  This is a text file!
'';
arminius-smh commented 4 days ago
format = txtList { };

ahh changing it to this works great, I'm starting to understand the code a bit more, I didn't quite grasp on how to use the files option before, a lot of nix is still magic to me

so with that files."white-list.txt".value = [ "a" "b" "c" ]; works

files."something.txt".value = ''
  Hi!
  Hello!
  This is a text file!
'';

wouldn't though, even with a change to txtList that accepts strings as well, since value only accepts either (attrsOf anything) (listOf anything) and I don't think the other pkgs.formats accept strings so that may be confusing again, if it would be added there

I tried myself add adding the txtList function and docs in https://github.com/Infinidoge/nix-minecraft/pull/103

and with the txt option added, I don't think legacy options are necessary, I feel like this was just a bit undocumented, or at least I couldn't grasp it before, I hope my pr will resolve this a bit, depending of what you think of it