testing with jails

This commit is contained in:
Michael Zhang 2021-08-28 06:37:52 -05:00
parent cf562b6ec1
commit 053973dd41
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
7 changed files with 95 additions and 37 deletions

28
' Normal file
View file

@ -0,0 +1,28 @@
{ writeTextFile, nsjail }:
let
inner = writeTextFile {
name = "ocamlStudentModuleInner";
executable = true;
text = ''
INTERFACE_FILE=$1
STUDENT_FILE=$2
DRIVER_FILE=$3
ocamlc -o student.cmi $INTERFACE_FILE
ocamlc -o student.cmo $STUDENT_FILE
ocaml student.cmo $DRIVER_FILE
'';
};
in
writeTextFile {
name = "ocamlStudentModule";
executable = true;
text = ''
JAIL=$(mktemp -d)
${nsjail}/bin/nsjail \
-Mo \ # launch a single process using clone/execve
--chroot $JAIL
${inner}
'';
}

View file

@ -3,5 +3,5 @@ root = true
[*]
indent_style = space
[*.{svelte,ts,json,rst}]
[*.{md,svelte,ts,json,rst}]
indent_size = 2

View file

@ -1,38 +1,22 @@
# create-svelte
education project
===
Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte);
The education project is just my personal ideal education system. Here are its
goals:
## Creating a project
- **Learning is measured through mastery, which is measured through tests.**
Mastery is similar to what Anki uses and is trained with spaced repetition.
Notably, doing well on a test once doesn't indicate complete mastery and
failing a test doesn't indicate complete unmastery. Skipping a question
lowers mastery a bit less than getting it wrong.
If you're seeing this, you've probably already done this step. Congrats!
- **Learning by doing.** Many different types of activity formats that should
all contribute to mastery of the given concepts. In addition, mastery of
certain concepts should also backpropagate to the concepts it depends on. The
planned list of activity types are:
* Classic multiple-choice problems
* Short-answer problems (for math)
* Write a short program (+ linting)
* Write a bigger project
```bash
# create a new project in the current directory
npm init svelte@next
# create a new project in my-app
npm init svelte@next my-app
```
> Note: the `@next` is temporary
## Developing
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
```bash
npm run dev
# or start the server and open the app in a new browser tab
npm run dev -- --open
```
## Building
Before creating a production version of your app, install an [adapter](https://kit.svelte.dev/docs#adapters) for your target environment. Then:
```bash
npm run build
```
> You can preview the built app with `npm run preview`, regardless of whether you installed an adapter. This should _not_ be used to serve your app in production.

View file

@ -4,9 +4,6 @@ import * as yaml from "js-yaml";
import { init } from "./db";
class Page {
}
async function main() {
// TODO: configure this thru cmdline or something later
let materials_dir = "../material";

1
jails/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/result

14
jails/default.nix Normal file
View file

@ -0,0 +1,14 @@
{ pkgs ? import <nixpkgs> {} }:
let
ocamlStudentModule = pkgs.callPackage ./ocamlStudentModule.nix {};
in
pkgs.stdenv.mkDerivation {
name = "edujails";
src = ./.;
installPhase = ''
mkdir -p $out/bin
cp ${ocamlStudentModule} $out/bin/ocamlStudentModule
'';
}

View file

@ -0,0 +1,34 @@
{ writeTextFile, nsjail }:
let
inner = writeTextFile {
name = "ocamlStudentModuleInner";
executable = true;
text = ''
#!/bin/sh
INTERFACE_FILE=$1
STUDENT_FILE=$2
DRIVER_FILE=$3
ocamlc -o student.cmi $INTERFACE_FILE
ocamlc -o student.cmo $STUDENT_FILE
ocaml student.cmo $DRIVER_FILE
'';
};
in
writeTextFile {
name = "ocamlStudentModule";
executable = true;
text = ''
JAIL=$(mktemp -d)
mkdir -p $JAIL/bin
cp ${inner} $JAIL/bin/ocamlStudentModule
${nsjail}/bin/nsjail \
-Mo \
--chroot $JAIL \
-R /bin/sh \
-R /bin/ls \
/bin/ls
# /bin/ocamlStudentModule
'';
}