This commit is contained in:
commit
95a533c876
451 changed files with 18255 additions and 0 deletions
26
templates/dev/rs-hello/.github/workflows/rust-nix.yml
vendored
Normal file
26
templates/dev/rs-hello/.github/workflows/rust-nix.yml
vendored
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
name: Rust Nix Pipeline
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
build-and-test:
|
||||
name: Build and Test
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Nix
|
||||
uses: cachix/install-nix-action@v18
|
||||
with:
|
||||
nix_path: nixpkgs=channel:nixos-unstable
|
||||
|
||||
- name: Run cargo tests in dev shell
|
||||
run: nix develop --command bash -c "cargo test"
|
||||
|
||||
- name: Run nix flake check
|
||||
run: nix flake check
|
||||
3
templates/dev/rs-hello/.gitignore
vendored
Normal file
3
templates/dev/rs-hello/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
.pre-commit-config.yaml
|
||||
result/
|
||||
target/
|
||||
8
templates/dev/rs-hello/Cargo.toml
Normal file
8
templates/dev/rs-hello/Cargo.toml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
[package]
|
||||
name = "hello-world"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
authors = ["Your Name <your.email@example.com>"]
|
||||
description = "A simple Hello World program"
|
||||
|
||||
[dependencies]
|
||||
127
templates/dev/rs-hello/flake.nix
Normal file
127
templates/dev/rs-hello/flake.nix
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
{
|
||||
description = "A hello world template in Rust";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "nixpkgs/nixos-unstable";
|
||||
pre-commit-hooks = {
|
||||
url = "github:cachix/pre-commit-hooks.nix";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
};
|
||||
|
||||
outputs =
|
||||
{
|
||||
self,
|
||||
nixpkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
pname = "hello-world";
|
||||
version = "0.1.0";
|
||||
|
||||
supportedSystems = [
|
||||
"x86_64-linux"
|
||||
"aarch64-linux"
|
||||
"x86_64-darwin"
|
||||
"aarch64-darwin"
|
||||
];
|
||||
|
||||
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
|
||||
|
||||
nixpkgsFor = forAllSystems (
|
||||
system:
|
||||
import nixpkgs {
|
||||
inherit system;
|
||||
overlays = [ self.overlays.default ];
|
||||
}
|
||||
);
|
||||
in
|
||||
{
|
||||
overlays.default = final: prev: {
|
||||
"${pname}" = final.rustPlatform.buildRustPackage {
|
||||
inherit pname version;
|
||||
src = ./.;
|
||||
cargoLock.lockFile = ./Cargo.lock;
|
||||
nativeBuildInputs = with final; [ pkg-config ];
|
||||
};
|
||||
};
|
||||
|
||||
packages = forAllSystems (system: {
|
||||
default = nixpkgsFor.${system}."${pname}";
|
||||
"${pname}" = nixpkgsFor.${system}."${pname}";
|
||||
});
|
||||
|
||||
devShells = forAllSystems (
|
||||
system:
|
||||
let
|
||||
pkgs = nixpkgsFor.${system};
|
||||
in
|
||||
{
|
||||
default = pkgs.mkShell {
|
||||
inherit (self.checks.${system}.pre-commit-check) shellHook;
|
||||
buildInputs =
|
||||
self.checks.${system}.pre-commit-check.enabledPackages
|
||||
++ (with pkgs; [
|
||||
cargo
|
||||
pkg-config
|
||||
pre-commit
|
||||
rust-analyzer
|
||||
rustc
|
||||
]);
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
formatter = forAllSystems (
|
||||
system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
config = self.checks.${system}.pre-commit-check.config;
|
||||
inherit (config) package configFile;
|
||||
script = ''
|
||||
${pkgs.lib.getExe package} run --all-files --config ${configFile}
|
||||
'';
|
||||
in
|
||||
pkgs.writeShellScriptBin "pre-commit-run" script
|
||||
);
|
||||
|
||||
checks = forAllSystems (
|
||||
system:
|
||||
let
|
||||
pkgs = nixpkgsFor.${system};
|
||||
in
|
||||
{
|
||||
integration-test =
|
||||
pkgs.runCommand "hello-world-test"
|
||||
{
|
||||
nativeBuildInputs = [
|
||||
pkgs.synixutils
|
||||
self.packages.${system}.${pname}
|
||||
];
|
||||
}
|
||||
''
|
||||
output=$(hello-world)
|
||||
|
||||
echo "$output" | grep -q "Hello, World!" || {
|
||||
echo "Test failed: Expected 'Hello, World!' but got: $output"
|
||||
exit 1
|
||||
}
|
||||
|
||||
echo "Hello World test passed!" > $out
|
||||
'';
|
||||
|
||||
pre-commit-check = self.inputs.pre-commit-hooks.lib.${system}.run {
|
||||
src = ./.;
|
||||
hooks = {
|
||||
nixfmt = {
|
||||
enable = true;
|
||||
};
|
||||
rustfmt = {
|
||||
enable = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
11
templates/dev/rs-hello/src/main.rs
Normal file
11
templates/dev/rs-hello/src/main.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn test_hello_world() {
|
||||
assert!(true);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue