Infinidoge / nix-minecraft

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

Write file and symlinks from expressions #29

Closed Misterio77 closed 1 year ago

Misterio77 commented 1 year ago

Building upon https://github.com/Infinidoge/nix-minecraft/pull/18.

Diff from #18 to this: https://github.com/Infinidoge/nix-minecraft/compare/Misterio77:deref-symlinks...Misterio77:file-formats

So, basically file/symlink items can now either be:

This is really really convenient for writing configuration files, as you can simply do them in nixlang without having to call any sort of function to write it.

Here's a real-world example:

{ pkgs, ... }: {
  services.minecraft-servers.servers.velocity = {
    enable = true;
    # ...
    files = {
      "velocity.toml".value = {
        config-version = "2.5";
        bind = "0.0.0.0:25565";
        player-info-forwarding-mode = "modern";
        forwarding-secret-file = "";
        forwarding-secret = "@VELOCITY_FORWARDING_SECRET@";
        online-mode = true;
        servers = {
          survival = "localhost:25561";
          limbo = "localhost:25560";
          try = [ "survival" "limbo" ];
        };
        forced-hosts = { };
        query = {
          enabled = true;
          port = 25565;
        };
        # ...
      };
      "plugins/librelogin/config.conf".value = {
        allowed-commands-while-unauthorized = [
          "login"
          "register"
          "2fa"
          "2faconfirm"
        ];
        auto-register = true;
        # ...
      };
      # We don't know what format .conf is, so specify it.
      "plugins/librelogin/config.conf".format = pkgs.formats.json { };
    };
  };
}

A nice consequence is that whitelist.json, server.properties, and eula.txt also don't have to be manually written with writeText.

TODO: document this in files and symlinks descriptions.

Misterio77 commented 1 year ago

This should help us with adding comments: https://github.com/NixOS/nixpkgs/pull/224456

Misterio77 commented 1 year ago

Hey @Infinidoge, I think it'll still take a while to merge the comments PR, do you think we can perhaps merge this one as-is? I can work on the comments later.

Infinidoge commented 1 year ago

Once again sorry for this taking so long! Thank you very much for the contribution, and for your patience with me!