diff --git a/README.md b/README.md index 474ede30..1339b24a 100644 --- a/README.md +++ b/README.md @@ -408,5 +408,57 @@ This example takes an attrset of the IDs and hashes for Modrinth mods, fetches e } ``` +`symlinks` is also able to automatically infer the format of certain extensions: `yml, yaml, json, props, properties, toml, ini, txt` + +For example, +```nix +symlinks."myfile.json" = { + value = { + option = "value"; + }; +}; +``` + +Would symlink a file containing the following into the server's folder: +```json +{ + "option": "value" +} +``` + +Other formats are able to be generated by providing a format function: [Example Functions](https://github.com/NixOS/nixpkgs/blob/e7b543ba95681a01148d8c267d668bdcbd521fcb/pkgs/pkgs-lib/formats.nix) +Example: +```nix +let + extList = {}: { + type = with lib.types; listOf str; + generate = name: value: pkgs.writeText name (lib.concatStringsSep "\n" value); + }; +in +{ + symlinks."myfile.ext" = { + format = extList {}; + value = [ + "Hi!" + "Hello!" + ]; + }; +} +``` + #### `servers..files` -Things to copy into this server's data directory. Similar to symlinks, but these are actual files. Useful for configuration files that don't behave well when read-only. + +Things to copy into this server's data directory. Every option and example in `symlinks` works the same way for `files`, except that actual files are generated. Useful for configuration files that don't behave well when read-only. + +For example: +```nix +files."white-list.txt" = { + value = [ + "person1" + "person2" + "person3" + ]; +}; +``` + +generates a legacy `white-list.txt` that is needed for older minecraft versions (< 1.7.6) diff --git a/modules/minecraft-servers.nix b/modules/minecraft-servers.nix index 9bd6037e..7ea3c6dd 100644 --- a/modules/minecraft-servers.nix +++ b/modules/minecraft-servers.nix @@ -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 { }; @@ -50,6 +57,7 @@ let "properties" = keyValue { }; "toml" = toml { }; "ini" = ini { }; + "txt" = txtList { }; }; configType = types.submodule {