From 960efd4cf6f3ccc88adafae5fde9aa36f09224b4 Mon Sep 17 00:00:00 2001 From: traxys Date: Thu, 9 Nov 2023 23:37:32 +0100 Subject: [PATCH] templates: Add gui template --- flake.nix | 4 ++++ templates/gui/.envrc | 1 + templates/gui/.gitignore | 3 +++ templates/gui/Cargo.toml | 8 ++++++++ templates/gui/flake.nix | 43 +++++++++++++++++++++++++++++++++++++++ templates/gui/src/main.rs | 31 ++++++++++++++++++++++++++++ 6 files changed, 90 insertions(+) create mode 100644 templates/gui/.envrc create mode 100644 templates/gui/.gitignore create mode 100644 templates/gui/Cargo.toml create mode 100644 templates/gui/flake.nix create mode 100644 templates/gui/src/main.rs diff --git a/flake.nix b/flake.nix index 62f6655..93aa3dc 100644 --- a/flake.nix +++ b/flake.nix @@ -134,6 +134,10 @@ path = ./templates/webserver; description = "A template for a web server (using templates for the frontend)"; }; + gui = { + path = ./templates/gui; + description = "A template for rust GUI applications"; + }; }; packages.x86_64-linux = pkgList "x86_64-linux" nixpkgs.legacyPackages.x86_64-linux.callPackage; packages.aarch64-linux = pkgList "aarch64-linux" nixpkgs.legacyPackages.aarch64-linux.callPackage; diff --git a/templates/gui/.envrc b/templates/gui/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/templates/gui/.envrc @@ -0,0 +1 @@ +use flake diff --git a/templates/gui/.gitignore b/templates/gui/.gitignore new file mode 100644 index 0000000..8b0789b --- /dev/null +++ b/templates/gui/.gitignore @@ -0,0 +1,3 @@ +/target +/.direnv + diff --git a/templates/gui/Cargo.toml b/templates/gui/Cargo.toml new file mode 100644 index 0000000..e228645 --- /dev/null +++ b/templates/gui/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "todo_change_name" +version = "0.1.0" +authors = ["traxys "] +edition = "2021" + +[dependencies] +iced = "0.10.0" diff --git a/templates/gui/flake.nix b/templates/gui/flake.nix new file mode 100644 index 0000000..39425f7 --- /dev/null +++ b/templates/gui/flake.nix @@ -0,0 +1,43 @@ +{ + description = "A basic flake with a shell"; + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + inputs.flake-utils.url = "github:numtide/flake-utils"; + inputs.naersk.url = "github:nix-community/naersk"; + inputs.rust-overlay.url = "github:oxalica/rust-overlay"; + + outputs = { + self, + nixpkgs, + flake-utils, + naersk, + rust-overlay, + }: + flake-utils.lib.eachDefaultSystem (system: let + pkgs = import nixpkgs { + inherit system; + overlays = [(import rust-overlay)]; + }; + rust = pkgs.rust-bin.stable.latest.default; + naersk' = pkgs.callPackage naersk { + cargo = rust; + rustc = rust; + }; + libPath = with pkgs; lib.makeLibraryPath [libxkbcommon wayland]; + in { + devShell = pkgs.mkShell { + nativeBuildInputs = [rust]; + RUST_PATH = "${rust}"; + RUST_DOC_PATH = "${rust}/share/doc/rust/html/std/index.html"; + LD_LIBRARY_PATH = libPath; + }; + + defaultPackage = naersk'.buildPackage { + src = ./.; + nativeBuildInputs = [pkgs.makeWrapper]; + postInstall = '' + wrapProgram "$out/bin/todo_change_name" --prefix LD_LIBRARY_PATH : "${libPath}" + ''; + }; + }); +} + diff --git a/templates/gui/src/main.rs b/templates/gui/src/main.rs new file mode 100644 index 0000000..41a2ed0 --- /dev/null +++ b/templates/gui/src/main.rs @@ -0,0 +1,31 @@ +use iced::{widget::column, Sandbox, Settings}; + +#[derive(Clone, Copy, Debug)] +enum Message {} + +struct App {} + +impl Sandbox for App { + type Message = Message; + + fn new() -> Self { + Self {} + } + + fn title(&self) -> String { + "TODO change name".into() + } + + fn update(&mut self, message: Self::Message) { + match message {} + } + + fn view(&self) -> iced::Element<'_, Self::Message> { + column![].into() + } +} + +fn main() -> iced::Result { + App::run(Settings::default()) +} +