Skip to content

Commit

Permalink
inline nixjs-rt
Browse files Browse the repository at this point in the history
  • Loading branch information
urbas committed Mar 22, 2024
1 parent 75513bd commit d9b5083
Show file tree
Hide file tree
Showing 31 changed files with 8,087 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
use flake
ls -t .direnv | grep -P '^flake-profile-.*-link$' | tail --lines=+5 | xargs --no-run-if-empty -I{} rm "$(direnv_layout_dir)/{}"
nix profile wipe-history --profile "$(direnv_layout_dir)/flake-profile" --older-than 14d
16 changes: 15 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,23 @@ jobs:
target
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/Cargo.toml', '**/Cargo.lock', '**/.cargo/config.toml', '**/rust-toolchain.toml', '**/flake.nix', '**/flake.lock') }}

- name: Build
- name: install nix
run: |
[ -f /home/runner/.nix-profile/etc/profile.d/nix.sh ] || sh <(curl -L https://nixos.org/nix/install) --no-daemon
- name: nixjs-rt
run: |
. /home/runner/.nix-profile/etc/profile.d/nix.sh
cd nixjs-rt
eval "$(nix print-dev-env)"
parallel --line-buffer --ctagstring "{}>\033[0m" scripts/{} ::: \
check-nix-pkg.sh \
check-npm-deps-hash.sh \
check-npm.sh
- name: Build
run: |
. /home/runner/.nix-profile/etc/profile.d/nix.sh
eval "$(nix print-dev-env)"
Expand Down
47 changes: 40 additions & 7 deletions CONTRIBUTE.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,49 @@ Your editor should pick up the Rust toolchain as specified in

Install the [direnv vscode extension](https://github.com/direnv/direnv-vscode).

# Building & Testing
# Build, Test, and Iterate

The typical Rust way:
In the first shell you can continuously build `nixjs-rt` (the Nix JavaScript run-time library):

```bash
cargo build
cargo test
cd nixjs-rt
npm ci
npm run build-watch
```

In the second shell continuously test `nixjs-rt`:

```bash
cd nixjs-rt
npm run test-watch
```

In the third shell continuously check and test `rix`:

```bash
cargo-watch -x clippy -x test
```

# Run `rix`

# Examples of how to run rix in debug mode
First build nixjs-rt:

```bash
cd nixjs-rt
npm ci
npm run build-watch
```

Now run `rix` in debug mode:

```bash
cargo run -- --help
cargo run -- eval --expr '1 + 1'
```

## Updating dependencies

Update the `nix` tool, the `nixrt` library, `rustup`, and dependencies used in
integration tests:
Update tools like `rustup`, `npm`, and other dependencies:

```bash
nix flake update
Expand All @@ -65,6 +91,13 @@ Update Rust dependencies:
cargo update
```

Update JavaScript dependencies:

```bash
cd nixjs-rt
npm update
```

# Troubleshooting

## Getting a cargo error after an update
Expand Down
44 changes: 5 additions & 39 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 13 additions & 6 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,40 @@
description = "A reimplementation or nix in Rust.";

inputs.nixpkgs.url = "nixpkgs/nixpkgs-unstable";
inputs.nixjs-rt.url = "github:urbas/nixjs-rt";

outputs = { self, nixpkgs, nixjs-rt }:
outputs = { self, nixpkgs }:
let
supportedSystems = [ "x86_64-linux" "aarch64-linux" ];
forSupportedSystems = f: with nixpkgs.lib; foldl' (resultAttrset: system: recursiveUpdate resultAttrset (f { inherit system; pkgs = import nixpkgs { inherit system; }; })) { } supportedSystems;

in
forSupportedSystems ({ pkgs, system, ... }:
let
buildInputs = with pkgs; [
rix-deps = with pkgs; [
busybox-sandbox-shell
coreutils
cargo-watch
nix
nixjs-rt.packages.${system}.default
nixpkgs-fmt
rustup
];

nixjs-rt-deps = with pkgs; [
nodejs
parallel
prefetch-npm-deps
];

nixjs-rt = import ./nixjs-rt/pkg.nix { inherit pkgs; self = "${self}/nixjs-rt"; };

in
{
packages.${system} = { inherit nixjs-rt pkgs; };
devShells.${system}.default = pkgs.stdenv.mkDerivation {
name = "rix";
inherit buildInputs;
buildInputs = rix-deps ++ nixjs-rt-deps;
shellHook = ''
export RIX_NIXRT_JS_MODULE=${nixjs-rt.packages.${system}.default}/lib/node_modules/nixjs-rt/dist/lib.js
export RIX_NIXRT_JS_MODULE=nixjs-rt/dist/lib.mjs
export RUSTFLAGS=-Dwarnings
'';
};
Expand Down
39 changes: 39 additions & 0 deletions nixjs-rt/.github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: builder
on: [push, pull_request]
jobs:
build:
name: Build
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Nix Setup
run: |
set -x
sudo mkdir /nix
sudo chown $USER /nix
mkdir -p $HOME/.config/nix
echo 'experimental-features = nix-command flakes' > $HOME/.config/nix/nix.conf
- name: Cache Nix DevEnv
uses: actions/cache@v4
env:
cache-name: cache-nix-dev-env
with:
path: |
/nix
/home/runner/.bash_profile
/home/runner/.nix-profile
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/flake.nix', '**/flake.lock') }}

- name: Build
run: |
[ -f /home/runner/.nix-profile/etc/profile.d/nix.sh ] || sh <(curl -L https://nixos.org/nix/install) --no-daemon
. /home/runner/.nix-profile/etc/profile.d/nix.sh
eval "$(nix print-dev-env)"
parallel --line-buffer --ctagstring "{}>\033[0m" scripts/{} ::: \
check-nix-pkg.sh \
check-npm-deps-hash.sh \
check-npm.sh
5 changes: 5 additions & 0 deletions nixjs-rt/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/.direnv
/dist
/coverage
/node_modules
tsconfig.tsbuildinfo
5 changes: 5 additions & 0 deletions nixjs-rt/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/.direnv
/node_modules
/dist
package-lock.json
/.vscode
3 changes: 3 additions & 0 deletions nixjs-rt/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"trailingComma": "all"
}
47 changes: 47 additions & 0 deletions nixjs-rt/CONTRIBUTE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Building & Testing

```bash
# Install dependencies:
npm ci

# Building:
# This will build TypeScript srouces from `src/*.ts` and place the resulting files into the `dist` folder
npm run build
# Same as `build`, but will watch changes in the `src` folder and continuously update the `dist` folder.
npm run build-watch

# Testing:
# This runs all tests once
npm run test
# This runs tests continuously every time sources in the `src` folder change
npm run test-watch

# Formatting:
npm run fmt
```

# Debugging

1. Use the `Debug: JavaScript Debug Terminal` action and VSCode will open a new terminal.
2. Now set a breakpoint somewhere in your code.
3. Run tests with `npm run test` and VSCode will break at the given breakpoint.

## Updating dependencies

Update the version of NodeJS:

```bash
nix flake update
```

Update the version of JavaScript dependencies:

```bash
npm update
```

Finally, update the dependencies hash:

```bash
scripts/update-npm-deps-hash.sh
```
5 changes: 5 additions & 0 deletions nixjs-rt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# nixjs-rt

Nix JavaScript Run-time, an implementation of nix language semantics in TypeScript.

This library is intended for use in transpiling the Nix language to JavaScript.
5 changes: 5 additions & 0 deletions nixjs-rt/jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"preset": "ts-jest",
"testEnvironment": "node",
"modulePathIgnorePatterns": ["dist"]
}
Loading

0 comments on commit d9b5083

Please sign in to comment.