diff options
| -rw-r--r-- | modules/templates/java/README.md | 91 | ||||
| -rw-r--r-- | modules/templates/java/flake.nix | 40 | ||||
| -rw-r--r-- | modules/templates/rustBevy/README.md | 145 | ||||
| -rw-r--r-- | modules/templates/rustBevy/flake.nix | 83 | ||||
| -rw-r--r-- | modules/templates/templates.nix | 13 |
5 files changed, 372 insertions, 0 deletions
diff --git a/modules/templates/java/README.md b/modules/templates/java/README.md new file mode 100644 index 0000000..7cc5735 --- /dev/null +++ b/modules/templates/java/README.md @@ -0,0 +1,91 @@ +# Java Development Environment + +A simple Nix Flake providing a reproducible Java development environment. + +## Included Tools + +* **JDK 21** – Java compiler and runtime +* **Maven** – Dependency management and project build tool +* **Gradle** – Alternative build system +* **JDT Language Server** – Language server used by many editors (Neovim, VS Code, Helix, etc.) + +## Usage + +Enter the development shell: + +```bash +nix develop +``` + +When the shell starts, it will display the installed Java version and create an `out/` directory for compiled classes if it doesn't already exist. + +## Helper Commands + +The shell provides a few convenience aliases for small Java projects. + +### `jbuild` + +Compiles every Java source file under `src/` into the `out/` directory. + +```bash +jbuild +``` + +Equivalent to: + +```bash +find src -name "*.java" | xargs javac -d out +``` + +--- + +### `jrun` + +Builds the project and runs: + +```text +src.Main +``` + +```bash +jrun +``` + +This assumes your application's entry point is `src.Main`. + +--- + +### `jclean` + +Removes compiled output. + +```bash +jclean +``` + +## Project Layout + +This template assumes a simple project structure: + +```text +. +├── flake.nix +├── src/ +│ └── Main.java +└── out/ +``` + +For larger projects, consider using Maven or Gradle instead of the helper aliases. + +## Customization + +This template is intended as a starting point. You can easily modify it to: + +* use a different JDK version +* add testing frameworks (JUnit, TestNG) +* include formatting and linting tools +* add debugging utilities +* add database or web development dependencies + +Because everything is defined in the flake, the development environment remains reproducible across Linux, macOS, and other supported platforms. + diff --git a/modules/templates/java/flake.nix b/modules/templates/java/flake.nix new file mode 100644 index 0000000..d69e2c6 --- /dev/null +++ b/modules/templates/java/flake.nix @@ -0,0 +1,40 @@ +{ + description = "Base dev env for Java"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { + self, + nixpkgs, + flake-utils, + }: + flake-utils.lib.eachDefaultSystem (system: let + pkgs = nixpkgs.legacyPackages.${system}; + in { + devShells.default = pkgs.mkShell { + packages = with pkgs; [ + jdk21 + maven + gradle + jdt-language-server # LSP for editors + ]; + + shellHook = '' + echo "Java $(java -version 2>&1 | head -1)" + + alias jbuild='find src -name "*.java" | xargs javac -d out && echo "Build success"' + alias jrun='jbuild && java -cp out src.Main' + alias jclean='rm -rf out && echo "Cleaned"' + + mkdir -p out + + echo " jbuild — compile all sources" + echo " jrun — compile and run" + echo " jclean — remove compiled output" + ''; + }; + }); +} diff --git a/modules/templates/rustBevy/README.md b/modules/templates/rustBevy/README.md new file mode 100644 index 0000000..33752ea --- /dev/null +++ b/modules/templates/rustBevy/README.md @@ -0,0 +1,145 @@ +# Rust + Bevy Development Environment + +A reproducible Rust development environment for building applications and games with **Bevy**. + +This flake provides a complete toolchain, common native dependencies for Bevy on Linux, and a preconfigured development shell. + +## Features + +* Latest stable Rust toolchain via **Fenix** +* **rust-analyzer** for editor integration +* **Crane** for reproducible package builds +* **Clang + Mold** for significantly faster linking +* Vulkan, Wayland, X11, ALSA, and udev libraries required by most Bevy projects +* Ready to use with `nix develop` + +## Included Software + +### Rust Toolchain + +* Stable Rust +* Cargo +* Rustfmt +* Clippy +* rust-analyzer + +### Build Tools + +* Clang +* Mold linker +* pkg-config + +### Native Libraries + +* Vulkan Loader +* Wayland +* libxkbcommon +* X11 +* Xcursor +* Xi +* Xrandr +* ALSA +* udev + +These libraries cover the requirements for most Bevy applications without additional setup. + +## Usage + +Enter the development environment: + +```bash +nix develop +``` + +Build the project: + +```bash +cargo build +``` + +Run the project: + +```bash +cargo run +``` + +Run with release optimizations: + +```bash +cargo run --release +``` + +## Building with Nix + +Build the project as a Nix package: + +```bash +nix build +``` + +Run the packaged application: + +```bash +nix run +``` + +The flake uses **Crane** to build your crate in a reproducible manner. + +## Linker Configuration + +The development environment uses: + +* **Clang** as the linker driver +* **Mold** as the linker + +This is configured automatically through: + +```text +CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=clang +RUSTFLAGS="-C link-arg=-fuse-ld=mold" +``` + +Using Mold can dramatically reduce link times, which is especially useful during game development. + +## Editor Support + +The included `rust-analyzer` integrates automatically with editors such as: + +* Neovim +* Helix +* VS Code +* Zed +* Emacs + +No additional Rust installation is required. + +## Project Layout + +This template assumes a standard Cargo project: + +```text +. +├── Cargo.toml +├── Cargo.lock +├── flake.nix +└── src/ + └── main.rs +``` + +## Customization + +Depending on your project, you may wish to extend the development shell with additional tools such as: + +* `trunk` for WebAssembly targets +* `lldb` or `gdb` for debugging +* `cargo-nextest` +* `cargo-watch` +* `cargo-deny` +* `cargo-flamegraph` + +Additional system libraries can also be added to `buildInputs` if your project depends on them. + +## Notes + +This template is primarily intended for Linux Bevy development. It includes the native dependencies commonly required for windowing, graphics, input, and audio. Basic Darwin support is included where applicable, but additional configuration may be necessary for macOS-specific projects. + diff --git a/modules/templates/rustBevy/flake.nix b/modules/templates/rustBevy/flake.nix new file mode 100644 index 0000000..1d7d862 --- /dev/null +++ b/modules/templates/rustBevy/flake.nix @@ -0,0 +1,83 @@ +{ + description = "Rust dev env flake for Bevy development"; + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + crane.url = "github:ipetkov/crane"; + fenix = { + url = "github:nix-community/fenix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + flake-utils.url = "github:numtide/flake-utils"; + }; + outputs = { + self, + nixpkgs, + crane, + fenix, + flake-utils, + ... + }: + flake-utils.lib.eachDefaultSystem (system: let + pkgs = nixpkgs.legacyPackages.${system}; + + rs-toolchain = with fenix.packages.${system}; + combine [ + default.toolchain + rust-analyzer + ]; + + craneLib = (crane.mkLib pkgs).overrideToolchain rs-toolchain; + + my-crate = craneLib.buildPackage { + src = craneLib.cleanCargoSource (craneLib.path ./.); + strictDeps = true; + buildInputs = with pkgs; + [ + udev + alsa-lib + vulkan-loader + libX11 + libXcursor + libXi + libXrandr + libxkbcommon + wayland + ] + ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [ + pkgs.libiconv + ]; + nativeBuildInputs = with pkgs; [ + pkg-config + mold + clang + ]; + CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER = "clang"; + RUSTFLAGS = "-C link-arg=-fuse-ld=mold"; + }; + in { + packages.default = my-crate; + apps.default = flake-utils.lib.mkApp { + drv = my-crate; + }; + devShells.default = pkgs.mkShell rec { + buildInputs = with pkgs; [ + rs-toolchain + pkg-config + udev + alsa-lib + vulkan-loader + libX11 + libXcursor + libXi + libXrandr + libxkbcommon + wayland + mold + clang + ]; + LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath buildInputs; + CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER = "clang"; + RUSTFLAGS = "-C link-arg=-fuse-ld=mold"; + }; + }); +} diff --git a/modules/templates/templates.nix b/modules/templates/templates.nix new file mode 100644 index 0000000..db99497 --- /dev/null +++ b/modules/templates/templates.nix @@ -0,0 +1,13 @@ +{...}: { + flake.templates = { + java = { + path = ./templates/java; + description = "Base Java development environment"; + }; + + rust = { + path = ./templates/rust; + description = "Base Rust development environment"; + }; + }; +} |
