https://github.com/xe/nixexpr
Nix expressions for JavaScript
https://github.com/xe/nixexpr
Last synced: about 1 year ago
JSON representation
Nix expressions for JavaScript
- Host: GitHub
- URL: https://github.com/xe/nixexpr
- Owner: Xe
- License: mit
- Created: 2023-08-11T13:08:56.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-08-11T13:36:37.000Z (almost 3 years ago)
- Last Synced: 2025-04-07T05:50:00.333Z (about 1 year ago)
- Language: JavaScript
- Size: 15.6 KB
- Stars: 19
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nixexpr



[](https://github.com/Xe/nixexpr/actions/workflows/node.js.yml)
JavaScript is great as a programming language, but sometimes it can be
really inconvenient when you are using it as a way to write
configuration data. nixexpr allows you to use [Nix](https://nixos.org)
syntax to make dealing with complicated configuration that much
easier.
To get started, install the package `@xeserv/nixexpr`:
```
npm install --save @xeserv/nixexpr
```
And then import it from your code:
```js
import { nix } from "@xeserv/nixexpr";
```
Then use it like you would any other tagged template:
```js
const highlight = nix`{
pre_tags = [ "em" ];
post_tags = [ "" ];
require_fields_match = false;
fields.body_content.fragment_size = 200;
fields.body_content.number_of_fragments = 1;
}
```
## Why?
Consider the differences between these two snippets of code:
```js
{
highlight: {
pre_tags: [''],
post_tags: [''],
require_field_match: false,
fields: {
body_content: {
fragment_size: 200,
number_of_fragments: 1,
},
},
},
}
```
vs
```nix
highlight = {
pre_tags = [ "em" ];
post_tags = [ "" ];
require_fields_match = false;
fields.body_content.fragment_size = 200;
fields.body_content.number_of_fragments = 1;
};
```
The one on the bottom has a lot less boilerplate and is overall a lot
easier to deal with.
## Disclaimer
If you use this in production and have issues with it, please
reconsider your life decisions. If you still think it's a good idea to
use this library, [get in contact](https://xeiaso.net/contact) to
arrange a consulting meeting to help optimize the library for your
unique needs.