Updated project details
This commit is contained in:
@@ -0,0 +1,68 @@
|
|||||||
|
---
|
||||||
|
sessionId: session-260819-004513-s2vk
|
||||||
|
---
|
||||||
|
|
||||||
|
# Requirements
|
||||||
|
|
||||||
|
### Overview & Goals
|
||||||
|
Tailor `flake.nix`, development environments, and packaging configurations specifically to the `coldIron` project (a Rust + `iced` desktop GUI application). Prune obsolete template boilerplate and microcontroller/embedded targets, structure the package derivation to conform to standard `nixpkgs` packaging practices (with runtime library wrapping for `winit`/`wayland`/`x11`/`wgpu`), and retain Flatpak build capabilities with a project-tailored manifest.
|
||||||
|
|
||||||
|
### Scope
|
||||||
|
- **In Scope**:
|
||||||
|
- Pruning generic template outputs (`templates.default`, `devHelper` binary, embedded `rustup target add` hooks) from `flake.nix`.
|
||||||
|
- Creating a clean, idiomatic `nixpkgs`-compatible package derivation (`buildRustPackage` with `makeBinaryWrapper` and `LD_LIBRARY_PATH` wrapping) so `coldIron` can be built with `nix build` and easily contributed/published to `nixpkgs`.
|
||||||
|
- Retaining Flatpak build capabilities by maintaining `flatpak` and `flatpak-builder` in the development environment and updating `flatpak/app.flatpak.json` to target `coldIron`.
|
||||||
|
- Aligning `project.toml`, `shell.nix`, `default.nix`, and `README.md` with the `coldIron` project metadata.
|
||||||
|
- **Out of Scope**:
|
||||||
|
- Modifying the application's UI logic or Rust code in `src/main.rs`.
|
||||||
|
|
||||||
|
# Technical Design
|
||||||
|
|
||||||
|
### Current Implementation
|
||||||
|
- `flake.nix` contains leftover template outputs (`templates.default`), a helper script (`devHelper` / `dev-helper`), and shell hooks attempting to install embedded targets (ARM Cortex-M, RISC-V, ESP32).
|
||||||
|
- `packages.default` builds a dummy `sample-rust-app` without wrapping required Linux GUI runtime libraries (`wayland`, `libxkbcommon`, `libGL`, `vulkan-loader`, `xorg` libraries).
|
||||||
|
- `flatpak/app.flatpak.json` references placeholder IDs (`org.example.rustdevshell`) and binary name `rustdevshell-app` instead of `ColdIron`.
|
||||||
|
- `project.toml` and `README.md` describe a generic reusable template rather than the `coldIron` application.
|
||||||
|
|
||||||
|
### Key Decisions
|
||||||
|
- **Nixpkgs Standard Package (`package.nix` / `packages.default`)**:
|
||||||
|
- Define the package derivation using `pkgs.rustPlatform.buildRustPackage` with `nativeBuildInputs = [ pkgs.pkg-config pkgs.makeBinaryWrapper ]` and `buildInputs = runtimeLibs`.
|
||||||
|
- Wrap the installed binary (`$out/bin/ColdIron`) with `LD_LIBRARY_PATH` prefixing `runtimeLibs` so that `nix run` or `nix build` produces a standalone binary that starts up without Wayland/X11 dynamic library errors.
|
||||||
|
- Structure `package.nix` (or `default.nix`) as a standard `callPackage` function suitable for inclusion in `nixpkgs` (e.g. `pkgs/by-name/co/coldiron/package.nix`).
|
||||||
|
- **Streamlined devShell**:
|
||||||
|
- Retain essential tools for Rust desktop GUI development: `rustToolchain` (fenix), `rust-analyzer`, `pkg-config`, `cargo-watch`, `cargo-edit`, `flatpak`, `flatpak-builder`, `alejandra`, and `runtimeLibs`.
|
||||||
|
- Remove embedded microcontroller hooks (`rustup target add ...`) and embedded tools from the shell hook and tool summary.
|
||||||
|
- **Flatpak Retention & Modernization**:
|
||||||
|
- Retain `Makefile` target `flatpak-build` and `flatpak-builder` in the devShell.
|
||||||
|
- Update `flatpak/app.flatpak.json` to specify `app-id: "io.github.gooba42.coldiron"`, command `ColdIron`, and clean module definitions.
|
||||||
|
|
||||||
|
### File Structure Changes
|
||||||
|
- `flake.nix`: Prune template/embedded artifacts; configure `packages.default`, `apps.default`, and tailored `devShells.default`.
|
||||||
|
- `package.nix` (or `default.nix`): Standard `nixpkgs` packaging expression using `callPackage` conventions.
|
||||||
|
- `flatpak/app.flatpak.json`: Tailor manifest metadata and build command for `coldIron`.
|
||||||
|
- `project.toml` & `README.md`: Update metadata and documentation to reflect the `coldIron` project.
|
||||||
|
|
||||||
|
# Delivery Steps
|
||||||
|
|
||||||
|
### ✓ Step 1: Create standard nixpkgs-compatible package derivation in package.nix and default.nix
|
||||||
|
- Create `package.nix` as a `callPackage`-compatible function using `rustPlatform.buildRustPackage`.
|
||||||
|
- Add `pkg-config` and `makeBinaryWrapper` to `nativeBuildInputs`, and include `runtimeLibs` in `buildInputs`.
|
||||||
|
- Add `postInstall` hook using `wrapProgram` to prefix `LD_LIBRARY_PATH` with `runtimeLibs` so the GUI application can dynamically load Wayland/X11 libraries.
|
||||||
|
- Update `default.nix` to call `package.nix`.
|
||||||
|
|
||||||
|
### ✓ Step 2: Update flake.nix packaging, applications, devShell, and prune template/embedded artifacts
|
||||||
|
- Remove `templates` output and `devHelper` / `dev-helper`.
|
||||||
|
- Configure `packages.default` (and `packages.coldiron`) to use `package.nix`.
|
||||||
|
- Configure `apps.default` to run `$out/bin/ColdIron`.
|
||||||
|
- Streamline `devShells.default` by removing embedded microcontroller targets (`rustup target add`) and updating the shell banner for `coldIron`.
|
||||||
|
- Ensure Flatpak tools (`flatpak`, `flatpak-builder`) and formatting tools are present.
|
||||||
|
|
||||||
|
### ✓ Step 3: Update Flatpak manifest, project metadata, and documentation
|
||||||
|
- Update `flatpak/app.flatpak.json` with app-id `io.github.gooba42.coldiron`, command `ColdIron`, graphics/wayland/x11 permissions, and build commands.
|
||||||
|
- Update `project.toml` with `coldiron` project name and description.
|
||||||
|
- Update `README.md` to describe the `coldIron` Iced application, dev workflow, Nix build/run, and Flatpak build.
|
||||||
|
|
||||||
|
### ✓ Step 4: Verify package build, dev shell, tests, and formatting
|
||||||
|
- Verify `nix build` builds the wrapped `ColdIron` package.
|
||||||
|
- Run `cargo check` and `cargo test` to verify codebase health.
|
||||||
|
- Run `alejandra .` to ensure Nix files are formatted cleanly.
|
||||||
Generated
+3964
File diff suppressed because it is too large
Load Diff
@@ -5,3 +5,4 @@ edition = "2021"
|
|||||||
description = "Learning Rust and Iced"
|
description = "Learning Rust and Iced"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
iced = "0.14.0"
|
||||||
@@ -1,163 +1,95 @@
|
|||||||
# Rust Nix Flake Template
|
# ColdIron
|
||||||
|
|
||||||
This template provides a reproducible Rust development environment using Nix flakes and the fenix toolchain.
|
ColdIron is a desktop GUI application built with [Rust](https://www.rust-lang.org/) and the [Iced](https://iced.rs/) GUI framework.
|
||||||
|
|
||||||
## Quick Start
|
## Quick Start
|
||||||
|
|
||||||
|
### Nix Flakes (Recommended)
|
||||||
|
|
||||||
|
Enter the reproducible development shell with all Rust tools and Linux GUI runtime dependencies (`wayland`, `libxkbcommon`, `libGL`, `vulkan-loader`, `xorg` libraries):
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
nix develop
|
nix develop
|
||||||
# or with direnv:
|
# or with direnv:
|
||||||
direnv allow
|
direnv allow
|
||||||
```
|
```
|
||||||
|
|
||||||
### Automatic Environment Setup
|
Then run the application:
|
||||||
|
|
||||||
When you enter the devShell (via `direnv allow` or `nix develop`), the following happens automatically:
|
|
||||||
|
|
||||||
✓ **Git Repository**: Initializes `.git` if not present
|
|
||||||
✓ **Rust Targets**: Automatically adds common embedded Rust targets (ARM Cortex-M, RISC-V)
|
|
||||||
✓ **Cargo Paths**: Sets up `$HOME/.cargo/bin` in PATH for cargo-installed binaries
|
|
||||||
✓ **Welcome Banner**: Displays available tools and quick commands
|
|
||||||
|
|
||||||
No manual setup needed! Just start coding.
|
|
||||||
|
|
||||||
## Quickstart
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
nix flake init -t path:../flakes#rust
|
cargo run
|
||||||
nix develop
|
|
||||||
cargo build
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Embedded Rust Support
|
### Running Tests & Quality Checks
|
||||||
|
|
||||||
The devShell automatically installs common embedded Rust targets via `rustup`:
|
```sh
|
||||||
|
# Run unit and integration tests
|
||||||
| Target | Platform | Use Case |
|
|
||||||
|--------|----------|----------|
|
|
||||||
| `thumbv6m-none-eabi` | ARM Cortex-M0/M0+ | RP2040 (Pico) |
|
|
||||||
| `thumbv7em-none-eabihf` | ARM Cortex-M4F/M7F | STM32, nRF52840 |
|
|
||||||
| `riscv32imc-unknown-none-elf` | RISC-V 32-bit | ESP32-C3 (basic) |
|
|
||||||
| `riscv32imac-unknown-none-elf` | RISC-V 32-bit (atomic) | ESP32-C3 (advanced) |
|
|
||||||
|
|
||||||
**Note:** ESP32 Xtensa targets require espup or custom toolchains (see [esp-rs](https://github.com/esp-rs)).
|
|
||||||
|
|
||||||
## Flatpak Packaging
|
|
||||||
|
|
||||||
This template supports building Flatpak packages for your Rust application.
|
|
||||||
|
|
||||||
### Build Flatpak Package
|
|
||||||
|
|
||||||
1. Ensure you have `flatpak-builder` installed.
|
|
||||||
2. Run:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
make flatpak-build
|
|
||||||
```
|
|
||||||
|
|
||||||
This will use the manifest at `flatpak/app.flatpak.json` to build a Flatpak bundle in the `build-flatpak/` directory.
|
|
||||||
|
|
||||||
### Customize Manifest
|
|
||||||
|
|
||||||
Edit `flatpak/app.flatpak.json` to update app ID, runtime, build commands, or sources as needed for your project.
|
|
||||||
|
|
||||||
### Install/Run Flatpak Locally
|
|
||||||
|
|
||||||
You can install and run the built Flatpak locally:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
flatpak install --user build-flatpak/org.example.rustdevshell.flatpak
|
|
||||||
flatpak run org.example.rustdevshell
|
|
||||||
```
|
|
||||||
|
|
||||||
## Included Tools
|
|
||||||
|
|
||||||
| Tool | Purpose |
|
|
||||||
|------|---------|
|
|
||||||
| **cargo** | Rust package manager and build system |
|
|
||||||
| **rustc** | Rust compiler |
|
|
||||||
| **clippy** | Rust linter for catching common mistakes |
|
|
||||||
| **rustfmt** | Rust code formatter |
|
|
||||||
| **rust-analyzer** | Language server for IDE integration |
|
|
||||||
| **rust-src** | Rust source code (for tools like rust-analyzer) |
|
|
||||||
| **probe-rs** | Embedded debugger/flasher for ARM targets |
|
|
||||||
| **espflash** | Flashing tool for ESP32 boards |
|
|
||||||
| **openocd** | JTAG/SWD debugger for ARM and other targets |
|
|
||||||
| **minicom** | Serial terminal for device output |
|
|
||||||
| **elf2uf2-rs** | Convert ELF to UF2 format (RP2040) |
|
|
||||||
| **picotool** | Pico-specific firmware operations |
|
|
||||||
| **avrdude** | AVR microcontroller programmer |
|
|
||||||
| **ravedude** | Rapid AVR development utility |
|
|
||||||
|
|
||||||
## Testing & Development Features
|
|
||||||
|
|
||||||
Build and testing tools:
|
|
||||||
|
|
||||||
- **cargo test** - Run unit and integration tests
|
|
||||||
- **cargo clippy** - Lint code for common issues
|
|
||||||
- **cargo fmt** - Format code consistently with rustfmt
|
|
||||||
|
|
||||||
**Example usage:**
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Run tests
|
|
||||||
cargo test
|
cargo test
|
||||||
|
|
||||||
# Check code with clippy
|
# Run linter
|
||||||
cargo clippy
|
cargo clippy
|
||||||
|
|
||||||
# Format code
|
# Format code
|
||||||
cargo fmt
|
cargo fmt
|
||||||
|
|
||||||
# Build for embedded target
|
|
||||||
cargo build --target thumbv7em-none-eabihf --release
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Project Layout
|
## Nix Packaging & nixpkgs Compatibility
|
||||||
|
|
||||||
```
|
`coldIron` provides an idiomatic, `nixpkgs`-compatible package expression in `package.nix` and `flake.nix`.
|
||||||
Cargo.toml
|
|
||||||
Cargo.lock
|
### Build with Nix
|
||||||
src/
|
|
||||||
└── main.rs (or lib.rs)
|
```sh
|
||||||
Makefile
|
nix build
|
||||||
.envrc
|
./result/bin/ColdIron
|
||||||
flake.nix
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Legacy Usage
|
Or run directly via flake:
|
||||||
|
|
||||||
If you do not use flakes, run:
|
```sh
|
||||||
|
nix run
|
||||||
|
```
|
||||||
|
|
||||||
|
### Contributing to nixpkgs
|
||||||
|
|
||||||
|
The `package.nix` derivation is designed for direct integration into `nixpkgs` (e.g. under `pkgs/by-name/co/coldiron/package.nix`). It uses `rustPlatform.buildRustPackage`, `makeBinaryWrapper`, and wraps the executable with runtime graphics and windowing libraries (`LD_LIBRARY_PATH`).
|
||||||
|
|
||||||
|
## Flatpak Packaging
|
||||||
|
|
||||||
|
ColdIron includes Flatpak packaging configuration for containerized desktop distribution.
|
||||||
|
|
||||||
|
### Build Flatpak Package
|
||||||
|
|
||||||
|
1. Enter the dev shell (`nix develop`) which includes `flatpak` and `flatpak-builder`.
|
||||||
|
2. Run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make flatpak-build
|
||||||
|
```
|
||||||
|
|
||||||
|
This uses the manifest in `flatpak/app.flatpak.json` (Application ID: `io.github.gooba42.coldiron`) to build the application into `build-flatpak/`.
|
||||||
|
|
||||||
|
## Legacy Nix Shell
|
||||||
|
|
||||||
|
If you are not using Nix flakes, you can enter the development environment using:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
nix-shell
|
nix-shell
|
||||||
```
|
```
|
||||||
|
|
||||||
## Project Metadata
|
## Project Structure
|
||||||
|
|
||||||
See project.toml for example metadata.
|
```
|
||||||
|
ColdIron/
|
||||||
## Helper Tools
|
├── Cargo.toml # Rust package manifest
|
||||||
|
├── Cargo.lock # Exact dependency lockfile
|
||||||
- **`nix run .#dev-helper`** - Display tool versions and availability
|
├── flake.nix # Nix flake for devShell, packages, and apps
|
||||||
- **`cargo build`** - Build the project
|
├── package.nix # Nixpkgs-compatible buildRustPackage derivation
|
||||||
- **`cargo check`** - Quick syntax check without building
|
├── default.nix # nix-build entrypoint calling package.nix
|
||||||
- **`cargo doc --open`** - Generate and view documentation
|
├── shell.nix # Legacy nix-shell configuration
|
||||||
|
├── flatpak/
|
||||||
## Packaging for nixpkgs
|
│ └── app.flatpak.json # Flatpak application manifest
|
||||||
|
├── src/
|
||||||
This template is structured for easy packaging in nixpkgs:
|
│ └── main.rs # Iced application entrypoint and UI
|
||||||
|
└── tests/ # Integration tests
|
||||||
- All sources in `src/`
|
```
|
||||||
- `flake.nix` provides a devShell and template
|
|
||||||
- Add a `default.nix` or package expression as needed for nixpkgs
|
|
||||||
|
|
||||||
See [nixpkgs Rust packaging docs](https://nixos.org/manual/nixpkgs/stable/#rust) for more details.
|
|
||||||
|
|
||||||
## Customization
|
|
||||||
|
|
||||||
Edit `flake.nix` to:
|
|
||||||
|
|
||||||
- Add additional Rust targets via `rustup target add [target]`
|
|
||||||
- Include additional cargo plugins
|
|
||||||
- Add board-specific tools (e.g., stm32cube, nrfjprog)
|
|
||||||
|
|||||||
+2
-29
@@ -1,29 +1,2 @@
|
|||||||
{ pkgs }:
|
{pkgs ? import <nixpkgs> {}}:
|
||||||
let
|
pkgs.callPackage ./package.nix {}
|
||||||
lib = pkgs.lib;
|
|
||||||
templateName = builtins.baseNameOf (toString ./.);
|
|
||||||
in
|
|
||||||
{
|
|
||||||
${templateName} = pkgs.stdenvNoCC.mkDerivation {
|
|
||||||
pname = templateName;
|
|
||||||
version = "0.1.0";
|
|
||||||
src = ./.;
|
|
||||||
dontBuild = true;
|
|
||||||
installPhase = ''
|
|
||||||
mkdir -p $out/share/${templateName}
|
|
||||||
if [ -d src ]; then
|
|
||||||
cp -r src $out/share/${templateName}/
|
|
||||||
fi
|
|
||||||
for f in README.md project.toml flake.nix default.nix shell.nix Makefile .editorconfig .gitignore; do
|
|
||||||
if [ -f "$f" ]; then
|
|
||||||
cp "$f" $out/share/${templateName}/
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
'';
|
|
||||||
meta = with lib; {
|
|
||||||
description = "Template project: ${templateName}";
|
|
||||||
license = licenses.unfreeRedistributable;
|
|
||||||
platforms = platforms.all;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
description = "A Nix-flake-based Rust development environment";
|
description = "ColdIron - Learning Rust and Iced";
|
||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
@@ -9,19 +9,16 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs =
|
outputs = inputs @ {self, ...}: let
|
||||||
inputs@{ self, ... }:
|
supportedSystems = [
|
||||||
let
|
"x86_64-linux"
|
||||||
supportedSystems = [
|
"aarch64-linux"
|
||||||
"x86_64-linux"
|
"x86_64-darwin"
|
||||||
"aarch64-linux"
|
"aarch64-darwin"
|
||||||
"x86_64-darwin"
|
];
|
||||||
"aarch64-darwin"
|
forEachSupportedSystem = f:
|
||||||
];
|
inputs.nixpkgs.lib.genAttrs supportedSystems (
|
||||||
forEachSupportedSystem =
|
system:
|
||||||
f:
|
|
||||||
inputs.nixpkgs.lib.genAttrs supportedSystems (
|
|
||||||
system:
|
|
||||||
f {
|
f {
|
||||||
pkgs = import inputs.nixpkgs {
|
pkgs = import inputs.nixpkgs {
|
||||||
inherit system;
|
inherit system;
|
||||||
@@ -30,36 +27,58 @@
|
|||||||
];
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
);
|
||||||
|
in {
|
||||||
|
overlays.default = _final: prev: {
|
||||||
|
rustToolchain = with inputs.fenix.packages.${prev.stdenv.hostPlatform.system};
|
||||||
|
combine (
|
||||||
|
with stable; [
|
||||||
|
clippy
|
||||||
|
rustc
|
||||||
|
cargo
|
||||||
|
rustfmt
|
||||||
|
rust-src
|
||||||
|
]
|
||||||
);
|
);
|
||||||
in
|
coldiron = prev.callPackage ./package.nix {};
|
||||||
{
|
};
|
||||||
templates = {
|
|
||||||
|
packages = forEachSupportedSystem (
|
||||||
|
{pkgs}: {
|
||||||
|
default = pkgs.callPackage ./package.nix {};
|
||||||
|
coldiron = pkgs.callPackage ./package.nix {};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
apps = forEachSupportedSystem (
|
||||||
|
{pkgs}: {
|
||||||
default = {
|
default = {
|
||||||
path = ./.;
|
type = "app";
|
||||||
description = "Rust dev environment using fenix; includes a skeletal Cargo project and packaged helper app";
|
program = pkgs.lib.getExe self.packages.${pkgs.stdenv.hostPlatform.system}.default;
|
||||||
};
|
};
|
||||||
};
|
coldiron = {
|
||||||
|
type = "app";
|
||||||
|
program = pkgs.lib.getExe self.packages.${pkgs.stdenv.hostPlatform.system}.coldiron;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
overlays.default = _final: prev: {
|
devShells = forEachSupportedSystem (
|
||||||
rustToolchain =
|
{pkgs}: let
|
||||||
with inputs.fenix.packages.${prev.stdenv.hostPlatform.system};
|
runtimeLibs = with pkgs; [
|
||||||
combine (
|
wayland
|
||||||
with stable;
|
libxkbcommon
|
||||||
|
libGL
|
||||||
|
vulkan-loader
|
||||||
|
libx11
|
||||||
|
libxcursor
|
||||||
|
libxrandr
|
||||||
|
libxi
|
||||||
|
];
|
||||||
|
in {
|
||||||
|
default = pkgs.mkShell {
|
||||||
|
packages = with pkgs;
|
||||||
[
|
[
|
||||||
clippy
|
|
||||||
rustc
|
|
||||||
cargo
|
|
||||||
rustfmt
|
|
||||||
rust-src
|
|
||||||
]
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
devShells = forEachSupportedSystem (
|
|
||||||
{ pkgs }:
|
|
||||||
{
|
|
||||||
default = pkgs.mkShell {
|
|
||||||
packages = with pkgs; [
|
|
||||||
rustToolchain
|
rustToolchain
|
||||||
git
|
git
|
||||||
gnumake
|
gnumake
|
||||||
@@ -73,88 +92,34 @@
|
|||||||
cargo-deny
|
cargo-deny
|
||||||
cargo-edit
|
cargo-edit
|
||||||
cargo-watch
|
cargo-watch
|
||||||
cargo-generate
|
|
||||||
rust-analyzer
|
rust-analyzer
|
||||||
rustup
|
|
||||||
# Embedded Rust tooling
|
|
||||||
probe-rs-tools
|
|
||||||
espflash
|
|
||||||
openocd
|
|
||||||
minicom
|
|
||||||
# RP2040 UF2 workflows
|
|
||||||
elf2uf2-rs
|
|
||||||
picotool
|
|
||||||
avrdude
|
|
||||||
pkgsCross.avr.buildPackages.libc
|
|
||||||
pkgsCross.avr.buildPackages.gcc
|
|
||||||
ravedude
|
|
||||||
pre-commit
|
pre-commit
|
||||||
];
|
]
|
||||||
|
++ runtimeLibs;
|
||||||
|
|
||||||
env = {
|
env = {
|
||||||
# Required by rust-analyzer
|
# Required by rust-analyzer
|
||||||
RUST_SRC_PATH = "${pkgs.rustToolchain}/lib/rustlib/src/rust/library";
|
RUST_SRC_PATH = "${pkgs.rustToolchain}/lib/rustlib/src/rust/library";
|
||||||
};
|
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath runtimeLibs;
|
||||||
|
|
||||||
shellHook = ''
|
|
||||||
# Initialize git repository if not already present
|
|
||||||
if [ ! -d .git ]; then
|
|
||||||
git init
|
|
||||||
echo "✓ Initialized git repository"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Ensure user's Cargo-installed binaries are available
|
|
||||||
export PATH="$HOME/.cargo/bin:$PATH"
|
|
||||||
|
|
||||||
if command -v rustup >/dev/null 2>&1; then
|
|
||||||
echo "Ensuring common embedded Rust targets are available (idempotent)..."
|
|
||||||
rustup target add thumbv6m-none-eabi >/dev/null 2>&1 || true # Cortex-M0/M0+ (RP2040)
|
|
||||||
rustup target add thumbv7em-none-eabihf >/dev/null 2>&1 || true # Cortex-M4F/M7F (many STM32/nRF52)
|
|
||||||
rustup target add riscv32imc-unknown-none-elf >/dev/null 2>&1 || true
|
|
||||||
rustup target add riscv32imac-unknown-none-elf >/dev/null 2>&1 || true # ESP32-C3 class
|
|
||||||
echo "Note: ESP32 Xtensa targets require espup/custom toolchains (see esp-rs)."
|
|
||||||
fi
|
|
||||||
echo "[rust-template] Welcome to the Rust dev shell!"
|
|
||||||
echo "Tools: cargo, rustc, clippy, rustfmt, rust-analyzer, probe-rs, espflash, openocd, minicom, elf2uf2-rs, picotool, avrdude, ravedude"
|
|
||||||
echo "Run 'cargo build' to build, or 'nix run .#dev-helper' for a tool summary."
|
|
||||||
echo "See README.md for usage."
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
packages = forEachSupportedSystem (
|
|
||||||
{ pkgs }:
|
|
||||||
{
|
|
||||||
# Build the skeletal Cargo project
|
|
||||||
default = pkgs.rustPlatform.buildRustPackage {
|
|
||||||
pname = "sample-rust-app";
|
|
||||||
version = "0.1.0";
|
|
||||||
src = ./.;
|
|
||||||
cargoLock.lockFile = ./Cargo.lock;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
devHelper = pkgs.writeShellScriptBin "dev-helper" ''
|
shellHook = ''
|
||||||
echo "Rust toolchain available:"
|
export LD_LIBRARY_PATH="${pkgs.lib.makeLibraryPath runtimeLibs}:$LD_LIBRARY_PATH"
|
||||||
command -v cargo >/dev/null 2>&1 && cargo --version || true
|
|
||||||
command -v rustc >/dev/null 2>&1 && rustc --version || true
|
# Initialize git repository if not already present
|
||||||
echo "This binary is built by Nix (packages.default)."
|
if [ ! -d .git ]; then
|
||||||
|
git init
|
||||||
|
echo "✓ Initialized git repository"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Ensure user's Cargo-installed binaries are available
|
||||||
|
export PATH="$HOME/.cargo/bin:$PATH"
|
||||||
|
|
||||||
|
echo "[ColdIron] Welcome to the ColdIron development shell!"
|
||||||
|
echo "Commands: 'cargo run' to start GUI, 'cargo test' to run tests, 'make flatpak-build' for Flatpak."
|
||||||
'';
|
'';
|
||||||
}
|
};
|
||||||
);
|
}
|
||||||
|
);
|
||||||
apps = forEachSupportedSystem (
|
};
|
||||||
{ pkgs }:
|
|
||||||
{
|
|
||||||
default = {
|
|
||||||
type = "app";
|
|
||||||
program = pkgs.lib.getExe self.packages.${pkgs.stdenv.hostPlatform.system}.default;
|
|
||||||
};
|
|
||||||
dev-helper = {
|
|
||||||
type = "app";
|
|
||||||
program = pkgs.lib.getExe self.packages.${pkgs.stdenv.hostPlatform.system}.devHelper;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,31 @@
|
|||||||
{
|
{
|
||||||
"app-id": "org.example.rustdevshell",
|
"app-id": "io.github.gooba42.coldiron",
|
||||||
"runtime": "org.freedesktop.Platform",
|
"runtime": "org.freedesktop.Platform",
|
||||||
"runtime-version": "23.08",
|
"runtime-version": "24.08",
|
||||||
"sdk": "org.freedesktop.Sdk",
|
"sdk": "org.freedesktop.Sdk",
|
||||||
"command": "rustdevshell-app",
|
"sdk-extensions": [
|
||||||
|
"org.freedesktop.Sdk.Extension.rust-stable"
|
||||||
|
],
|
||||||
|
"command": "ColdIron",
|
||||||
|
"finish-args": [
|
||||||
|
"--share=ipc",
|
||||||
|
"--socket=fallback-x11",
|
||||||
|
"--socket=wayland",
|
||||||
|
"--device=dri"
|
||||||
|
],
|
||||||
|
"build-options": {
|
||||||
|
"append-path": "/usr/lib/sdk/rust-stable/bin",
|
||||||
|
"env": {
|
||||||
|
"CARGO_HOME": "/run/build/coldiron/cargo"
|
||||||
|
}
|
||||||
|
},
|
||||||
"modules": [
|
"modules": [
|
||||||
{
|
{
|
||||||
"name": "rustdevshell-app",
|
"name": "coldiron",
|
||||||
"buildsystem": "simple",
|
"buildsystem": "simple",
|
||||||
"build-commands": [
|
"build-commands": [
|
||||||
"cargo build --release"
|
"cargo build --release",
|
||||||
|
"install -Dm755 target/release/ColdIron /app/bin/ColdIron"
|
||||||
],
|
],
|
||||||
"sources": [
|
"sources": [
|
||||||
{
|
{
|
||||||
|
|||||||
+55
@@ -0,0 +1,55 @@
|
|||||||
|
{
|
||||||
|
lib,
|
||||||
|
rustPlatform,
|
||||||
|
makeBinaryWrapper,
|
||||||
|
pkg-config,
|
||||||
|
wayland,
|
||||||
|
libxkbcommon,
|
||||||
|
libGL,
|
||||||
|
vulkan-loader,
|
||||||
|
libx11,
|
||||||
|
libxcursor,
|
||||||
|
libxrandr,
|
||||||
|
libxi,
|
||||||
|
}: let
|
||||||
|
runtimeLibs = [
|
||||||
|
wayland
|
||||||
|
libxkbcommon
|
||||||
|
libGL
|
||||||
|
vulkan-loader
|
||||||
|
libx11
|
||||||
|
libxcursor
|
||||||
|
libxrandr
|
||||||
|
libxi
|
||||||
|
];
|
||||||
|
in
|
||||||
|
rustPlatform.buildRustPackage {
|
||||||
|
pname = "coldiron";
|
||||||
|
version = "0.1.0";
|
||||||
|
|
||||||
|
src = lib.cleanSource ./.;
|
||||||
|
|
||||||
|
cargoLock = {
|
||||||
|
lockFile = ./Cargo.lock;
|
||||||
|
};
|
||||||
|
|
||||||
|
nativeBuildInputs = [
|
||||||
|
pkg-config
|
||||||
|
makeBinaryWrapper
|
||||||
|
];
|
||||||
|
|
||||||
|
buildInputs = runtimeLibs;
|
||||||
|
|
||||||
|
postInstall = ''
|
||||||
|
wrapProgram "$out/bin/ColdIron" \
|
||||||
|
--prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath runtimeLibs}"
|
||||||
|
'';
|
||||||
|
|
||||||
|
meta = with lib; {
|
||||||
|
description = "ColdIron - Learning Rust and Iced desktop GUI application";
|
||||||
|
homepage = "https://github.com/gooba42/coldIron";
|
||||||
|
license = licenses.mit;
|
||||||
|
mainProgram = "ColdIron";
|
||||||
|
platforms = platforms.linux;
|
||||||
|
};
|
||||||
|
}
|
||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "rust-template"
|
name = "coldiron"
|
||||||
description = "A reusable Nix flake template for Rust development."
|
description = "ColdIron - Learning Rust and Iced desktop GUI application"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["gooba42 <your@email>"]
|
authors = ["gooba42 <your@email>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|||||||
@@ -1,15 +1,33 @@
|
|||||||
{
|
{pkgs ? import <nixpkgs> {}}: let
|
||||||
pkgs ? import <nixpkgs> { },
|
runtimeLibs = with pkgs; [
|
||||||
}:
|
wayland
|
||||||
pkgs.mkShell {
|
libxkbcommon
|
||||||
buildInputs = [
|
libGL
|
||||||
pkgs.rustc
|
vulkan-loader
|
||||||
pkgs.cargo
|
libx11
|
||||||
pkgs.rustfmt
|
libxcursor
|
||||||
pkgs.clippy
|
libxrandr
|
||||||
pkgs.rust-analyzer
|
libxi
|
||||||
];
|
];
|
||||||
shellHook = ''
|
in
|
||||||
echo "[shell.nix] Legacy shell for Rust dev. Use 'nix develop' for full flake support."
|
pkgs.mkShell {
|
||||||
'';
|
buildInputs =
|
||||||
}
|
[
|
||||||
|
pkgs.rustc
|
||||||
|
pkgs.cargo
|
||||||
|
pkgs.rustfmt
|
||||||
|
pkgs.clippy
|
||||||
|
pkgs.rust-analyzer
|
||||||
|
pkgs.pkg-config
|
||||||
|
]
|
||||||
|
++ runtimeLibs;
|
||||||
|
|
||||||
|
env = {
|
||||||
|
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath runtimeLibs;
|
||||||
|
};
|
||||||
|
|
||||||
|
shellHook = ''
|
||||||
|
export LD_LIBRARY_PATH="${pkgs.lib.makeLibraryPath runtimeLibs}:$LD_LIBRARY_PATH"
|
||||||
|
echo "[shell.nix] Legacy shell for Rust dev. Use 'nix develop' for full flake support."
|
||||||
|
'';
|
||||||
|
}
|
||||||
|
|||||||
+19
-2
@@ -1,3 +1,20 @@
|
|||||||
fn main() {
|
use iced::widget::{button, text};
|
||||||
println!("Hello from Rust skeletal app. Edit src/main.rs to get started!");
|
use iced::Element;
|
||||||
|
|
||||||
|
pub fn main() -> iced::Result {
|
||||||
|
iced::run(update, view)
|
||||||
|
}
|
||||||
|
fn update(counter: &mut u64, message: Message) {
|
||||||
|
match message {
|
||||||
|
Message::Increment => *counter += 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
enum Message {
|
||||||
|
Increment,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn view(counter: &u64) -> Element<'_, Message> {
|
||||||
|
button(text(counter)).on_press(Message::Increment).into()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user