Thanks to visit codestin.com
Credit goes to github.com

Skip to content

rmst/jix

Repository files navigation

Jix: Declarative Project and System Configs in JS

(alpha version – rough edges)

Use JavaScript to declaratively define your project environments or system/user configurations, with good editor and type-checking support.

Jix is conceptually similar to Nix. In Jix, "effects" are a generalization of Nix' "derivations". Effects can have install and uninstall actions which allows them to influence system state declaratively. Dependencies are tracked automatically.

Jix itself has no out-of-repo dependencies. It does not depend on NPM or Node.js or Nix.

Jix can be used as an ergonomic, lightweight alternative1 to

Nixpkgs are available in Jix via jix.nix.pkgs.<packageName>.<binaryName> (see example).

Documentation: https://rmst.github.io/jix

Getting Started

Install Jix: Run

git clone --recurse-submodules --depth 1 "https://github.com/rmst/jix.git"
make -C jix install
rm -rf jix

Follow the instruction to add . "$HOME/.jix/jix/shell_integration" to your shell rcfile.

Create a jix.js file: in a new or existing dir run jix init, which will create a __jix__.js for you (also .jix/ and jsconfig.json for code completion and type-checking).

// __jix__.js
const hellojix = jix.script`
	echo "Hello from Jix!"
`
export const run = {
	hellojix,
}

You can run hellojix with jix run hellojix, which will output Hello from Jix!. Scripts, like all effects, behave like file paths or strings when composed/interpolated:

// ...
export const run = {
	hellojix2: jix.script`
		${hellojix}
		which ${hellojix}
	`,
}
> jix run hellojix2
Hello from Jix!
/home/bob/.jix/out/f452f0d23f58307e5b758b7fec88b35055dcb8fe9839d8e7ef3f28e33ac7588b

jix install: To persistently add hellojix as a shell command, you can add

// ...
export const install = () => {
	jix.alias({ hellojix })
}

After running jix install, hellojix will be available as a shell command for your user. To remove it you can either comment out the jix.alias line and rerun jix install or you can run jix uninstall.

Reference

FAQ

Why use Jix over Ansible or Nix?

Like Ansible, Jix can modify arbitrary system state, but unlike Ansible it declaratively tracks these effects. E.g. if you comment out a jix.service definition in a __jix__.js and rerun jix install, Jix will remove this service for you. On Ansible you'd have to add a new task to uninstall the service (afaik). Also, if you like, you can only use pure Jix effects that behave like Nix derivations (i.e. only modify the Jix store ~/.jix/). So it's a generalization of Nix that gives you Ansible-like flexibility while remaining fully declarative.

Why JavaScript?

JavaScript was chosen for Jix because it has:

  • Great multiline string and string interpolation support to embed scripts and config files
  • Decent functional programming support (as opposed to Python, which lacks proper anonymous functions)
  • Great tooling (e.g. IDE support for JS is outstanding)
  • Great object/dictionary ergonomics
  • Great, super minimalist interpreter: Fabrice Bellard's Quickjs

Why not Typescript?

Typescript support might be added in the future. Jix already supports typing via JSDoc. The entire Jix standard library is typed.

Development

This repo contains everything to build Jix from source (including the Quickjs Javascript engine). It only requires make and a C compiler, has no other dependencies and takes less than a minute to build.

The quickjs-x git submodule provides a partial Nodejs standard library shim. This allows us to write code that works both with Quickjs and Nodejs.



Footnotes

  1. Within each niche that each of the alternatives occupy Jix's built-in feature set is comparatively very basic. However, Jix should be flexible enough for users to work around missing features.

About

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published