{
description = "Turing Machine Simulator - Multi-platform implementation";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, flake-utils, rust-overlay }:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};
# Rust toolchain with WASM target
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
extensions = [ "rust-src" "clippy" "rustfmt" ];
targets = [ "wasm32-unknown-unknown" ];
};
# Common build inputs for all Rust packages
commonBuildInputs = with pkgs; [
rustToolchain
pkg-config
] ++ lib.optionals stdenv.isDarwin [
darwin.apple_sdk.frameworks.Security
darwin.apple_sdk.frameworks.SystemConfiguration
];
# Build the core library
tur = pkgs.rustPlatform.buildRustPackage {
pname = "tur";
version = "0.1.0";
src = ./.;
cargoLock.lockFile = ./Cargo.lock;
buildInputs = commonBuildInputs;
# Only build the core library
cargoBuildFlags = [ "--package" "tur" ];
cargoTestFlags = [ "--package" "tur" ];
meta = with pkgs.lib; {
description = "Turing Machine Language - Parser, interpreter, and execution engine";
license = with licenses; [ mit asl20 ];
};
};
# Build the CLI platform
tur-cli = pkgs.rustPlatform.buildRustPackage {
pname = "tur-cli";
version = "0.1.0";
src = ./.;
cargoLock.lockFile = ./Cargo.lock;
buildInputs = commonBuildInputs;
cargoBuildFlags = [ "--package" "tur-cli" ];
cargoTestFlags = [ "--package" "tur-cli" ];
meta = with pkgs.lib; {
description = "Command-line interface for Turing machine simulator";
license = with licenses; [ mit asl20 ];
};
};
# Build the TUI platform
tur-tui = pkgs.rustPlatform.buildRustPackage {
pname = "tur-tui";
version = "0.1.0";
src = ./.;
cargoLock.lockFile = ./Cargo.lock;
buildInputs = commonBuildInputs;
cargoBuildFlags = [ "--package" "tur-tui" ];
cargoTestFlags = [ "--package" "tur-tui" ];
meta = with pkgs.lib; {
description = "Terminal user interface for Turing machine simulator";
license = with licenses; [ mit asl20 ];
};
};
# Build the web platform using trunk
tur-web = pkgs.stdenv.mkDerivation {
pname = "tur-web";
version = "0.1.0";
src = ./.;
nativeBuildInputs = [
rustToolchain
pkgs.trunk
pkgs.pkg-config
] ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [
pkgs.darwin.apple_sdk.frameworks.Security
pkgs.darwin.apple_sdk.frameworks.SystemConfiguration
];
buildPhase = ''
cd platforms/web
trunk build --release
'';
installPhase = ''
mkdir -p $out
cp -r platforms/web/dist/* $out/
'';
meta = with pkgs.lib; {
description = "Web interface for Turing machine simulator";
license = with licenses; [ mit asl20 ];
};
};
# Development shell with all tools
devShell = pkgs.mkShell {
buildInputs = commonBuildInputs ++ [
# Rust tools
pkgs.cargo-watch
pkgs.cargo-edit
pkgs.cargo-audit
# Web development tools
pkgs.trunk
pkgs.wasm-pack
pkgs.wasmtime
# Node.js for serving
pkgs.nodejs_20
pkgs.nodePackages.pnpm
# General tools
pkgs.git
pkgs.just
];
# Environment variables
RUST_SRC_PATH = "${rustToolchain}/lib/rustlib/src/rust/library";
# macOS workaround for WASM compilation
RUSTFLAGS = pkgs.lib.optionalString pkgs.stdenv.isDarwin "";
shellHook = ''
echo "🦀 Turing Machine Simulator Development Environment"
echo "Available platforms:"
echo " • CLI: cargo run --package tur-cli"
echo " • TUI: cargo run --package tur-tui"
echo " • Web: cd platforms/web && trunk serve"
echo ""
echo "Build commands:"
echo " • nix build .#cli"
echo " • nix build .#tui"
echo " • nix build .#web"
echo ""
echo "Development:"
echo " • just dev (watch and check)"
echo " • just serve-web (serve web app)"
echo " • cargo test"
echo ""
'';
};
in
{
packages = {
default = tur-cli;
core = tur;
cli = tur-cli;
tui = tur-tui;
web = tur-web;
};
devShells.default = devShell;
# Apps for easy running
apps = {
cli = flake-utils.lib.mkApp {
drv = tur-cli;
exePath = "/bin/tur-cli";
};
tui = flake-utils.lib.mkApp {
drv = tur-tui;
exePath = "/bin/tur-tui";
};
};
# Formatter
formatter = pkgs.nixpkgs-fmt;
});
}