This is a small but functional library that converts your nix configurations into lua format.
Find a file
2024-04-17 18:42:33 +03:00
.gitignore initial commit 2022-11-18 02:36:55 +03:00
COPYING fix license 2022-11-19 04:46:37 +03:00
flake.lock use makefile instead of script in flake.nix 2022-11-22 10:51:34 +03:00
flake.nix use makefile instead of script in flake.nix 2022-11-22 10:51:34 +03:00
lib.nix fix keyword separator in operations 2024-04-17 18:42:33 +03:00
lib.test.nix fix keyword separator in operations 2024-04-17 18:42:33 +03:00
Makefile add concat and concatLists 2024-04-17 11:20:56 +03:00
README.md doc: fix typo 2024-03-13 00:10:08 +03:00

nix2lua

This is a small but functional library that converts your nix configurations into Lua format.

This library was initially designed for my personal Neovim flake.

Installation

Add nix2lua as input to your flake.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;
}

References

toLua expr

Returns a string containing Lua representation of expr. Strings, integers, floats, boolean, lists and sets are mapped to their Lua equivalents.

Null will be skipped. This is useful when you want to use an optional value. To render nil you should use the LuaNil function.

toLua { foo = "bar"; }
toLua [ 10 "foo" [ "bar" ] ]

LuaNil

Creates a type that will be mapped by the toLua as nil

toLua LuaNil

LuaRaw expr

Creates a type that instructs toLua not to change the passed expression expr.

toLua (mkLuaRaw "require('bar').baz")

mkNamedField name expr

Creates a type that represents a named field in the Lua table. This type cannot exist outside a list or set.

This is useful to create table with some named fields.

toLua [
  "foo"
  (mkNamedField "bar" "baz")
]

License

GNU General Public License v3.0 or later

See COPYING to see the full text.