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

txt-file generation & docs symlinks/files value examples #103

Merged
merged 2 commits into from
Dec 29, 2024
Merged
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
54 changes: 53 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.<name>.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)
8 changes: 8 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