From a1d8493242d002a7e31e25c3e52f9271f664583d Mon Sep 17 00:00:00 2001 From: stubbfel Date: Sat, 29 Jun 2024 18:11:25 +0000 Subject: [PATCH] add bare metal runtime --- .devcontainer/devcontainer.json | 7 ++++- .gitignore | 3 +- flake.nix | 6 ++-- .../example/services/python/default.nix | 2 ++ playground/example/services/rust/default.nix | 2 ++ .../runtime/engines/baremetal/default.nix | 28 +++++++++++++++++++ 6 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 playground/runtime/engines/baremetal/default.nix diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index a0a48ef..47ad41c 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,7 +1,12 @@ { "name": "Alpine", "image": "mcr.microsoft.com/devcontainers/base:alpine", - "postCreateCommand": "sudo apk add nix nix-dev nix-doc nix-manual nix-bash-completion && sudo chown -R vscode:vscode /nix && echo 'experimental-features = nix-command flakes' | sudo tee -a /etc/nix/nix.conf", + "features": { + "ghcr.io/devcontainers/features/nix:1": { + "extraNixConfig": "experimental-features = nix-command flakes", + "packages": "nixpkgs-fmt" + } + }, "runArgs": [ "--userns=keep-id" ], diff --git a/.gitignore b/.gitignore index e2f5dd2..ece38b6 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -result \ No newline at end of file +result +nohup.out \ No newline at end of file diff --git a/flake.nix b/flake.nix index c27109b..166c8ce 100644 --- a/flake.nix +++ b/flake.nix @@ -19,15 +19,15 @@ { packages = rec { playground = space.playground.package; - default = playground; + default = pkgs.callPackage ./playground/runtime/engines/baremetal { services = [ space.playground.package ]; }; }; apps = rec { playground = flake-utils.lib.mkApp { drv = space.playground.package; exePath = ""; }; - default = playground; + default = flake-utils.lib.mkApp { drv = self.packages.${system}.default; }; }; devShells.default = pkgs.mkShell { - packages = [ pkgs.nixpkgs-fmt pkgs.nixpkgs-lint ]; + packages = [ pkgs.nixpkgs-fmt ]; }; }); } diff --git a/playground/example/services/python/default.nix b/playground/example/services/python/default.nix index 92eace8..af843f8 100644 --- a/playground/example/services/python/default.nix +++ b/playground/example/services/python/default.nix @@ -1,5 +1,7 @@ { config ? import ../../config { } }: config.nixpkgs.writeScript "python-example-web-server" '' + #! /usr/bin/env sh + ${config.nixpkgs.python3}/bin/python -m http.server ${config.playground.port} '' diff --git a/playground/example/services/rust/default.nix b/playground/example/services/rust/default.nix index ddb38c8..a4d0414 100644 --- a/playground/example/services/rust/default.nix +++ b/playground/example/services/rust/default.nix @@ -1,6 +1,8 @@ { config ? import ../../config { } }: config.nixpkgs.writeScript "rust-example-web-server" '' + #! /usr/bin/env sh + ${config.nixpkgs.simple-http-server}/bin/simple-http-server --port ${config.playground.port} '' diff --git a/playground/runtime/engines/baremetal/default.nix b/playground/runtime/engines/baremetal/default.nix new file mode 100644 index 0000000..1ce6d4d --- /dev/null +++ b/playground/runtime/engines/baremetal/default.nix @@ -0,0 +1,28 @@ +{ pkgs, lib, services ? [ ] }: + +let + + backgroundServices = lib.forEach services (s: " exec nohup 2>&1 ${s} &"); + launchBackgroundServices = lib.strings.concatLines backgroundServices; + +in + +pkgs.writeScriptBin "run" '' + #! /usr/bin/env sh + + echo start services + + ${launchBackgroundServices} + + sleep 3 + + read -r -p "to stop press any key:" + + echo stop services + + for job in `jobs -p` + do + pkill -P $job + kill $job + done +''