Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
urbas committed Mar 19, 2024
1 parent 61b65b4 commit 4c58c1c
Show file tree
Hide file tree
Showing 32 changed files with 8,113 additions and 15 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name: builder
on: [push, pull_request]
jobs:
build:
name: Build
prepare-dev-env:
runs-on: ubuntu-22.04
steps:
- name: Checkout
Expand Down Expand Up @@ -38,6 +37,10 @@ jobs:
target
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/Cargo.toml', '**/Cargo.lock', '**/.cargo/config.toml', '**/rust-toolchain.toml', '**/flake.nix', '**/flake.lock') }}

rix-build:
needs: [prepare-dev-env]
runs-on: ubuntu-22.04
steps:
- name: Build
run: |
[ -f /home/runner/.nix-profile/etc/profile.d/nix.sh ] || sh <(curl -L https://nixos.org/nix/install) --no-daemon
Expand Down
21 changes: 9 additions & 12 deletions flake.lock

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

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
description = "A reimplementation or nix in Rust.";

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

outputs = { self, nixpkgs, nixjs-rt }:
let
Expand Down
3 changes: 3 additions & 0 deletions nixjs-rt/.envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use flake
nix build --out-link $(direnv_layout_dir)/devEnv .#devEnv
ls -t .direnv | grep -P '^flake-profile-.*-link$' | tail --lines=+5 | xargs --no-run-if-empty -I{} rm "$(direnv_layout_dir)/{}"
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"
}
70 changes: 70 additions & 0 deletions nixjs-rt/CONTRIBUTE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# First-time dev env set up

## Shell

1. Install the nix package manager:
https://nixos.org/manual/nix/stable/installation/installation.html

2. Install direnv: https://direnv.net/

Once you enter this directory in your shell, the NodeJS tooling should be
automatically set up. You can verify this with:

```bash
# This should match the version specified in `rust-toolchain.toml`
npm --version
```

## Editor

You must follow the "Shell" instructions above to make sure the `.direnv`
folder is populated. After that all the needed tooling will be in the `PATH`.

### VSCode

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

# Building & Testing

```bash
# 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 [![builder](https://github.com/urbas/nixjs-rt/actions/workflows/build.yml/badge.svg)](https://github.com/urbas/nixjs-rt/actions/workflows/build.yml)

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.
26 changes: 26 additions & 0 deletions nixjs-rt/flake.lock

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

34 changes: 34 additions & 0 deletions nixjs-rt/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
description = "A library that implements Nix language semantics in JS.";

inputs.nixpkgs.url = "nixpkgs/nixpkgs-unstable";

outputs = { self, nixpkgs }:
let
forAllSystems = f: nixpkgs.lib.genAttrs [ "x86_64-linux" "aarch64-linux" ] (system: f { pkgs = import nixpkgs { inherit system; }; });

devPkgs = pkgs: with pkgs; [
nodejs
parallel
prefetch-npm-deps
];

in
{
packages = forAllSystems ({ pkgs }: with pkgs; {
default = import ./pkg.nix { inherit pkgs self; };

devEnv = buildEnv {
name = "devEnv";
paths = devPkgs pkgs;
};
});

devShells = forAllSystems ({ pkgs }: with pkgs; {
default = stdenv.mkDerivation {
name = "nixjs-rt";
buildInputs = devPkgs pkgs;
};
});
};
}
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 4c58c1c

Please sign in to comment.