nix2lua/README.md

85 lines
1.6 KiB
Markdown
Raw Permalink Normal View History

2022-11-18 00:17:19 +03:00
# nix2lua
2022-11-19 04:41:28 +03:00
This is a small but functional library that converts your nix configurations
2024-03-13 00:10:08 +03:00
into Lua format.
2022-11-19 04:41:28 +03:00
This library was initially designed for my personal
2024-03-13 00:10:08 +03:00
[Neovim flake](https://git.pleshevski.ru/mynix/neovim).
2022-11-19 04:41:28 +03:00
2022-11-19 04:46:37 +03:00
# Installation
2022-11-19 04:41:28 +03:00
2024-03-13 00:10:08 +03:00
Add `nix2lua` as input to your `flake.nix`
2022-11-19 04:41:28 +03:00
```nix
{
inputs.nix2lua.url = "git+https://git.pleshevski.ru/mynix/nix2lua";
outputs = { nix2lua }:
let
luaTable = nix2lua.lib.toLua {
foo = "bar";
nvimTree.settings = {
open_on_setup = true;
renderer = {
group_empty = true;
full_name = true;
};
};
};
in luaTable;
}
```
2022-11-19 04:46:37 +03:00
# References
2022-11-19 04:41:28 +03:00
`toLua expr`
> Returns a string containing Lua representation of `expr`. Strings, integers,
2024-03-13 00:10:08 +03:00
> floats, boolean, lists and sets are mapped to their Lua equivalents.
2022-11-19 04:41:28 +03:00
>
> Null will be skipped. This is useful when you want to use an optional value.
2024-03-13 00:10:08 +03:00
> To render `nil` you should use the `LuaNil` function.
2022-11-19 04:41:28 +03:00
>
> ```nix
2022-11-19 05:03:59 +03:00
> toLua { foo = "bar"; }
> toLua [ 10 "foo" [ "bar" ] ]
2022-11-19 04:41:28 +03:00
> ```
2024-03-13 00:10:08 +03:00
`LuaNil`
2022-11-19 04:41:28 +03:00
2024-03-13 00:10:08 +03:00
> Creates a type that will be mapped by the `toLua` as `nil`
2022-11-19 04:41:28 +03:00
>
> ```nix
2024-03-13 00:10:08 +03:00
> toLua LuaNil
2022-11-19 04:41:28 +03:00
> ```
2024-02-28 12:50:08 +03:00
`LuaRaw expr`
2022-11-19 04:41:28 +03:00
> Creates a type that instructs `toLua` not to change the passed expression
> `expr`.
>
> ```nix
2022-11-19 05:03:59 +03:00
> toLua (mkLuaRaw "require('bar').baz")
2022-11-19 04:41:28 +03:00
> ```
`mkNamedField name expr`
2024-03-13 00:10:08 +03:00
> Creates a type that represents a named field in the Lua table. This type
> cannot exist outside a list or set.
2022-11-19 04:41:28 +03:00
>
2024-03-13 00:10:08 +03:00
> This is useful to create table with some named fields.
2022-11-19 04:41:28 +03:00
>
> ```nix
> toLua [
> "foo"
> (mkNamedField "bar" "baz")
2022-11-19 05:03:59 +03:00
> ]
2022-11-19 04:41:28 +03:00
> ```
2022-11-19 04:46:37 +03:00
# License
GNU General Public License v3.0 or later
See [COPYING](./COPYING) to see the full text.