diff --git a/configs/flake-parts/templates.nix b/configs/flake-parts/templates.nix index 2baa8c7d..71ed652e 100644 --- a/configs/flake-parts/templates.nix +++ b/configs/flake-parts/templates.nix @@ -18,6 +18,10 @@ path = ../../templates/basic-overlay-flake; description = "Basic overlay as a flake"; }; + rust-app = { + path = ../../templates/rust-app; + description = "Rust app scaffolding"; + }; sample-nixos-template = { path = ../../templates/sample-nixos-template; description = "Simple sample Nix flake with NixOS and home-manager"; diff --git a/templates/rust-app/Cargo.toml b/templates/rust-app/Cargo.toml new file mode 100644 index 00000000..e5e90c8b --- /dev/null +++ b/templates/rust-app/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "rust-app" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/templates/rust-app/default.nix b/templates/rust-app/default.nix new file mode 100644 index 00000000..9d896be9 --- /dev/null +++ b/templates/rust-app/default.nix @@ -0,0 +1,37 @@ +{ lib +, rustPlatform +, meson +, ninja +, pkg-config +}: + +rustPlatform.buildRustPackage { + pname = "app"; + version = "VERSION"; + + src = lib.fileset.toSource { + root = ./.; + fileset = lib.fs.unions [ + ./Cargo.lock + ./Cargo.toml + ./LICENSE + ./meson.build + ./meson_options.txt + ./src + ]; + }; + + cargoLock.lockFile = ./Cargo.lock; + + nativeBuildInputs = [ + meson + ninja + pkg-config + ]; + + meta = with lib; { + description = "Rust app"; + mainProgram = "app"; + platforms = platforms.unix; + }; +} diff --git a/templates/rust-app/flake.nix b/templates/rust-app/flake.nix new file mode 100644 index 00000000..4a2d0bc8 --- /dev/null +++ b/templates/rust-app/flake.nix @@ -0,0 +1,42 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + rust-overlay.url = "github:oxalica/rust-overlay"; + }; + + outputs = { self, nixpkgs, ... }@inputs: + let + inherit (nixpkgs) lib; + systems = [ "x86_64-linux" ]; + forAllSystems = f: lib.genAttrs systems (system: f system); + in + { + devShells = forAllSystems + (system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ + inputs.rust-overlay.overlays.default + ]; + }; + in + { + default = import ./shell.nix { inherit pkgs; }; + }); + + packages = forAllSystems + (system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ + inputs.rust-overlay.overlays.default + ]; + }; + in + { + default = pkgs.callPackage ./. { }; + }); + }; +} diff --git a/templates/rust-app/meson.build b/templates/rust-app/meson.build new file mode 100644 index 00000000..61fd9f5d --- /dev/null +++ b/templates/rust-app/meson.build @@ -0,0 +1,5 @@ +project('rust-app', 'rust', + version: '0.1.0', + meson_version: '>=1.0.0') + +subdir('src') diff --git a/templates/rust-app/shell.nix b/templates/rust-app/shell.nix new file mode 100644 index 00000000..9238a441 --- /dev/null +++ b/templates/rust-app/shell.nix @@ -0,0 +1,13 @@ +{ pkgs }: + +let + app = pkgs.callPackage ./. { }; +in +pkgs.mkShell { + inputsFrom = [ app ]; + + packages = with pkgs; [ + treefmt + rust-analyzer + ]; +} diff --git a/templates/rust-app/src/main.rs b/templates/rust-app/src/main.rs new file mode 100644 index 00000000..e7a11a96 --- /dev/null +++ b/templates/rust-app/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/templates/rust-app/src/meson.build b/templates/rust-app/src/meson.build new file mode 100644 index 00000000..d8906563 --- /dev/null +++ b/templates/rust-app/src/meson.build @@ -0,0 +1,6 @@ +srcs = [ + 'main.rs' + ] + +executable('app', + srcs)