templates/rust-app: init

This commit is contained in:
Gabriel Arazas 2024-03-16 15:12:59 +08:00
parent 738c7a5004
commit 1d7ff0fcc5
No known key found for this signature in database
GPG Key ID: 62104B43D00AA360
8 changed files with 118 additions and 0 deletions

View File

@ -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";

View File

@ -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]

View File

@ -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;
};
}

View File

@ -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 ./. { };
});
};
}

View File

@ -0,0 +1,5 @@
project('rust-app', 'rust',
version: '0.1.0',
meson_version: '>=1.0.0')
subdir('src')

View File

@ -0,0 +1,13 @@
{ pkgs }:
let
app = pkgs.callPackage ./. { };
in
pkgs.mkShell {
inputsFrom = [ app ];
packages = with pkgs; [
treefmt
rust-analyzer
];
}

View File

@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}

View File

@ -0,0 +1,6 @@
srcs = [
'main.rs'
]
executable('app',
srcs)